Exstract Value from Gridview Cell created by function in Item Templates

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>

Answers


Edit:

Poking around a little more, it appears your content is there, but not as text. It is a DataBoundLiteralControl in the cell's Controls collection. You can get the value with:

var value = (row.Cells[7].Controls[0] as DataBoundLiteralControl).Text.Trim();

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:

<ItemTemplate>
    <asp:Label ID="mylabel" runat="server" 
               Text='<%# GetWednesday(decimal.Parse(Eval("Wed").ToString())).ToString("N2") %>' />
</ItemTemplate>

And from code behind:

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
     var label = GridView1.SelectedRow.FindControl("mylabel") as Label;
     lblTest.Text = label.Text; 
}

Need Your Help

full setup for configuraton of local host

php

my project is saved in c:/wamp/www/EducationPortal

Can Chronicle Queue be used like RMI?

java rmi chronicle chronicle-queue

I want my two JVM applications speak to each other on the same machine. I considered using RMI, but then I found Chronicle Queue which claims that it is very fast. I wonder whether I can use Chroni...