通过单击按钮在asp.net中查看Gridview [英] View Gridview in asp.net by clicking button

查看:85
本文介绍了通过单击按钮在asp.net中查看Gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经将GridView与数据源连接了.它工作正常,但仅在表单加载时显示.我想在用户单击按钮时显示它.怎么做呢?

谢谢

Hi,
I have connected GridView with a datasource. It works fine but it is displayed just at form load. I want to show it when user clicks the button. How to make it so?

Thanks

推荐答案

请提供任何代码示例?
protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            Bind();
        }
    }
private void Bind()
{
  string connectionString =    
  WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
  string selectSQL ="SELECT ProductID, ProductName, UnitPrice FROM Products";
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand(selectSQL, con);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();

            adapter.Fill(ds, "Products");

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

}
//I want to show it when user clicks the button
private void Button1_click(Object sender,EventArgs e)
{
    Bind();
}


[


source[^]


因此,您有任何检查IsPostBack吗?单击按钮绑定数据.
So, do you have any check for IsPostBack ? Bind the Data on Click of Button.


这篇关于通过单击按钮在asp.net中查看Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆