User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 426,335 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,456 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 17092 | Replies: 8
Reply
Join Date: Nov 2004
Posts: 13
Reputation: dru987 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
dru987 dru987 is offline Offline
Newbie Poster

dynamic tables

  #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!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Posts: 1,590
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 35
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: dynamic tables

  #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  
Join Date: Nov 2004
Posts: 13
Reputation: dru987 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
dru987 dru987 is offline Offline
Newbie Poster

Re: dynamic tables

  #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  
Join Date: Dec 2004
Posts: 1,590
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 35
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: dynamic tables

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

Re: dynamic tables

  #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  
Join Date: Dec 2004
Posts: 1,590
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 35
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: dynamic tables

  #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  
Join Date: Sep 2005
Posts: 7
Reputation: sandy2005 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sandy2005 sandy2005 is offline Offline
Newbie Poster

Re: dynamic tables

  #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  
Join Date: Sep 2005
Posts: 7
Reputation: sandy2005 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sandy2005 sandy2005 is offline Offline
Newbie Poster

Re: dynamic tables

  #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  
Join Date: Dec 2004
Posts: 1,590
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 35
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: dynamic tables

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 11:29 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC