asp .net url variable select dropdown list

You would think it would be easy fro a Novice programmer to pre-select a dropdownlist with C# in ASP .Net from a url variable.

Well after an hour of fumbling around I was able to do it.

Page Code:

    <asp:DropDownList ID="txtDepartment" TabIndex="1" style="Z-INDEX: 105; LEFT: 176px; POSITION: absolute; TOP: 48px" runat="server" Width="258px" Height="20px" Font-Names="Verdana" Font-Size="Small">
            <asp:ListItem Value="custlistitemomerservice">Customer Assistance</asp:ListItem>
            <asp:ListItem Value="clientsupport">Client Assistance</asp:ListItem>
            <asp:ListItem Value="portfolioinquiries">Aquisition and Sales</asp:ListItem>
            <asp:ListItem Value="investors">Investor Relations</asp:ListItem>
            <asp:ListItem Value="b2b">Business Development</asp:ListItem>


Page onLoad Code:

       string Department = Request.QueryString["dep"];
            if (!IsPostBack)
                    txtDepartment.Items.FindByValue(Department).Selected = true;
                    txtDepartment.Items.FindByValue("custlistitemomerservice").Selected = true;

Example URL Request:


Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>