SqlDataSource1_Selected 不起作用
如果数据源实际检索任何数据,我需要能够更改布尔变量,因此不会显示 gridviews/detailsviews。我已将所有数据放置在 PlaceHolder 标记内,该标记默认情况下不可见。
但是使用 SqlDataSource1_Selected 方法,它实际上并没有更改布尔变量 - 这是为什么?这是我的代码:
protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
if (e.AffectedRows == 0)
{
displayData = false;
}
else
{
displayData = true;
}
}
这是我在 ASP 中的数据源的一个片段,显示它确实链接到该方法:
onselected="SqlDataSource1_Selected"
I need to be able to change a Boolean variable if a datasource actually retrieves any data, so gridviews/detailsviews aren'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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的处理方式是错误的,
您可以尝试这样的方法吗?
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)
{
//显示数据
}
别的
{
//不显示数据
}
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
}