回传后面板和datagridview有多清晰?

时间:2016-12-14 12:29:02

标签: c# asp.net datagridview postback clear

我希望在Postback(下载按钮)后清除面板和datagrdiview。 当我第二次点击搜索数据(查询按钮)时。 datagridview现在显示2个网格和2个面板(不工作绑定,不刷新网格)。

单击按钮Postback后,

第一个网格是旧数据不清晰。 第二个网格是新数据。

设计ASPX C#

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
 <div style="padding: 5px 10px 5px 10px; text-align: center;">
  <asp:UpdatePanel ID="udpMain" runat="server" UpdateMode="Conditional" >        
  <ContentTemplate>
   <asp:Panel ID="pnlQuery" Visible="true" runat="server">
     <fieldset style="width: 50%;">
      <legend>Query Conditions: </legend>
       <table>
        <tr>
         <td>
         //Condition Search        
         </td>                                
        </tr>                                           
       <tr>
       <td colspan="2" align="center">
         <table>                                        
          <tr>
           <td>                                            
            <asp:Button ID="btnQuery" CssClass="btn" runat="server" Text=" Query " Visible="false" OnClick="btnQuery_Click" />       
           </td>
          <td>
            <asp:Button ID="btnClear" CssClass="btn" runat="server" Text=" Clear " Visible="false" OnClick="btnClear_Click" />
           </td>                                            
          </tr>
         </table>
        </td>
       </tr>                            
      </table>
     </fieldset>
    </asp:Panel>

   <tr>
     <td align="center">                        
      <asp:Panel ID="pnDetails" runat="server" GroupingText="TAP File" Width="30%">
       <asp:GridView ID="gvDetail" runat="server" Width="30%" SkinID="gvSkSearch" PageSize="50" OnPageIndexChanging="gvDetail_PageIndexChanging" AutoGenerateColumns="False"
OnRowDataBound="gvDetail_RowDataBound" >
       <Columns>
         //Condition Columns                           
       </Columns>
      </asp:GridView>
     </asp:Panel>                             
    </td>
   </tr>
    <tr>
     <td align="center">
       <asp:Button ID="btnDownload" runat="server" CssClass="btn" OnClick="btnDownload_Click" Text=" Download " Visible="false" />
       <asp:Button ID="btnConfirmTAP" runat="server" CssClass="btn" OnClick="btnConfirmTAP_Click" Text=" Confirm send TAP " Visible="false" 
       Width="120px" />
      </td>
     </tr>
    </br>
   </ContentTemplate>
   <Triggers>
     <asp:PostBackTrigger ControlID="btnDownload" />
   </Triggers>           
  </asp:UpdatePanel>
 </div>
</asp:Content>

c#中

public void btnQuery_Click(object sender, EventArgs e)
{
    //.... dt = list data

    if (dt != null && dt.Rows.Count > 0)
    {
        gvDetail.DataSource = dt;
        gvDetail.DataBind();
        pnDetails.Visible = true;
        btnDownload.Visible = true;
        btnConfirmTAP.Visible = true;
    }
    else
    {
        pnDetails.Visible = false;
        btnDownload.Visible = false;
        btnConfirmTAP.Visible = false;
    }
}

如何清除面板和datagridview后回发。 谢谢提前:))

1 个答案:

答案 0 :(得分:0)

您可以通过将null绑定到它来清除GridView。

GridView1.DataSource = null;
GridView1.DataBind();

你可以清除这样的面板

Panel1.Controls.Clear();