开发者

SqlDataSource1_Selected not working

I need to be able to change a Boolean variable if a datasource actually retrieves any data, so gridviews/detailsviews a开发者_如何学Cren't displayed. I've placed all the data inside a PlaceHolder tag which is by default not visible.

But using the SqlDataSource1_Selected method, it doesn't actually change the boolean variable - why is this? Here is my code:

    protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        if (e.AffectedRows == 0)
        {
            displayData = false;
        }
        else
        {
            displayData = true;
        }


    }

And this is a snippet from my datasource in ASP to show it is indeed linking to the method:

onselected="SqlDataSource1_Selected"


I think you are going about this the wrong way

Can you try something like this

SqlDataSource DS = new SqlDataSource(); DataView DV = new DataView();

DS.ConnectionString = _Conn_String; DS.SelectCommand = query_String;

DataView DV = new DataView(); DV = (DataView)DS.Select(DataSourceSelectArguments.Empty);

if (DV != null) { //display data } else { //do not display data }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜