开发者

jQuery Selector ASP.NET GridView Column

开发者 https://www.devze.com 2023-02-22 06:02 出处:网络
how can i write a selector for specific column of GridView ? i want to do something on mouseover of a GridView Column.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消