使用session插入gridview [英] Insert to gridview by using session
本文介绍了使用session插入gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个文本框和按钮...当我点击按钮时,两个文本框值应该通过使用session
I have two textbox and button...when i click button that two textbox values should add to grid by using session
推荐答案
添加到网格中你可以尝试这个
aspx:
You can try this
aspx:
Enter Eno<asp:textbox id="TextBox1" runat="server" asp:button id="Button1" runat="server" text="Added to grid" onclick="Button1_Click" />
aspx.cs
aspx.cs
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
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.
这篇关于使用session插入gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文