在Button Click上获取Gridview TextBox的值 [英] Get values of Gridview TextBox on Button Click
本文介绍了在Button Click上获取Gridview TextBox的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Gridview中有一个ITEMTemplate TextBox。我想在点击按钮时保存Texboxes的值。我使用以下代码::
源代码:
Hi,
I have a ITEMTemplate TextBox in a Gridview. I want to save values of Texboxes on button click. I am using following code ::
Source code:
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server">
<columns>
<asp:TemplateField HeaderText="Values">
<itemtemplate>
<asp:TextBox ID="TextBox1" runat="server">
</itemtemplate>
</columns>
</div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Insert Into Table" />
</form>
cs文件:
cs file:
protected void Page_Load(object sender, EventArgs e)
{
GetDetails();
}
private void GetDetails()
{
da = new SqlDataAdapter("select column_name from testing.information_schema.columns where table_name = 'emp'", con);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count - 1; i++)
{
TextBox box1 = (TextBox)GridView1.Rows[i].Cells[0].FindControl("TextBox1");
string s = box1.Text;
}
}
但它不起作用。我得到s =。请帮帮我。
提前致谢。
Pankaj Singh
But it is not working . I am getting s="" . please help me.
Thanks in advance.
Pankaj Singh
推荐答案
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.isPostBack){
GetDetails();}
}
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
TextBox box1 = (TextBox)GridView1.Rows[i].Cells[0].FindControl("TextBox1");
string s = box1.Text;
}
}
这篇关于在Button Click上获取Gridview TextBox的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文