1

カテゴリでプロジェクトをフィルタリングするために使用される 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" />    
4

2 に答える 2

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
于 2013-06-10T11:25:45.257 に答える
1

データバインドのイベント ハンドラーを作成したコードがわかりません。

必要な手順を示すために、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

これで問題が解決しない場合は、お知らせください。

于 2013-06-07T09:48:15.743 に答える