使用按钮执行的SqlDataSource [英] execute sqldatasource with button

查看:526
本文介绍了使用按钮执行的SqlDataSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我希望能够到一个页面上运行两个查询。我有在页面和另一个按钮,GridView和SqlDataSource的在底部的第二查询的顶部的一个按钮,GridView和SqlDataSource的

I have two queries that I want to be able to run on a page. I have a button, gridview and sqldatasource at the top of the page and another button, gridview and sqldatasource with the second query at the bottom.

我如何的按钮与特定网格和数据源关联。

How do I associate the buttons with their particular grid and datasource.

现在,当我点击任一按钮,既gridview1和gridview2填充。

right now when I click either button, both gridview1 and gridview2 populate.

推荐答案

我在你的grdiviews你的DataSource属性设置为SQL数据源之一的标记假设。

I'm assuming in the markup for your grdiviews you have set the datasource property to one of the sql data sources.

我还要上你不希望在GridView的任何数据,假设在第一次加载页面。

I'm also going on the assumption that you do not want any data in the gridviews when the page first loads.

如果是这样的话你可以简单地离开GridView的空白的DataSource属性。然后,在按钮单击事件处理程序,你可以填入你想要的网格视图。

If that is the case you can simply leave the datasource property of the gridviews blank. Then in the click event handler for the buttons you can populate the grid view you want.

下面是C#code我以前做这个

Here is the c# code I used to do this

 protected void Button2_Click(object sender, EventArgs e)
    {
        GridView1.DataSource = SqlDataSource1;
        GridView1.DataBind();
        //If you only want to show one grid at a time
        GridView2.DataSource = null;
        GridView2.DataBind();
    }

    protected void Button3_Click(object sender, EventArgs e)
    {
        GridView2.DataSource = SqlDataSource2;
        GridView2.DataBind();
        //If you only want to show one grid at a time
        GridView1.DataSource = null;
        GridView1.DataBind();
    }

这篇关于使用按钮执行的SqlDataSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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