如果ASP.Net按钮和GridView位于不同的ASP:Content块中,则刷新ASP.Net GridView

如果ASP.Net按钮和GridView位于不同的ASP:Content块中,则刷新ASP.Net GridView,asp.net,vb.net,gridview,refresh,Asp.net,Vb.net,Gridview,Refresh,如果ASP.Net按钮和GridView位于不同的ASP:Content块中,我们希望刷新ASP.Net GridView 在一个工作的ASP.NETWeb表单中,我们有一个数据源、GridView、DetailsView、各种其他控件、一个ASP:TextBox和一个ASP:Button,用于根据用户在文本框中输入的内容搜索数据。所有这些都在一个asp:Content块中,它还有一个asp:UpdatePanel 我们决定更改表单的布局,分离GridView和DetailsView,并将它们放

如果ASP.Net按钮和GridView位于不同的ASP:Content块中,我们希望刷新ASP.Net GridView

在一个工作的ASP.NETWeb表单中,我们有一个数据源、GridView、DetailsView、各种其他控件、一个ASP:TextBox和一个ASP:Button,用于根据用户在文本框中输入的内容搜索数据。所有这些都在一个asp:Content块中,它还有一个asp:UpdatePanel

我们决定更改表单的布局,分离GridView和DetailsView,并将它们放在另一个asp:Content块中。当表单运行时,所有内容都显示在屏幕上的正确位置,并按预期显示来自数据库的数据

我们发现,如果用户输入搜索条件并单击搜索按钮,代码隐藏文件中的代码会执行,但GridView不会刷新

我将假设需要在代码隐藏文件中添加一些额外的编码来实现这一点

以下是其中一个asp:Content块中搜索按钮的标记:

<asp:Content 
ID="ContentBody" 
ContentPlaceHolderID="BodyPlaceholder" 
runat="server">

<% '-- Ajax enable this area so flicker us cut down to a minumum. -- %>
<% '---------------------------------------------------------------- %>
<asp:UpdatePanel 
    ID="UpdatePanelSummary" 
    runat="server" 
    UpdateMode="Conditional">

    <ContentTemplate> 

        <h1>Classes / Subjects Maintenance</h1>

        Class Search:
        <asp:TextBox 
            ID="TextBoxSearch" 
            runat="server" 
            Width="207px" 
            Text="ALL">
        </asp:TextBox>

        <asp:Button 
            ID="ButtonSearch" 
            runat="server" 
            Text="Search"
            OnClick="ButtonSearch_Click" />

        <asp:Button 
            ID="ButtonSearchAll" 
            runat="server" 
            Text="Show ALL Classes" 
            OnClick="ButtonSearchAll_Click"/>

        <br />

        <asp:Button 
            ID="ButtonAddNewClass" 
            runat="server" 
            Text="Add a New Class to this List" />
        <br />

        <strong><span class="auto-style1">
        <br />
        To send an email of this list, enter the email address of whom you wish to send it to then click the envelope.</span></strong>        
        <br />
        <br />

        Recipient:
        <asp:TextBox ID="TextBoxEmailRecipient" runat="server" Width="203px"></asp:TextBox>
        <strong><span class="auto-style1">&nbsp;</span></strong>

        <asp:ImageButton 
            ID="ImageButtonEmailThisList" 
            runat="server" 
            BorderStyle="None" 
            ImageUrl="~/Images/email1.png" 
            OnClick="ImageButtonEmailThisList_Click" 
            ToolTip="Email this List as a report." Height="50px" Width="50px" 
        />

        <br />
        <asp:Label ID="LabelEmailMessage" runat="server" style="font-weight: 700; color: black"></asp:Label>
        <br />

    </ContentTemplate>
</asp:UpdatePanel>
</asp:Content>

按钮上绑定数据后,您可以调用
UpdatePanelDetails.Update()
。\u单击

Protected Sub ButtonSearch_Click(sender As Object, e As EventArgs)

    ' Show the schedules the user wants.
    '-----------------------------------
    GridViewSummary.DataSource = theTableAdapter.GetDataByAllClasses(TextBoxSearch.Text)
    GridViewSummary.DataBind()
    UpdatePanelDetails.Update()
End Sub
Protected Sub ButtonSearch_Click(sender As Object, e As EventArgs)

    ' Show the schedules the user wants.
    '-----------------------------------
    GridViewSummary.DataSource = theTableAdapter.GetDataByAllClasses(TextBoxSearch.Text)
    GridViewSummary.DataBind()
End Sub
Protected Sub ButtonSearch_Click(sender As Object, e As EventArgs)

    ' Show the schedules the user wants.
    '-----------------------------------
    GridViewSummary.DataSource = theTableAdapter.GetDataByAllClasses(TextBoxSearch.Text)
    GridViewSummary.DataBind()
    UpdatePanelDetails.Update()
End Sub