Prepopulating my ASP.NET Form
I have this code in my .ascx file (the ascx file is used in my search.aspx and search.aspx.cs files):
<form name="search" method="get" action="s开发者_开发问答earchresults.aspx" id="searchform" runat="server">
<p>Need to refine your search? Use the fields below to narrow results.</p><br />
<input type="text" id="keywordSearch" value="Keyword" />
<div class="advanceSearchBox">
<p><b>Narrow results by:</b></p>
<asp:Literal ID="ltrlExplorePopulation" runat="server" />
<asp:Literal ID="ltrlExploreDatasource" runat="server" />
</div>
<img src="images/go_up.png" alt="GO" name="keywordSearchGO" width="34" height="24" id="keywordSearchGO" />
</form>
I have data in my query string in my search.aspx.cs page that I want to put into the input of the form above. And the first literal ltrlExplorePopulation gets translated to this:
<div class="narrowRes">Poulation</div><select class="narrowResSelect" name="population"><option value="0">All populations</option><option vale="1">Small population</option></select>
So how do I get my query string data into this form?
My search.aspx.cs Page_Load has this:
string keywords = Request.QueryString["keywords"];
string datasources = Request.QueryString["datasources"];
string population = Request.QueryString["population"];
And I want to have keywords be set into the input above, population be set to the select statement, etc. I'm not sure if using Form.Controls.? is correct?
Are the value in the options e.g. "All populations" and "Small Population" dynamic or static?
With static you can do like this:
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="All Population" Value="0"></asp:ListItem>
<asp:ListItem Text="Small Population" Value="1"></asp:ListItem>
</asp:DropDownList>
And in code-behind set the value e.g. DropDownList1.SelectedValue=population; //this comes from your querystring.
Please clarify if I misunderstood your question.
精彩评论