0

UpdatePanelには次のコードがあります。

 <asp:UpdatePanel 
    ID="UpdatePanelSearch" 
    runat="server" 
    UpdateMode="Conditional">

    <ContentTemplate> 
        <p>Parent Search:
            <asp:TextBox ID="TextBoxSearch" runat="server" Width="207px"></asp:TextBox>
            <asp:Button ID="ButtonSearch" runat="server" Text="Search" />
        </p>
    </ContentTemplate>
 </asp:UpdatePanel>

VBファイルのコードは、[検索]ボタンのクリックを処理するために次のようになり、GridViewはTextBoxに入力された値に基づいてデータを表示します。

GridViewも別のUpdatePanelにあります。

Protected Sub ButtonSearch_Click(sender As Object, e As EventArgs) Handles ButtonSearch.Click

    GridViewParentsSummary.DataSource = theTableAdapter.GetData(strSearchText)
End Sub

ここで正しいことを行う場合は、GridViewを更新するトリガーを作成します。

これがGridViewです。

    <ContentTemplate> 
        <asp:GridView
            ID="GridViewParentsSummary" 
            runat="server" 
            AllowPaging="True" 
            AllowSorting="True" 
            AutoGenerateColumns="False" 
            DataKeyNames="ID" 
            PageSize="3"
            >

            <Columns>

                <asp:BoundField 
                    DataField="FatherName" 
                    HeaderText="Father's Name" 
                    SortExpression="FatherName" />

                <asp:BoundField 
                    DataField="MotherName" 
                    HeaderText="Mother's Name" 
                    SortExpression="MotherName" />

                <asp:ButtonField 
                    ButtonType="Button" 
                    CommandName="Select" 
                    Text="Select This Parent" />
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

GridViewを更新する正しいトリガーを作成するために必要なコードを表示できますか?

4

1 に答える 1

1

が別の場所にある場合GridViewは、別のUpdatePanel更新時にも更新する必要がありUpdatePanelます。デフォルトでは、このUpdatePanel.UpdateModeプロパティは に設定されてAlwaysおり、これによりページ内のすべてUpdatePanelが更新されます。

ただし、これは常に望ましい動作であるとは限らないため、何度も変更して、トリガーの 1 つが起動された場合にのみ が更新されることConditionalを意味します。UpdatePanelその場合、ButtonSearch_Clickメソッドに次の行を追加する必要があります。

gridUpdatePanel.Update() 'assuming gridUpdatePanel is the UpdatePanel with the grid

UpdateModeプロパティ の詳細については、 http: //msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.updatemode.aspxを参照してください。

于 2012-09-23T14:59:14.127 に答える