ほとんどが sqldatasource から入力されるドロップダウン リストがあります。
<asp:DropDownList ID="searchApplicationDropDown" runat="server" OnDataBound="searchApplicationDropDown_DataBound" DataSourceID="SqlDataSource8" DataTextField="AppName" DataValueField="PK_Application" AutoPostBack="true"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource8" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" SelectCommand="SELECT [PK_Application], [AppName] FROM [Application] ORDER BY CASE WHEN [PK_Application] = 1 THEN 1 ELSE 2 END, [AppName]">
</asp:SqlDataSource>
さらに、データベースにない 1 行を追加しました。
//add default non selected row outside of database to drop down list
protected void searchApplicationDropDown_DataBound(object sender, EventArgs e)
{
DropDownList list = sender as DropDownList;
if (list != null)
{
list.Items.Insert(0, "--All Applications--");
}
}
ポストバックすると、ドロップダウン リストは最後に選択した位置を保存しません。理由がわかりません。
編集:
/* ===== PAGE LOAD ===== */
protected void Page_Load(object sender, EventArgs e)
{
//default tab behavior if not a postback
if (!IsPostBack)
{
//bind all datafields on startup
dataBindFields();
catagoryDropDown.DataBind();
applicationDropDown.DataBind();
//populate the input fields with the most recent story of the user currently logged in on startup,
//the user drop down menu automatically puts to the top and selects the currently logged in user when the user first goes to the page
populateMostRecentStory(sqlQueryReturnString(getPKofUserLoggedIn).ToString());
//preliminary behavior of panels tabs, tab settings
Tab1.CssClass = "Clicked";
resetTabControlValues();
//set default date range in the search inputs
searchDateFrom.SelectedDate = DateTime.Today.AddDays(-30);
searchDateTo.SelectedDate = DateTime.Now;
//set GridView SQL parameters to default search values intitially and application to all applications
SqlDataSource6.SelectParameters["fromDateParam"].DefaultValue = searchDateFrom.SelectedDate.ToString();
SqlDataSource6.SelectParameters["toDateParam"].DefaultValue = searchDateTo.SelectedDate.AddDays(1).ToString();
SqlDataSource6.SelectParameters["applicationParam"].DefaultValue = "%";
//set gridview parameter with logged in user initially
SqlDataSource6.SelectParameters["userIdSearchParam"].DefaultValue = sqlQueryReturnString(getPKofUserLoggedIn);
}
//shows user whether they are working on a new story or an existing story
showStoryInfo();
searchApplicationDropDown.DataBind();
//set user drop down list server control SQL parameter to currently logged in user so that they are at the top of the list and selected by default
SqlDataSource1.SelectParameters["userLoggedIn"].DefaultValue = User.Identity.Name;