Obtenga la fila seleccionada de la vista de cuadrícula en asp.net

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

por favor me ayude

preguntado el 10 de marzo de 12 a las 07:03

1 Respuestas

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")).Texto;

You are missing Text property in the code above.

respondido 10 mar '12, 07:03

ahh!! the rowcommand is fired when any event is raised by any control in a single row of the grid... here you need to set CommandArgument on the Label to track the rowIndex in the event as RowCommand does not have such a property called rowIndex. Have a look here for this - aspsnippets.com/Artículos/… . This will surely help. - Dinesh

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.