我有一个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。
您也可以在txtbox上过滤它,我以完全相同的方式保存值:
Protected Sub txtKlant_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Session("Klant") = txtKlant.Text
End Sub
并且还在page_Load上调用它们但是这些值在中间活动并显示在 Klant (客户)上过滤的数据
我的整个代码:
的 pageLoad的 的
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
我没有收到任何错误。过滤确实有效,但是当我去的时候 其他页面,按后退按钮它不保持所选的值 会议。因此,类别的选择将丢失。但它确实保留了它的价值 以相同方式处理的文本框
的 / EDIT // 的
GridView的:
<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" />
答案 0 :(得分:2)
我找到了一个非常简单的修复方法。今天早上我有一个明确的时刻。修正如下:
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 Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Cookie()
If Not Page.IsPostBack Then
DropDownList1.SelectedValue = Session("Categorie")
If DropDownList1.SelectedValue = Session("Categorie") = True Then
GridView1.DataBind()
txtKlant.Text = Session("Klant")
txtWebsite.Text = Session("Website")
txtTitel.Text = Session("Titel")
GridView1.DataBind()
End If
End If
End Sub
答案 1 :(得分:1)
我无法在您的代码中看到您为databind创建了一个事件处理程序。
我从MSDN中获取了一些示例,以显示您需要的步骤。
Function CreateDataSource() As ICollection
'put your data source in here
End Function 'CreateDataSource
'Declaration
Public Event ItemDataBound As DataGridItemEventHandler
Sub Item_Bound(sender As Object, e As DataGridItemEventArgs)
Label1.Text = Label1.Text & " " & e.Item.ItemIndex
End Sub 'Item_Bound
Sub Page_Load(sender As Object, e As EventArgs)
' Manually register the event-handling method for the
' ItemDataBound event of the DataGrid control.
AddHandler ItemsGrid.ItemDataBound, AddressOf Item_Bound
' Load sample data only once, when the page is first loaded.
If Not IsPostBack Then
ItemsGrid.DataSource = CreateDataSource()
ItemsGrid.DataBind()
End If
End Sub
我建议你查看这个链接,这里太详细了,无法重申。
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.itemdatabound.aspx
如果这不能解决您的问题,请告知我们。