按下按钮后显示gridview

时间:2016-12-09 19:05:04

标签: c# asp.net gridview

我在按下按钮后尝试显示gridview。 这是关于视图的代码:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3">
    <Columns>
        <asp:BoundField DataField="Lounge No" HeaderText="Lounge No" InsertVisible="False" SortExpression="Lounge No" />
        <asp:BoundField DataField="Film Name" HeaderText="Film Name" SortExpression="Film Name" />
        <asp:BoundField DataField="Time" HeaderText="Time" SortExpression="Time" />
        <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
        <asp:BoundField DataField="Type_Description" HeaderText="Type_Description" SortExpression="Type_Description" />
    </Columns>
</asp:GridView>

这就是我在按钮的代码中所拥有的:

protected void Button1_Click(object sender, EventArgs e)
{
    SqlDataSource3.DataBind();
}

1 个答案:

答案 0 :(得分:0)

你可以这样做。

<asp:GridView ID="GridView1" Visible="false" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3">
<Columns>
    <asp:BoundField DataField="Lounge No" HeaderText="Lounge No" InsertVisible="False" SortExpression="Lounge No" />
    <asp:BoundField DataField="Film Name" HeaderText="Film Name" SortExpression="Film Name" />
    <asp:BoundField DataField="Time" HeaderText="Time" SortExpression="Time" />
    <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
    <asp:BoundField DataField="Type_Description" HeaderText="Type_Description" SortExpression="Type_Description" />
</Columns>

添加Visible =&#34; false&#34;属性为gridview。

按钮单击

的代码
protected void Button1_Click(object sender, EventArgs e)
{
      if (GridView1.Visible == false)
      {
            SqlDataSource3.DataBind();
            GridView1.Visible = true;
            Button1.Text = "Hide";
      }
      else
      {
           GridView1.Visible = false;
           Button1.Text = "Show";
      }
}