dynamic tables

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 13
Reputation: dru987 is an unknown quantity at this point 
Solved Threads: 0
dru987 dru987 is offline Offline
Newbie Poster

dynamic tables

 
0
  #1
Apr 12th, 2005
im fairly new to the .Net world and i'm tryin to make a simple page that dynamicly fills a table/form from a database based on user log info. i've been doin some reading and the datalist/repeater seem like more than i need...or maybe they are exactly what i need but i'm not using them correctly. i have the login working already (thanks to some nice code samples from this site) that idenifies the user and stores first and last name in session variable to be used with later SQL strings. if anyone could suggest something or point me in the right direction, that'd be great. thanks!
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: dynamic tables

 
0
  #2
Apr 12th, 2005
What does the rendered table need to do?

If the answer is "it needs to contain "stuff" that the user will click/change, and then more server code will run", then you need to "Render dynamic controls", and should use a server side control to do that. Repeater. DataList. DataGrid.

If the answer is "sit there and look pretty", then you simply output a good old fashioned HTML Table, by using the LiteralControl.

The idea is: drag a PlaceHolder where you want the table to be.

Build a query, run the query, return a SqlDataReader.

Start your table:

PlaceHolder1.Controls.Add(new LiteralControl("<table>"));

Read through your datareader, outputting tags and content as you go:

[PHP]while(myDataReader.Read())
{
PlaceHolder1.Controls.Add(new LiteralControl("<tr><td>" + myDataReader["myField"].ToString() + "</td></tr>"));
}[/PHP]

And so on.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 13
Reputation: dru987 is an unknown quantity at this point 
Solved Threads: 0
dru987 dru987 is offline Offline
Newbie Poster

Re: dynamic tables

 
0
  #3
Apr 14th, 2005
tgreer, thank you so much. that was excatly what i was looking for. just had to make very minor change for VB.Net :cheesy:
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: dynamic tables

 
0
  #4
Apr 14th, 2005
You're welcome. Ain't forums grand?
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 7
Reputation: sandy2005 is an unknown quantity at this point 
Solved Threads: 0
sandy2005 sandy2005 is offline Offline
Newbie Poster

Re: dynamic tables

 
0
  #5
Sep 12th, 2005
Hi

I need to render a table with dynamic rows based on data obtained through data reader. Each row has a image link button, a link button
and a label to which data comes from the database. In the earlier message you said we can use either a datalist, repeator or datagrid.
Can you please let me know how to render the table dynamically.

Thanks
Sandy

Originally Posted by tgreer
What does the rendered table need to do?

If the answer is "it needs to contain "stuff" that the user will click/change, and then more server code will run", then you need to "Render dynamic controls", and should use a server side control to do that. Repeater. DataList. DataGrid.

If the answer is "sit there and look pretty", then you simply output a good old fashioned HTML Table, by using the LiteralControl.

The idea is: drag a PlaceHolder where you want the table to be.

Build a query, run the query, return a SqlDataReader.

Start your table:

PlaceHolder1.Controls.Add(new LiteralControl("<table>"));

Read through your datareader, outputting tags and content as you go:

[PHP]while(myDataReader.Read())
{
PlaceHolder1.Controls.Add(new LiteralControl("<tr><td>" + myDataReader["myField"].ToString() + "</td></tr>"));
}[/PHP]

And so on.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: dynamic tables

 
0
  #6
Sep 12th, 2005
The central point is, with ASP.NET, you need to forget HTML. Stop thinking of rendering a "table". Instead, use an ASP.NET Server Control. It will render the table.

There are lots of "Repeater control" examples on the web, if you search for them.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 7
Reputation: sandy2005 is an unknown quantity at this point 
Solved Threads: 0
sandy2005 sandy2005 is offline Offline
Newbie Poster

Re: dynamic tables

 
0
  #7
Sep 13th, 2005
Originally Posted by tgreer
The central point is, with ASP.NET, you need to forget HTML. Stop thinking of rendering a "table". Instead, use an ASP.NET Server Control. It will render the table.

There are lots of "Repeater control" examples on the web, if you search for them.
Thanks for the info. I have tried with Repeater control and it works. Only thing is, I have an asp:ImageButton Control which OnClick should open a url obtained from database. I am not sure about the exact format to do this. Following is what I am doing:

<asp:Repeater ID="repSpecials" Runat="server">
<ItemTemplate>

<td
<asp:ImageButton ID="ibSpecial" Runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImageUrl") %>'
OnClick="javascript:OpenSpecialsLink('<%# DataBinder.Eval(Container.DataItem, "SpecialsLink") %>'); >

</asp:ImageButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 7
Reputation: sandy2005 is an unknown quantity at this point 
Solved Threads: 0
sandy2005 sandy2005 is offline Offline
Newbie Poster

Re: dynamic tables

 
0
  #8
Sep 13th, 2005
Originally Posted by sandy2005
Thanks for the info. I have tried with Repeater control and it works. Only thing is, I have an asp:ImageButton Control which OnClick should open a url obtained from database. I am not sure about the exact format to do this. Following is what I am doing:

<asp:Repeater ID="repSpecials" Runat="server">
<ItemTemplate>

<td
<asp:ImageButton ID="ibSpecial" Runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImageUrl") %>'
OnClick="javascript:OpenSpecialsLink('<%# DataBinder.Eval(Container.DataItem, "SpecialsLink") %>'); >

</asp:ImageButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
I get the following error with this code:

Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: The server tag is not well formed.

Source Error:


Line 97: </td>
Line 98: <td bgcolor="#ffccff">
Line 99: <asp:ImageButton ID="ibSpecial" Runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImageUrl") %>' OnClick="javascript:OpenSpecialsLink('<%# DataBinder.Eval(Container.DataItem, "SpecialsLink") %>'); >
Line 100: </asp:ImageButton>
Line 101:
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: dynamic tables

 
0
  #9
Sep 13th, 2005
Since it's a server control, it's expecting the "onclick" attribute to contain a server-side method as its value. That's one problem.

It's been awhile, so this might not be 100% correct, but I think what you need to do is code the server-side ItemDataBound event. Within that method, you check the argument type, and if the control is an image button, then use the control's ".Attributes.Add()" method to code your onclick statement.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC