borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Help on sending and receiving sms using vb)Next Topic (Open new form when cell in datagridview is clicked) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : ASP.NET DataList Problems!
Poster Message
gregind
Level: Protégé

Registered: 22-03-2006
Posts: 6

Ads by Lake Quincy Media
icon 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:

<aspataList 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" />
                </aspataList>    

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
!

02-04-2009 at 12:49 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VB.Net : ASP.NET DataList Problems!
Previous Topic (Help on sending and receiving sms using vb)Next Topic (Open new form when cell in datagridview is clicked) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincaniborder