you have to write code in code-behind file only

Recommended Answers

All 4 Replies

This code may help you:

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
      GridViewRow r = this.GridView1.Controls[0].Controls[e.RowIndex] as GridViewRow;
      TextBox t=  r.Controls[cell_index].Controls[control_index] as Text Box;
     }

This Syntax for Grid View:

GridView.Controls(0) ------ Table

GridView.Controls(0).Controls(index) ------ GridViewRow

GridView.Controls(0).Controls(index).Controls(index) ------ TableCell. For BoundField, we can use

getting null value after writting this code.

My code is:-

TextBox tname =(TextBox ) GridView1.Rows[e.RowIndex].Cells[2].Controls[0];
        ds.Tables[0].Rows[e.RowIndex ][1] = tname.Text;
        TextBox tgender = (TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0] ;
        ds.Tables[0].Rows[e.RowIndex][2] = tgender.Text;

when i run the application then it throwing an exception: Unable to cast object of type
'System.Web.UI.WebControls.DataControlLinkButton' to type 'System.Web.UI.WebControls.TextBox'.

pharindra,

Can you please supply your code for the the GridView? That would help a lot in trying to find any problems that may be in the code.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.