On May 25, 10:47 am, Smita <S...@discussio ns.microsoft.co mwrote:
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_OnPage IndexChanged 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 OnpageIndexChan ged for a
gridview or not but what I have below is for the
SelectedIndexCh anged.
<asp:GridView ID="GridView1" runat="server"
AutoGenerateCol umns="False" DataKeyNames="I D"
DataSourceID="S qlDataSource1"
OnSelectedIndex Changed="GridVi ew1_SelectedInd exChanged">
<Columns>
<asp:CommandFie ld ShowSelectButto n="true" />
<asp:TemplateFi eld>
<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:TemplateFie ld>
</Columns>
</asp:GridView>
Code Behind:
protected void GridView1_Selec tedIndexChanged (object sender, EventArgs
e)
{
Label test =
(Label)GridView 1.SelectedRow.C ells[0].FindControl("t estId");
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.