GridView1”的 DataSourceID 必须是 IDataSource 类型的控件的 ID未能找到 ID 为“SqlDataSource1”的控件
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSys...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack){
svoid();
}
}
protected void svoid() {
string sql = "select * from TBL_MESSAGE";//定义sql查询语句
string conStringSql = "Data Source=XIAOLIU-PC;Initial Catalog=MessageNew;Persist Security Info=True;User ID=sa;password=sa";
SqlConnection con = new SqlConnection(conStringSql);
SqlDataAdapter adapter = new SqlDataAdapter(sql,con);
DataSet ds = new DataSet();
con.Open();
adapter.Fill(ds, "TBL_MESSAGE");
GridView1.DataSource = ds;
GridView1.DataKeyNames=new string[]{"id"};
GridView1.DataBind();
con.Close();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
} 展开
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack){
svoid();
}
}
protected void svoid() {
string sql = "select * from TBL_MESSAGE";//定义sql查询语句
string conStringSql = "Data Source=XIAOLIU-PC;Initial Catalog=MessageNew;Persist Security Info=True;User ID=sa;password=sa";
SqlConnection con = new SqlConnection(conStringSql);
SqlDataAdapter adapter = new SqlDataAdapter(sql,con);
DataSet ds = new DataSet();
con.Open();
adapter.Fill(ds, "TBL_MESSAGE");
GridView1.DataSource = ds;
GridView1.DataKeyNames=new string[]{"id"};
GridView1.DataBind();
con.Close();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询