我有一个用于过滤类别项目的 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>
SQL 数据源
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" />