Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

selectedvalue on dropdown not selecting option  inside gridview

Posted on 2011-02-11
1
Medium Priority
?
374 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 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

963 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