| | |
dynamic tables
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2004
Posts: 13
Reputation:
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!
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
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:
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:
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:
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:
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
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.
![]() |
Similar Threads
- text orientation (HTML and CSS)
Other Threads in the ASP.NET Forum
- Previous Thread: pascal write problem
- Next Thread: Programming Sag Really Need Help / Advice
| Thread Tools | Search this Thread |
.net 3.5 activexcontrol ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser businesslogiclayer button c# cac checkbox class click commonfunctions countryselector dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash formatdecimal formview gridview gudi iis javascript list listbox microsoft mono mouse mssql nameisnotdeclared news novell numerical opera panelmasterpagebuttoncontrols problem radio redirect registration relationaldatabases reportemail save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos vista visualstudio vs2008 web webapplications webdevelopemnt webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers






