3

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
  • web forms or mvc ? your tag says MVC and question title says web forms. Commented Apr 3, 2016 at 20:29
  • sorry :( it is web form Commented Apr 3, 2016 at 20:30

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks abramlimpin
Would you tell me, how I call the list view from aspx.cs?
0

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

I think the question is for WebForms not MVC.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.