Hi akhter,
Check this sample. now take its reference and correct your code.
HTML
Container Number : <asp:TextBox ID="txtcontno" runat="server"></asp:TextBox>
<div>
Input Number of Range : <asp:TextBox ID="txtqty" runat="server"></asp:TextBox>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="OnAdd" />
</div><br />
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="OnSave" /><hr />
<asp:GridView ID="gvEmployees" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lblBid" runat="server" Text='<%#Bind("BID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="QTY">
<ItemTemplate>
<asp:Label ID="lblQty" runat="server" Text='<%#Bind("QTY")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void OnAdd(object sender, EventArgs e)
{
int containerNo = int.Parse(txtcontno.Text.Trim());
int quantity = int.Parse(txtqty.Text.Trim());
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("BID", typeof(int)),
new DataColumn("QTY", typeof(string))
});
for (int i = 1; i <= quantity; i++)
{
dt.Rows.Add(i.ToString(), containerNo);
}
this.gvEmployees.DataSource = dt;
this.gvEmployees.DataBind();
}
VB.Net
Protected Sub OnAdd(ByVal sender As Object, ByVal e As EventArgs)
Dim containerNo As Integer = Integer.Parse(txtcontno.Text.Trim())
Dim quantity As Integer = Integer.Parse(txtqty.Text.Trim())
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {
New DataColumn("BID", GetType(Integer)),
New DataColumn("QTY", GetType(String))
})
For i As Integer = 1 To quantity
dt.Rows.Add(i.ToString(), containerNo)
Next
Me.gvEmployees.DataSource = dt
Me.gvEmployees.DataBind()
End Sub
Screenshot