读书人

dropdownlist已绑定 怎么可以在gridvi

发布时间: 2013-12-19 00:33:34 作者: rapoo

dropdownlist已绑定 如何可以在gridview中显示全部
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{

if (!Page.IsPostBack)
{

GridView1.DataSource = GetDataset("select * from TestID").Tables[0];
GridView1.DataBind();

}
}
private DataSet GetDataset(string sql)
{
string strConn = "data source=PC-20130111CRCF\\SQL;initial catalog=Test;uid=sa;password=sa";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();


SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds);

conn.Close();
return ds;
}







protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

SqlDataSource1.SelectCommand = "SELECT * FROM TestID WHERE 周次 = " + DropDownList1.SelectedValue;
}

protected void Button1_Click(object sender, EventArgs e)
{

GridView1.DataSource = GetDataset("SELECT * FROM TestID WHERE 周次");
GridView1.DataBind();


}
}
我这段代码哪里需要改动才可以实现,,新手求指导
[解决办法]

引用:
Quote: 引用:

这是看你的sql查询到的结果,改sql语句去掉重复的绑定上去就行了!
我是直接用dropdownlist绑定的

直接把值写上去的?还是用了数据源控件?你在后台直接写个查询语句绑定上去不好吗??

读书人网 >asp.net

热点推荐