Gridview显示不出来。 15
DataSetds=newDataSet();SqlDataAdapterMyAdapter=newSqlDataAdapter(sql,cn);MyAdapter.Fi...
DataSet ds = new DataSet();
SqlDataAdapter MyAdapter = new SqlDataAdapter(sql,cn);
MyAdapter.Fill(ds, "list");
GridView1.DataSource = ds.Tables["list"].DefaultView;
GridView1.DataBind();
sql是查询语句,我感觉我已经绑定数据源了,实在不知道为是什么。
本人新手,希望大神详细解答,谢谢。
下面是我整个代码,假如上面没问题麻烦看一下
protected void sel_Click(object sender, EventArgs e)
{
string strconn = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection cn = new SqlConnection(strconn);
cn.Open();
string name1 = name.Text.ToString();
string title1 = title.Text.ToString();
string server1 = ddl1.SelectedItem.ToString();
string type1 = DropDownList1.SelectedItem.ToString();
string sqlname = "";
if (name1 != "")
{
sqlname = " and service_customer_name='" + name1 + "' ";
}
string sqltitle = "";
if (title1 != "")
{
sqltitle = " and service_title like '%" + title1 + "%' ";
}
string sqlren = "";
if (server1 != "")
{
sqlren = " and service_type='" + server1 + "' ";
}
string sql = "select * from service where service_status='" + type1 + "'";
sql += sqlname;
sql += sqltitle;
sql += sqlren;
DataSet ds = new DataSet();
SqlDataAdapter MyAdapter = new SqlDataAdapter(sql,cn);
MyAdapter.Fill(ds, "list");
GridView1.DataSource = ds.Tables["list"].DefaultView;
GridView1.DataBind();
cn.Close();
} 展开
SqlDataAdapter MyAdapter = new SqlDataAdapter(sql,cn);
MyAdapter.Fill(ds, "list");
GridView1.DataSource = ds.Tables["list"].DefaultView;
GridView1.DataBind();
sql是查询语句,我感觉我已经绑定数据源了,实在不知道为是什么。
本人新手,希望大神详细解答,谢谢。
下面是我整个代码,假如上面没问题麻烦看一下
protected void sel_Click(object sender, EventArgs e)
{
string strconn = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection cn = new SqlConnection(strconn);
cn.Open();
string name1 = name.Text.ToString();
string title1 = title.Text.ToString();
string server1 = ddl1.SelectedItem.ToString();
string type1 = DropDownList1.SelectedItem.ToString();
string sqlname = "";
if (name1 != "")
{
sqlname = " and service_customer_name='" + name1 + "' ";
}
string sqltitle = "";
if (title1 != "")
{
sqltitle = " and service_title like '%" + title1 + "%' ";
}
string sqlren = "";
if (server1 != "")
{
sqlren = " and service_type='" + server1 + "' ";
}
string sql = "select * from service where service_status='" + type1 + "'";
sql += sqlname;
sql += sqltitle;
sql += sqlren;
DataSet ds = new DataSet();
SqlDataAdapter MyAdapter = new SqlDataAdapter(sql,cn);
MyAdapter.Fill(ds, "list");
GridView1.DataSource = ds.Tables["list"].DefaultView;
GridView1.DataBind();
cn.Close();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询