0

how can i write a selector for specific column of GridView ? i want to do something on mouseover of a GridView Column. and i want to do it once. Here is my gridview :

<asp:GridView AutoGenerateColumns="False" Width="100%" ID="grvUsers" runat="server">
        <Columns>
            <asp:TemplateField HeaderText="Delete">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# eval("ID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
 </Columns>
    </asp:GridView>

Html Output :

<table cellspacing="0" rules="all" border="1" id="grvUsers" style="width:100%;border-collapse:collapse;">
    <tr>
        <th scope="col">Delete</th>
    </tr><tr>
        <td>
                <span id="grvUsers_Label1_0">23</span>
            </td>
    </tr>

</table>

GridView DataBound

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim dr As DataRow
        Dim dt As New DataTable
        dt.Columns.Add("id")
        dr = dt.NewRow
        dr(0) = "23"
        dt.Rows.Add(dr)
        grvUsers.DataSource = dt
        grvUsers.DataBind()
    End Sub
3
  • can you post the generated html please? Commented Apr 5, 2011 at 4:45
  • Is it the Delete column or the other one? Commented Apr 5, 2011 at 5:11
  • This is delete, delete is just a sample name for this question. Commented Apr 5, 2011 at 5:12

1 Answer 1

1

In your itemtemplate, include a CssClass like this:

<asp:TemplateField HeaderText="Delete" ItemStyle-CssClass="myRow">
    <ItemTemplate>
        <asp:Label ID="Label1" runat="server" Text='<%# eval("ID") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

If you also need the header to be selectable, then include the HeaderStyle-CssClass property as well.

Then you can use $("td.myRow").bind("mouseover", function() { }); to bind an event to each cell in the column.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.