Add Rows into Datatable based on count and Bind Gridview

Rajesh_Kumar
Posted by Rajesh_Kumar under ASP.NET category on | Points: 40 | Views : 705
//Suppose Textbox has 5 value,then 5 rows will be added into Datatable.

using System.Text;

DataTable dt_customer = new DataTable();
dt_customer.Columns.Add("customer_id");
dt_customer.Columns.Add("customer_name");

if (!string.IsNullOrEmpty(TextBox1.Text))
{
for (int cnt = 0; cnt <= TextBox1.Text.Length - 1; cnt++)
{
dt_customer.Rows.Add(string.Empty, string.Empty);
}
}

GridView1.DataSource = dt_customer;
GridView1.DataBind();


<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Comments or Responses

Login to post response