I’m having trouble retrieving the value of a cell in a gridview.
I think it may have something to do with the item template calling a function since I am able to retrieve the values of cells that are not calling a function in the same gridview.
How can i extract the displayed value from this cell?
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = GridView1.SelectedRow;
lblTest.Text=row.Cells[7].Text;
}
<ItemTemplate>
<%# GetWednesday(decimal.Parse(Eval("Wed").ToString())).ToString("N2") %>
</ItemTemplate>
Edit:
Poking around a little more, it appears your content is there, but not as text. It is a
DataBoundLiteralControlin the cell’sControlscollection. You can get the value with:Use of the
Trim()function is necessary to remove leading and trailing whitespace above and below the binding statement in your template.I still prefer the approach described below.
End
If I understand correctly, I think your value is not stored in ViewState.You can get at your text with this alternate approach:
And from code behind: