Solved

selectedvalue on dropdown not selecting option  inside gridview

Posted on 2011-02-11
1
356 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
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Exceptions 3 44
.net and XML report from SCCM 5 23
Set value of dynamically created checkboxlist 2 33
jQuery - following an example but can I save data server side? 20 49
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…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 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