Solved

selectedvalue on dropdown not selecting option  inside gridview

Posted on 2011-02-11
1
352 Views
Last Modified: 2012-05-11

why is my selectedvalue on dropdown not selecting option that is already in the database?  
list shows but nothing is selected.  

          <asp:TemplateColumn HeaderText="Whse" ItemStyle-HorizontalAlign="Center">
                                                          <ItemTemplate>
                                                                <asp:Label id="lblWhse" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.whse") %>'>
                                                                </asp:Label>
                                                          </ItemTemplate>
                                                          <EditItemTemplate>
                                                                <asp:DropDownList id="lstWhse" runat="server" Width="63px"   AppendDataBoundItems="true" DataValueField="whse" DataTextField="whse" CssClass="textbox1">
                                                                 
                                                                  </asp:DropDownList>
                                                             
                                                          </EditItemTemplate>
                                                    </asp:TemplateColumn>
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand


        Try

            DataGrid1.Columns(13).Visible = True
            DataGrid1.EditItemIndex = e.Item.ItemIndex

  

            FillGrid()


            Dim itemWhse As New System.Web.UI.WebControls.DropDownList
            itemWhse = DirectCast(DataGrid1.Items(e.Item.ItemIndex).FindControl("lstWhse"), DropDownList)
            ' itemWhse = CType(e.Item.Cells(9).FindControl("lstWhse"), System.Web.UI.WebControls.DropDownList)

            If Session("usertype") = "ASC" Then

                Dim defaultwhse As String = ""
                defaultwhse = c1.getDefaultWhse
                If defaultwhse = "OR" Then
                    itemWhse.Items.Add(New ListItem("SALE", "SALE"))
                    itemWhse.Items.Add(New ListItem(defaultwhse, defaultwhse))
                ElseIf defaultwhse = "SALE" Then
                    itemWhse.Items.Add(New ListItem("OR", "OR"))
                    itemWhse.Items.Add(New ListItem(defaultwhse, defaultwhse))
                Else
                    itemWhse.Items.Add(New ListItem("OR", "OR"))
                    itemWhse.Items.Add(New ListItem("SALE", "SALE"))
                    itemWhse.Items.Add(New ListItem(defaultwhse, defaultwhse))
                End If


            Else

                itemWhse.Items.Add(New ListItem("GA", "GA"))
                itemWhse.Items.Add(New ListItem("MO", "MO"))
                itemWhse.Items.Add(New ListItem("NY", "NY"))
                itemWhse.Items.Add(New ListItem("OR", "OR"))
                itemWhse.Items.Add(New ListItem("SALE", "SALE"))
                itemWhse.Items.Add(New ListItem("123", "123"))



            End If

        Catch ex As Exception
            sbody = "SQL=" & strSQL & " User=" & Session("username") & " Cust=" & Session("cust") & ", Estimate=" & Session("head_num")
            c1.handleError("datagrid1EditCommand", ex.Message, sbody)
        End Try


    End Sub

Open in new window

0
Comment
Question by:Wigging
1 Comment
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
Comment Utility
You need to use the bind command to bind it to the value being returned from the database.

<asp:DropDownList id="lstWhse" runat="server" Width="63px"   AppendDataBoundItems="true" DataValueField="whse" DataTextField="whse" selectedValue=<%# Bind(mydatabasefield)%> CssClass="textbox1">
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now