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();
}