Click here to Skip to main content
14,665,569 members
Rate this:
Please Sign up or sign in to vote.
See more:
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 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;
}
}


But it is not working . I am getting s="" . please help me.

Thanks in advance.

Pankaj Singh
Posted
Updated 18-Apr-12 15:52pm
v2

Rate this:
Please Sign up or sign in to vote.

Solution 1

protected void Page_Load(object sender, EventArgs e)
{
if(!Page.isPostBack){
GetDetails();}

}
   
Comments
Mohamed Mitwalli 19-Apr-12 1:23am
   
Agree with you
Dholakiya Ankit 5-Aug-13 6:37am
   
5ed
Rate this:
Please Sign up or sign in to vote.

Solution 2

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100