Full disclosure: I'm very new to .NET and sort of feeling my way through it. Been asked to make a tweak and I'm not sure exactly where to start. Was hoping someone might be able to provide a helpful link or example. Would be greatly appreciated.
Basically, I'd like to read in a querystring... let's call it "inquirytype". If that querystring is equal to "other", I want to change the selection in a dropdown box that I have in my .ascx control (see below):
<asp:DropDownList ID="inquiry_type" runat="server" CssClass="inquiry_type">
<asp:ListItem Value="" Selected="True">Select Below</asp:ListItem>
<asp:ListItem>Place an Order</asp:ListItem>
<asp:ListItem>Order Status</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
Is there a way I can keep this code in my .ascx file and still achieve this by adding something to my .cs file? Or must I create a function in my .cs that creates this dropdown list altogether?
Thanks in advance!
Try something like this:
DropDownList1.SelectedValue = Request.QueryString["foo"];
You can also do it like this:
ListItem item = DropDownList1.Items.FindByValue(Request.QueryString["foo"]);
if (item != null)
{
item.Selected = true;
}
I don't think you'll need to test for null, but incase you do:
DropDownList1.SelectedValue = Request.QueryString["foo"] ?? String.Empty;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With