カテゴリでプロジェクトをフィルタリングするために使用される DDL があります。そして、それは完璧に機能します。選択した値を次のようにセッションに保存します。
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Session("Categorie") = DropDownList1.SelectedValue
End Sub
そして、次のように Page_Load でそれを思い出してください。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Cookie()
If Not Page.IsPostBack Then
DropDownList1.SelectedValue = Session("Categorie")
End If
End Sub
また、DDLは DLL 自体に値を表示しますが、それを GridView にバインドしません。
txtboxes でフィルター処理することもできます。まったく同じ方法で値を保存します。
Protected Sub txtKlant_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Session("Klant") = txtKlant.Text
End Sub
また、page_Load でもそれらを呼び出しますが、これらの値はすぐにアクティブになり、Klant (顧客)でフィルター処理されたデータを表示します。
私のコード全体:
ページロード
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Cookie()
If Not Page.IsPostBack Then
DropDownList1.SelectedValue = Session("Categorie")
txtKlant.Text = Session("Klant")
txtWebsite.Text = Session("Website")
txtTitel.Text = Session("Titel")
GridView1.DataBind()
End If
End Sub
セッション
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Session("Categorie") = DropDownList1.SelectedValue
End Sub
Protected Sub txtKlant_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Session("Klant") = txtKlant.Text
End Sub
Protected Sub txtWebsite_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Session("Website") = txtWebsite.Text
End Sub
Protected Sub txtTitel_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Session("Titel") = txtTitel.Text
End Sub
エラーは発生しません。フィルタリングは機能しますが、別のページに移動したときに [戻る] ボタンを押しても、セッションで選択した値が保持されません。したがって、カテゴリの選択は失われます。ただし、同じ方法で処理されるテキストボックスの値は保持されます
/編集//
グリッドビュー:
<asp:GridView ID="GridView1"
runat="server"
AutoGenerateColumns="False"
DataKeyNames="ID"
gridlines="None"
cellpadding="15"
width="980px"
ItemStyle-backcolor="#ebecf0"
AlternatingItemStyle-backcolor="#ebecf0"
AllowPaging="True"
PageSize="4"
onpageindexchanging="GridView1_PageIndexChanging"
datasourceid="SqlDataSource2"
>
//BOUNDED ITEMS//
</GridView>
SQLDATASOURCE
SelectCommand="SELECT * FROM [tbl_Project] INNER JOIN tbl_Cat ON tbl_Project.CatID = tbl_Cat.Cat_ID
INNER JOIN tbl_Klant ON tbl_Project.KlantID = tbl_Klant.Klant_ID
WHERE (([Titel] LIKE '%' + @Titel + '%')
AND ([CatID] = CASE WHEN @CatID = -1 THEN [CatID] ELSE @CatID END) AND ([Bedrijf] LIKE '%' + @Bedrijf + '%')
AND ([Website] LIKE '%' + @Website + '%'))"
deletecommand="DELETE FROM [tbl_Project] WHERE [ID] = @original_ID"
OldValuesParameterFormatString="original_{0}" >
<DeleteParameters>
<asp:Parameter Name="original_ID" Type="Int32" />
</DeleteParameters>
<SelectParameters>
<asp:ControlParameter ControlID="txtTitel" DefaultValue="*" Name="Titel"
PropertyName="Text" Type="String" ConvertEmptyStringToNull="False" />
<asp:ControlParameter ControlID="txtKlant" DefaultValue="*" Name="Bedrijf"
PropertyName="Text" Type="String" ConvertEmptyStringToNull="False" />
<asp:ControlParameter ControlID="txtWebsite" DefaultValue="*" Name="Website"
PropertyName="Text" Type="String" ConvertEmptyStringToNull="False" />
<asp:ControlParameter ControlID="DropDownList1" DefaultValue="1"
Name="CatID" PropertyName="SelectedValue" Type="Int32" ConvertEmptyStringToNull="False" />