Will's Life – Blog

URL Variable

Automatically Select a Dropdown ListItem Value

asp .net url variable select dropdown list

Oct. 14th | Posted by 0 comments

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:

0 comments Add a comment

No comments yet.

Add a Comment

reset all fields