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;
- }