Click here to Skip to main content
12,999,633 members (42,357 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello Friends,
I am using Datalist
<asp:DataList ID="dlCategories" runat="server" DataKeyField="KBCategoryID" RepeatDirection="Horizontal" RepeatColumns="5" >
<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" />
<asp:Label ID="lblspace" runat="server" Width="50px" Text="" />

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

Please help me out of this.
Posted 23-Apr-12 22:40pm
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

try this i hope u will get
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 24 Apr 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100