I have a Gridview having 3 columns in which i took checkbox,label and label as item templates for columns select,code,name respectively.
ecode column is not editable.Button edit and update are present outside of gridview.

i can edit multiple rows like this...

when i select checkbox in 1st row of gridview then in ename column of that row i added textbox by this code

protected void btnEdit_Click(object sender, EventArgs e)
    {
        
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            txteditEname = new TextBox();       
            CheckBox chkDelete = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("chkSelect");
            Label lblEname = (Label)GridView1.Rows[i].Cells[0].FindControl("lblEname");
           
            if (chkDelete.Checked)
            {
                GridView1.Rows[i].Cells[2].Controls.Add(txteditEname);
                txteditEname.Text = lblEname.Text;
                lblEname.Visible = false;
            }

        }
    }

protected void btnUpdate_Click(object sender, EventArgs e)
    {
        ArrayList al = new ArrayList();

        for (int i = 0; i < GridView1.Rows.Count; i++)
        {

            CheckBox chkDelete = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("chkSelect");
            txteditEname = (TextBox)GridView1.Rows[i].Cells[2].FindControl("txteditEname");
            string str=txteditEname.Text;//error

//here i set breakpoint and wanted to retrieve txteditEname but error comes...
then thinking that there is no such textbox when i press Update button as autopost back then
i saved the txteditEname 's value in Viewstate but when i retrieved viewstate it showed me the textbox's value before page is posted back.
But the current txteditEname's value is different which i want to update.Please tell me how to get curret txteditEname's value.
But before that i wonder if this textbox is not available then i'll surely get null value.

Please refer the ASP.NET Page life cycle topic at MSDN. ASP.NET page and control objects are created on each post back.

your code will never work..

you need to iterate through Gridview rows..

Checking should be done on RowDataBound Event..

foreach(GridviewRows Gvr in Gridview1.rows)
{
  Checkbox chk = (CheckBox)e.row.FindControl("Name Of Your Checkbox");

if(chk.checked == true)
{
 // carry out rest of the operation...
}
}
This article has been dead for over six months. Start a new discussion instead.