0

I have a gridview and it has HTML label element like below:

<asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="false">
<Columns>
    <asp:TemplateField HeaderText="ID" ItemStyle-Width="2%">
        <ItemTemplate>
            <label id="test" runat="server" title="" />
        </ItemTemplate>
    </asp:TemplateField>
</Columns>

I want to change title attribute of label on C#. I tried this code below bu it did not work.

Label test= (Label)GridView1.Rows[1].Cells[1].FindControl("test");
test.ToolTip= "abc";

Am I missing something or did something wrong? I know I can use <asp:Label> but I don't want to

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Be Ta
  • 45
  • 11
  • There was an article on this issue. maybe it will help you https://stackoverflow.com/questions/6873973/how-to-find-control-in-templatefield-of-gridview – NgocLH May 20 '19 at 10:24
  • try adding the name attribute to the label and then use `var labels = document.getElementByName('test');`. this will return an array. You can then just use the row number to get it... `var label = labels[rownum];` – Kevbo May 20 '19 at 19:26
  • Thanks for answering, but I want to get that label on server side with C#. – Be Ta May 21 '19 at 05:58

0 Answers0