1、如何获得SqlDataSource查询的数据条数
解决办法:
在Selected函数中处理:
protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
Label1.Text = e.AffectedRows.ToString();
}
e在sqldatasources的selected事件中加入以上代码e.AffectedRows获取受影响的行数
2、SqlDataSource1.SelectCommand更改数据源的sql查询语句后并不能显示新的sql语句查询的数据
解决办法:改变sql查询语句后需要调用绑定该数据源(SqlDataSource1)的DataBind函数
3、为绑定了数据源的DropdownList添加数据项,似乎直接在在空间上添加不行!
- if(!IsPostBack)
- {
- DropDownList_news.DataSource = SqlDataSource1; //绑定数据源
- DropDownList_news.DataTextField = "Ncaption"; //显示内容
- DropDownList_news.DataValueField = "Id"; //值字段
- DropDownList_news.DataBind();
- DropDownList_news.Items.Insert(0, new ListItem("---所有---", "-1"));
- DropDownList_news.SelectedIndex = 0;
- }