I wan to get id from the gridview and using this code
string UserID = ((Label)grdUser.SelectedRow.FindControl(“UserID”)).ToString();
Gridview code
<asp:TemplateField HeaderText="userID" Visible="False">
<ItemTemplate>
<asp:Label ID="UserID" runat="server" Text='<%# Bind("iduser_Detail") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Getting error object reference null
please help me
First of all make sure you are writting this in SelectedRow event and then
Most probably you are writting your in wrong event handler.
You seem to be calling it when selecting a row in the grid. Write this code in selectedrow event of grid.
The way you will need to access the label is
string UserID = ((Label)grdUser.SelectedRow.FindControl(“UserID”)).Text;
You are missing Text property in the code above.