I want to generate same numbers of Labels and TextBoxes depending on the numbers of my sql database's table rows. It will generate the same numbers of Labels and TextBoxes and retrieve 1 column data to the labelsThe image shows a sample of database table and a webform design
2 Answers
You can use a Repeater or ListView control to create labels and text boxes dynamically:
.aspx:
<table>
<asp:ListView id="lvSample" runat="server">
<ItemTemplate>
<tr>
<td><%# Eval("ItemID") %></td>
<td><asp:TextBox ID="txtName" runat="server" Text='<%# Eval("Name") %>' />
</tr>
</ItemTemplate>
</asp:ListView>
</table>
Then set the DataSource value from your code-behind. You can also set it from the .aspx using the DataSource control.
see this :
<% var data=(from e in table select e).ToList<type>(); %>
<% foreach(type dr in data)
{ %>
<label><%=dr.Name %> </label>
<input type="text" name="<%=dr.ItemID %>" />
<% } %>
1 Comment
dmeglio
I think the question is for WebForms not MVC.