Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a few template fields (text boxes) in Grid View. After filling in data in the fields, when I click 'Submit' Button, the data disappears. Can any one kindly help me to resolve this?

Thanks
S.Rajagopal
Posted
Comments
Richard C Bishop 27-Mar-14 10:53am    
We'll need to see your code.
Member 10599847 27-Mar-14 11:12am    
Here is the code:
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{

if (GridView1.Rows.Count != 0)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
for (int x = 0; x < GridView1.Columns.Count; x ++)
{
if (x == 2)
{
TextBox tb1 = (TextBox)GridView1.Rows[i].FindControl("txtIntDt");
txtdt = tb1.Text.ToString();

}
else if (x == 4)
{
TextBox tb2 = (TextBox)GridView1.Rows[i].FindControl("txtITDt");
txtdt = tb2.Text.ToString();

}
else if (x == 6)
{
TextBox tb3 = (TextBox)GridView1.Rows[i].FindControl("txtBimsDt");
txtdt = tb3.Text.ToString();

}
else if (x == 8)
{
TextBox tb4 = (TextBox)GridView1.Rows[i].FindControl("txtQMDt");
txtdt = tb4.Text.ToString()
;
}
else if (x == 10)
{
TextBox tb5 = (TextBox)GridView1.Rows[i].FindControl("txt5Dt");
txtdt = tb5.Text.ToString();

}
else if (x == 12)
{
TextBox tb6 = (TextBox)GridView1.Rows[i].FindControl("txt6Dt");
txtdt = tb6.Text.ToString();

}
else if (x == 14)
{
TextBox tb7 = (TextBox)GridView1.Rows[i].FindControl("txtTTDt");
txtdt = tb7.Text.ToString();

}

if (txtdt != "")
{

----here i am updating the tables, but not happening because the value is always null---
}


}

}

Check your Page_Load method: I'm betting you clear the fields there.
Page_Load is called fro all page activities, including the postbacks caused by button clicks, so unless you check for a post back they will be cleared before the click event handler gets to run.
C#
protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
        {
        // Handle the initial page setup.
 
Share this answer
 
SQL
manage

ispostback on page load

and bind data on every submit
 
Share this answer
 
Comments
Member 10599847 30-Mar-14 2:11am    
on page load event I did manage that. As suggested I am binding data on every event, it works. Thanks.

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