Solved

selectedvalue on dropdown not selecting option  inside gridview

Posted on 2011-02-11
1
364 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 34872812
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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

729 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