Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I am using a datalist and binding data to it. I have a lable within a table in datalist. On click of that label, I am firing a jquery to perform some action. That jquery requires the id of the label or td or tr to identify the particular row in the dtalist. How to assign unique ID inside a datalist...
Please provide some suggestions...

Here is the code I am using...
<asp:DataList ID="dlMembers" runat="server" CellPadding="0" CellSpacing="0" RepeatLayout="Table"
                                    ShowHeader="true" ViewStateMode="Enabled" RepeatColumns="1" GridLines="Horizontal"
                                    OnItemDataBound="dlMembers_ItemDataBound" Width="100%" OnSelectedIndexChanged="dlMembers_SelectedIndexChanged">
                                    <HeaderStyle Width="100%" />
                                    <ItemTemplate>
                                        <table cellpadding="0" cellspacing="0" border="0" width="100%" class="divContainer1">
                                            <tr>
                                                <td width="10%">
                                                    <asp:Image ID="imgAvailableimage" runat="server" />
                                                </td>
</tr>
<tr>
   <td >       
                                                    <table cellpadding="0" cellspacing="0" border="0" width="100%" class="divContainer">
                                                        <tr>
                                                            <td id="memberID">
                                                                <asp:Label CssClass="labelclass" Text="Show" runat="server" />
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
JavaScript
  $(".divContainer td").click(function (e) {
//perform action
});
Posted
Updated 11-Feb-13 23:36pm
v2

1 solution

try

In "dlMembers_ItemDataBound" you need to find the control and
add one extra attribute to it.


eg.
Label memberID =(Label)e.row.FindControl("memberID");
memberID.Attribute.Add("RowNumber","+(e.RowIndex+1)+");

In client side you will easily get the this attribute.

e.g.
var rowNum=obj.getAttribute("RowNumber");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900