Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET4.0
Hello Friends,
I am using Datalist
<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 23-Apr-12 22:40pm
Comments
sam7one at 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
good
Please Sign up or sign in to vote.

Solution 1

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

try this i hope u will get
  Permalink  
v2
Comments
RashdSiddique at 24-Apr-12 4:51am
   
what is dataListItem
pradeep040186 at 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().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
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,680
2 CPallini 4,850
3 George Jonsson 3,454
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 24 Apr 2012
Copyright © CodeProject, 1999-2014
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