查询数据时,查询条件绑定在DropDownList里,查询结果显示在Gridview里解决思路
查询数据时,查询条件绑定在DropDownList里,查询结果显示在Gridview里
查询数据时,查询条件绑定在DropDownList里, 然后放一个Textbox一个button(查询) 点击按钮
查询结果显示在Gridview里
怎么做 有代码吗??
------解决方案--------------------
查询数据时,查询条件绑定在DropDownList里, 然后放一个Textbox一个button(查询) 点击按钮
查询结果显示在Gridview里
怎么做 有代码吗??
------解决方案--------------------
public partial class admin_alladmin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//页面的判断
if (!this.IsPostBack)
{
dd();//页面加载数据绑定
}
}
private void dd()// GridView火速据绑定
{
string strcon = System.Configuration.ConfigurationManager.ConnectionStrings["mycon"].ConnectionString;
OleDbConnection mycon = new OleDbConnection(strcon);
mycon.Open();
string sql = "select * from admin";
// OleDbCommand mycom = new OleDbCommand(sql, mycon);
OleDbDataAdapter myda = new OleDbDataAdapter(sql, mycon);
//myda.SelectCommand = mycom;
DataSet ds = new DataSet();
myda.Fill(ds, "admin");
GridView1.DataSource = ds.Tables["admin"];
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)//一个搜索的 按钮事件
{
string strcon = System.Configuration.ConfigurationManager.ConnectionStrings["mycon"].ConnectionString;
OleDbConnection mycon = new OleDbConnection(strcon);
mycon.Open();
string sql = "select * from admin where uname='" + TextBox1.Text + "'";
// OleDbCommand mycom = new OleDbCommand(sql, mycon);
OleDbDataAdapter myda = new OleDbDataAdapter(sql, mycon);
// myda.SelectCommand = mycom;
DataSet ds = new DataSet();
myda.Fill(ds, "admin");
GridView1.DataSource = ds.Tables["admin"];
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)//GridView行编辑的事件
{
this.GridView1.EditIndex = e.NewEditIndex;
dd();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)//行编辑后的事件
{
GridView1.EditIndex = -1;
dd();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)//山很粗行的事件
{
string strcon = System.Configuration.ConfigurationManager.ConnectionStrings["mycon"].ConnectionString;
OleDbConnection mycon = new OleDbConnection(strcon);
mycon.Open();
OleDbCommand cmd = new OleDbCommand("delete from admin where id=" + GridView1.DataKeys[e.RowIndex].Value, mycon);
cmd.ExecuteNonQuery();
mycon.Close();
Response.Redirect("alladmin.aspx");