Click here to Skip to main content
16,016,623 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hello Friends,
I am using Datalist
XML
<asp:DataList ID="dlCategories" runat="server" DataKeyField="KBCategoryID" RepeatDirection="Horizontal" RepeatColumns="5" >
            <ItemTemplate>
<div style="padding:15,15,15,15;font-size:10pt;font-family:Verdana">
<div style="font:12pt verdana;color:darkred">
<i><b><asp:LinkButton ID="lnkTitle" runat="server"
        Text= '<%# DataBinder.Eval(Container.DataItem, "Title")%>'
        style="text-decoration:none;" onclick="lnkTitle_Click" />
</i></b>
<asp:Label ID="lblspace" runat="server" Width="50px" Text="" />
</div>
</div>
</ItemTemplate>
        </asp:DataList>

I want to retrieve the value of DataKey on click of link button.

Please help me out of this.
Posted
Comments
sam7one 14-Aug-13 2:42am    
HI, I am having a same problem. I have to populate categories from DB to Datalist and when user will click specific category I have to populate subcategories from DB and show them in another Datalist within the Category datalist. But how could I assign "KBCategoryID" to DataKeyField attribute. could you provide me codebehind for the same

1 solution

C#
int i = DataList1.DataKeys[dataListItem.ItemIndex];

try this i hope u will get
 
Share this answer
 
v2
Comments
RashdSiddique 24-Apr-12 4:51am    
what is dataListItem
pradeep040186 24-Apr-12 4:52am    
var button = sender as Button; if (button == null) return; var dataListItem = button.NamingContainer as DataListItem; if (dataListItem == null) return; var currentKey = DataList1.DataKeys[dataListItem.ItemIndex]; var myLabel = button.Parent.Controls.Cast<control>().FirstOrDefault(x => x.ID == "testLabel") as Label; if (myLabel == null) return; var myLabelText = myLabel.Text;

try this

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