Click here to Skip to main content
16,022,234 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have textbox control in which User Insert values i.e 4
then It will create gridview of size 4*4 i.e gridview with
4 rows and 4 columns
if User insert 5 then it will create grid view with size 5 rows ans 5 columns
and so on
which does not contain any data in it

What I have tried:

I dont have any Idea about this
Posted
Updated 23-Oct-17 21:25pm
v2

1 solution

try

<asp:TextBox runat="server" ID ="txtCount" />
      <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        <asp:GridView ID="GridView1" runat="server"></asp:GridView>


protected void Button1_Click(object sender, EventArgs e)
      {
          DataTable dt = new DataTable();
          int count = 0;
          int.TryParse(txtCount.Text.Trim(), out count);
          for (int i = 1; i <= count; i++)
              dt.Columns.Add(i.ToString());
          for (int i = 0; i < count; i++)
              dt.Rows.Add(dt.NewRow());

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


      }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900