Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DropDownList and GirdView
Message
From
27/11/2007 12:52:27
 
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
DropDownList and GirdView
Miscellaneous
Thread ID:
01271489
Message ID:
01271489
Views:
61
Hi there,

I have a dropdownlist on the GridView, I can bind the data to the dropdownlist the first time, but after the user selects an item from the list I store that in a table so it can be retrived the next time when the user comes back to the page. But somehow
DropDownList.SelectedValue = myobj.value doesn't work.



Below is the code that I have so far.
<asp:GridView GridLines="None" ID="ItemGridView" runat="server" AutoGenerateColumns="False"
                    Width="100%" DataKeyNames="bvin" CssClass="cartproductgrid" SelectedIndex="0">
                    <Columns>
                        <asp:TemplateField HeaderText="Activity Name">
                            <ItemTemplate>
                               <div class="cartitemimage">
                                    <!--<asp:Image ID="imgProduct" runat="server" AlternateText="" /></div>-->
                                <div id="cartitemdescription" runat="server" class="cartitemdescription">                                    
                                    <asp:LinkButton ID="DescriptionLinkButton" runat="server"></asp:LinkButton>
                                    <asp:PlaceHolder ID="CartInputModifiersPlaceHolder" runat="server"></asp:PlaceHolder>                                    
                                </div>
                            </ItemTemplate>
                            <ItemStyle CssClass="productimagecolumn" />
                            <HeaderStyle HorizontalAlign="Left" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Price">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='< %# Bind("AdjustedPrice", "{0:c}") % >' CssClass="cartproductprice"></asp:Label>
                            </ItemTemplate>                            
                            <ItemStyle CssClass="productpricecolumn" />
                            <HeaderStyle HorizontalAlign="Right" />
                        </asp:TemplateField>
                        
                        <asp:TemplateField HeaderText="Select Student Profile">
                            <ItemTemplate>
                                <div id="studentProfile" runat="server">                                    
                                    <asp:DropDownList  ID="drpStudent"  EnableViewState ="true" runat="server"></asp:DropDownList>                                    
                                </div>
                            </ItemTemplate>
                            <ItemStyle CssClass="productimagecolumn" />
                            <HeaderStyle HorizontalAlign="Left" />
                        </asp:TemplateField>
                       
                        <asp:TemplateField HeaderText="Total">
                            <ItemTemplate>
                                <asp:Label ID="TotalWithoutDiscountsLabel" CssClass="lineitemnodiscounts" runat="server" Text='' Visible="false"></asp:Label>
                                <asp:Label ID="TotalLabel" runat="server" Text='' CssClass="totallabel"></asp:Label>
                            </ItemTemplate>                            
                            <ItemStyle CssClass="producttotalcolumn" />
                            <HeaderStyle HorizontalAlign="Right" />
                        </asp:TemplateField>
                        
                        
                        
                    </Columns>
                </asp:GridView>


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Utilities.WebForms.MakePageNonCacheable(Me)


        If Not Page.IsPostBack Then
            Me.btnContinueShopping.ImageUrl = PersonalizationServices.GetThemedButton("Previous")
            Me.btnStudentProfile.ImageUrl = PersonalizationServices.GetThemedButton("Next")
            Me.btnCheckout.ImageUrl = PersonalizationServices.GetThemedButton("Next")
            LoadCart()
        Else
            If Not _InputsAndModifiersLoaded Then
                ViewUtilities.GetInputsAndModifiersForLineItemDescription(Me.Page, ItemGridView)
            End If
        End If
    End Sub


Private Sub LoadStudentProfile(ByVal drpStudent As DropDownList)
        oStudentProfile = New StudentProfile
        drpStudent.DataSource = oStudentProfile.GetAllStudents(SessionManager.GetCurrentUserId)
        drpStudent.DataTextField = "LastName"
        drpStudent.DataValueField = "StudentID"
        drpStudent.DataBind()
        drpStudent.Items.Insert(0, "- Select Student Profile -")
 End Sub


 Protected Sub ItemGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles ItemGridView.RowDataBound
        Dim drpStudent As New DropDownList
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim lineItem As Orders.LineItem = CType(e.Row.DataItem, Orders.LineItem)
            If lineItem IsNot Nothing Then
                Dim description As LinkButton = CType(e.Row.FindControl("DescriptionLinkButton"), LinkButton)
                If description IsNot Nothing Then
                    description.Text = "<div class=""cartsku"">" & lineItem.AssociatedProduct.Sku & "</div><div class=""cartproductname"">" & lineItem.AssociatedProduct.ProductName & "</div>"
                    description.CommandName = "EditProduct"
                    description.CommandArgument = lineItem.Bvin
                End If

                drpStudent = e.Row.FindControl("drpStudent")
                LoadStudentProfile(drpStudent)

                Dim custproperty As CustomProperty = Nothing
                For Each item As CustomProperty In lineItem.CustomProperties
                    If item.DeveloperId = "bvsoftware" AndAlso item.Key = "quantitychanged" Then
                        description.Text = description.Text & "<div class=""quantitychanged"">" & Content.SiteTerms.GetTerm("QuantityChanged") & "</div>"
                        custproperty = item
                        MessageBox1.ShowInformation(Content.SiteTerms.GetTerm("LineItemsChanged"))
                        Exit For
                    End If

                    If item.DeveloperId = "Acelo" And item.Key = "StudentID" Then
                        drpStudent.SelectedValue = item.Value
                    End If

                Next
                Dim totalLabel As Label = e.Row.FindControl("TotalLabel")
                totalLabel.Text = lineItem.LineTotal.ToString("c")
            End If
        End If
    End Sub


 Private Sub LoadCart()
        Dim Basket As Orders.Order = SessionManager.CurrentShoppingCart

        If Basket IsNot Nothing Then

            If (Basket.Items Is Nothing) OrElse ((Basket.Items IsNot Nothing) AndAlso (Basket.Items.Count <= 0)) Then
                Me.pnlWholeCart.Visible = False
            Else
                If Basket.TotalQuantity > 1 Then
                    Me.lblcart.Text = Basket.TotalQuantity.ToString("#") & " Items in Cart"
                Else
                    Me.lblcart.Text = Basket.TotalQuantity.ToString("#") & " Item in Cart"
                End If

                Me.pnlWholeCart.Visible = True

                Me.lblSubTotal.Text = String.Format("{0:c}", Basket.SubTotal)
                If Basket.OrderDiscounts > 0 Then
                    Me.trDiscounts.Visible = True
                    Me.lblDiscounts.Text = "-" & String.Format("{0:c}", Basket.OrderDiscounts)
                    Me.lblDiscounts.Text += "<br />" & String.Format("{0:c}", (Basket.SubTotal - Basket.OrderDiscounts))
                Else
                    Me.trDiscounts.Visible = False
                End If
                
                Me.ItemGridView.DataSource = Basket.Items
                Me.ItemGridView.DataBind()


                If Basket.TotalQuantity <= 0 Then
                    cartactioncheckout.Visible = False
                End If
            End If
        End If
    End Sub
Please help.

Thanks
Yassin
Reply
Map
View

Click here to load this message in the networking platform