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();
}
}
我这段代码哪里需要改动才可以实现,,新手求指导
[解决办法]