We help IT Professionals succeed at work.
Get Started

Setting the SelectedValue property of a DropdownList within a Gridview

rito1
rito1 asked
on
393 Views
Last Modified: 2009-12-16
Hi All
I have a databound Gridview which contains a Template field like so…

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" PageSize="50">
<Columns>
            <asp:TemplateField HeaderText="Destination" SortExpression="DESTINATION">
                <ItemStyle HorizontalAlign="Left" />
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("DESTINATION") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server">
                        <asp:ListItem Value="England">England</asp:ListItem>
                        <asp:ListItem Value="USA">USA</asp:ListItem>
                        <asp:ListItem Value="France">France</asp:ListItem>                  
                    </asp:DropDownList>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:CommandField ShowEditButton="True" />
        </Columns>
    </asp:GridView>

In VB, please could anyone suggest a way to set the Dropdownlist’s selected value to be the value bound within Label1’s text property?
e.g. When ther Gridview is viewed, Label1’s text property is set to USA. Then when the user selects ‘Edit’ they are presented with the dropdownlist with USA selected as its default selected item.
Many thanks
Rit
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 3 Answers and 12 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE