•
•
•
•
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
![]() |
•
•
Join Date: Nov 2004
Posts: 13
Reputation:
Rep Power: 4
Solved Threads: 0
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!
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.
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.
•
•
Join Date: Sep 2005
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
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
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.
•
•
Join Date: Sep 2005
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
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.
<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>
•
•
Join Date: Sep 2005
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
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>
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:
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.
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- text orientation (HTML and CSS)
Other Threads in the ASP.NET Forum
- Previous Thread: pascal write problem
- Next Thread: rich editor for cms



Linear Mode