I have a GridView , and the GridView has an item template. Now I need to get the value of the first cell which contains the value I need but I have tried the following and does not work, it eturns a “”
int id = Convert.ToInt32(GridView.Rows[index].Cells[0].Text);
Here is the code I have in the gridview
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label runat="server" ID="lblDepartmentID" Text='<%#DataBinder.Eval(Container.DataItem,"DepartmentID")%>' />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
I have to emphazise that I do not want to use the GridView_RowCommand or other GridView events.. I need to pull this value upon clicking a button on the same page.
How can I do this?
If you are trying to access the text value of
Labelthen you have to first get the reference toLabelcontrol like this:and then use it’s
Textproperty to get the value required: