Me gustaría saber como puedo "coger" o "seleccionar" un label de un gridview.
Tengo este gridview en mi pagina aspx:
Código ASP:
Ver original
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id_user" DataSourceID="ObjectDataSource1" SkinID="GV" style="margin-top: 0px" AllowPaging="True" AllowSorting="True" > <Columns> <asp:TemplateField HeaderText="Pool" SortExpression="pool"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("pool") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Name" SortExpression="name"> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("name") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="User Id" SortExpression="id_user"> <ItemTemplate> <asp:Label ID="Label11" runat="server" Text='<%# Bind("id_user") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Launch"> <ItemTemplate> <asp:Button ID="LaunchButton" runat="server" Text="Launch" CssClass="normalButton" onclick="btnLaunch_Click" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
y en mi fichero .cs me gustaria coger el valor de label11.
he intentado lo siguiente:
Código c#:
Ver original
count.id_user = GridView1.Label11.Text;
Error: 'System.Web.UI.WebControls.GridView' does not contain a definition for 'Label11' and no extension method 'Label11' accepting a first argument of type 'System.Web.UI.WebControls.GridView' could be found (are you missing a using directive or an assembly reference?)
Tambien intente esto:
Código c#:
Ver original
count.id_user = Convert.ToInt32(GridView1.SelectedRow.Cells[3].Text);
Error: Object reference not set to an instance of an object.
[NullReferenceException: Object reference not set to an instance of an object.]
Warehouse_Warehouse_Launch_Count.btnLaunch_Click(O bject sender, EventArgs e) in c:\inetpub\wwwroot\Walt\Logistics\Launch_Count.asp x.cs:39
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
¿Alguien sabe que hago mal?¿Como podría coger ese dato?
Muchas gracias por su ayuda!
Un saludo.