Solved

selectedvalue on dropdown not selecting option  inside gridview

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 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