【新手问题】GridView显示不出来。
DataSet ds = new DataSet();
SqlDataAdapter MyAdapter = new SqlDataAdapter(sql,cn);
MyAdapter.Fill(ds, "list");
GridView1.DataSource = ds.Tables["list"].DefaultView;
GridView1.DataBind();
代码如上,我在网上搜了搜问题,人家说绑定了数据源就能显示出来,我感觉我这个应该绑定了吧,新手不是很懂。
PS:在.ASPX文件中点右上角的小三角形显示的是未绑定数据源。下面附上其余部分程序,不知道问题会不会出现在别的地方。
protected void Page_Load(object sender, EventArgs e)
{
}
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 server1 = "";
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&