On May 25, 10:47 am, Smita <S...@discussions.microsoft.comwrote:
Hello all,
I have a gridview, and a label inside the <Columnsand ItemTemplate. The
label is a hidden. I want to retrieve the value of this label on the
gridview_OnPageIndexChanged event, but i seem to get a nullexception. Can
anyone please tell me what iam doing wrong.
When i do the "view source" option i do see the values in the label.
thanks for all the help
I am not sure if there is an event called OnpageIndexChanged for a
gridview or not but what I have below is for the
SelectedIndexChanged.
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SqlDataSource1"
OnSelectedIndexChanged="GridView1_SelectedIndexCha nged">
<Columns>
<asp:CommandField ShowSelectButton="true" />
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="test2" runat="server"
Text='<%# Bind("id") %>' ></asp:Label>
<asp:Label ID="testId" runat="server"
Text='<%# Bind("type") %>' Visible="true" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code Behind:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs
e)
{
Label test =
(Label)GridView1.SelectedRow.Cells[0].FindControl("testId");
Response.Write(test.Text);
}
You should be able to apply to your other gridview event. This is
assumed that there is a row selected on the gridview.