SharePoint - SPGridView problem getting a cell data

Asked By Bookworm on 12-Jan-12 06:13 AM
Hi,

im using this code to get cell data but it return empty string "" :

int index = e.NewSelectedIndex;
gridview.Rows[index].Cells[1].Text;

in anothe web part that im using another grid it works? i dont know, if there is any property of the SPgrid?
any idea?

thnx
dipa ahuja replied to Bookworm on 12-Jan-12 06:14 AM
void bind()
{
  foreach (GridViewRow row in GridView1.Rows)
  {
    string name = ((Label)row.FindControl("label1")).Text.ToString();
    string gender = ((DropDownList)row.FindControl("dropdown1")).SelectedValue.ToString();
    string contact = ((Label)row.FindControl("lblcontact")).Text.ToString();
 
    //code to write
  }
}
 

Asked By Bookworm on 12-Jan-12 07:00 AM
but i want the cell in the second column, whatever even with this  :
k = row.Cells[0].Text; 
it does not work, it seem like it cannot read the grid cell because it return empty string ""

any idea for this problem?
[)ia6l0 iii replied to Bookworm on 12-Jan-12 01:50 PM
Most likely in your case, the Cell has a control and the control then has the text.

So, this should work:
((TextBox)gridview.Rows[gridview.SelectedIndex].Cells[1].Controls[0]).Text;