Hi ,
try this
protected void Button1_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
if (GridView2.Rows.Count == 0)
{
dt = MakeTable();
}
else
{
dt =(DataTable) ViewState["dt"];
}
DataRow dr = dt.NewRow();
dr[0] = TextBox2.Text;
dr[1] = TextBox3.Text;
dr[2] = TextBox4.Text;
dt.Rows.Add(dr);
GridView2.DataSource = null;
GridView2.DataSource = dt;
GridView2.DataBind();
ViewState.Add("dt", dt);
}
DataTable MakeTable()
{
DataTable Mydt = new DataTable();
DataColumn col1 = new DataColumn("col");
col1.DataType = System.Type.GetType("System.String");
Mydt.Columns.Add(col1);
DataColumn col2 = new DataColumn("col2");
col1.DataType = System.Type.GetType("System.String");
Mydt.Columns.Add(col2);
DataColumn col3 = new DataColumn("col3");
col1.DataType = System.Type.GetType("System.String");
Mydt.Columns.Add(col3);
return Mydt;
}
OR
protected void Button2_Click(object sender, EventArgs e)
{
string[] xx = new string[3];
xx[0] = TextBox2.Text;
xx[1] = TextBox3.Text;
xx[2] = TextBox4.Text;
GridView2.DataSource= xx.ToList();
GridView2.DataBind();
}
<div>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:GridView ID="GridView2" runat="server">
</asp:GridView>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
Best Regards
M.Mitwalli