Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two textbox and button...when i click button that two textbox values should add to grid by using session
Posted
Updated 3-Dec-12 19:57pm
v2

1 solution

You can try this
aspx:
C#
Enter Eno<asp:textbox id="TextBox1" runat="server" asp:button id="Button1" runat="server" text="Added to grid" onclick="Button1_Click" /> 


aspx.cs
C#
protected void Page_Load(object sender, EventArgs e)
{
    lblmsg.Text = "";
    
    if (!Page.IsPostBack)
    {
        dt.Columns.Add("eno");

 Session["reptable"] = dt;
        GridData();        
    }
}
//Load grid data from session
void GridData()
{
    GridView1.DataSource = (DataTable)Session["reptable"];
    GridView1.DataBind();
}


Add each row in the session when user add new details in the submit button
C#
protected void Button1_Click(object sender, EventArgs e)
{
    dt = (DataTable)Session["reptable"];
    dr = dt.NewRow();
    dr["eno"] = TextBox1.Text;
dt.Rows.Add(dr);
    Session.Remove("reptable");
    Session["reptable"] = dt;
    GridData();
    TextBox1.Text = "";
}

Hope this will help you.
 
Share this answer
 
v3

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