gregind Level: Protégé
 Registered: 22-03-2006 Posts: 6
|
ASP.NET DataList Problems!
Hi all!
I have been working with a datalist ins Asp.NET for the first time with limited success. It is the only data presentation control that gets the affect we want. I amd filling the datalist with the contents of a XML file using a dataset and a data view and the control fills perfectly and looks great. The problem is I want to make the title of item a linkbutton and when the linkbutton is clicked the data for that Item is stroed in a session variable then a "details" page is called up that will display the greater details of the item. My problem has been getting an event to actually fire when a user clicks the title. I found out a way to get an event to fire but I lose the index of the item that fired the event!!! So I can't pull the data out of the datalist properly!! Help! Here is the code:
This is the aspx code for the data list:
<asp ataList ID="dlBestsellers" runat="server" RepeatColumns="5" CellPadding="2" CellSpacing="2" GridLines="None" RepeatDirection="Horizontal" ShowFooter="False" Width="740px">
<HeaderTemplate>
<div style="text-align:left;">
<h3>Shop for these Bestsellers Now!</h3></div>
</HeaderTemplate>
<ItemTemplate>
<asp:Image id="Image" height="110" Width="73" ImageUrl='<%# Eval("Image") %>' runat="server" />
<br />
<asp:LinkButton id="btnTest" Text='<%# Eval("Title") %>' runat="server" CommandName="Show" OnCommand="ButtonClick"></asp:LinkButton>
<br />
<asp:Label id="author" Text='<%# Eval("Author") %>' runat="server" />
</ItemTemplate>
<ItemStyle CssClass="DatalistItem" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" Wrap="False" />
<AlternatingItemStyle CssClass="DatalistAItem" Font-Bold="False" Font-Italic="False" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False" Wrap="False" />
<HeaderStyle cssclass="DatalistHeader" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" Wrap="False" />
</asp ataList>
Here is the event code:
Public Sub ButtonClick(ByVal sender As Object, ByVal e As CommandEventArgs)
'Session("title") = DirectCast(dlBestsellers.FindControl("btnTest"), LinkButton).Text
'Session("title") = DirectCast(dlBestsellers.Items.Item(0).FindControl("author"), Label).Text
Session("title") = DirectCast(dlBestsellers.Items.Item(0).FindControl("btnTest"), LinkButton).Text
Response.Redirect("details.aspx")
End Sub
This is all code behind VB.net Framework target 2.0
AS you can see the event fires and when I specify the index (i.e. 0) I get data but I need to know the index of the item selected to get the data the user asked for. When I use datalist.selectedindex I get -1 so it seems to me I am losing the item index!!!
Thanks in advance
!
|