« | August 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | | | | | |
|
统计 |
blog名称:小雨 日志总数:262 评论数量:1273 留言数量:15 访问次数:4667327 建立时间:2005年1月8日 |
| 
|
W3CHINA Blog首页 管理页面 写新日志 退出
[杂七杂八]gridview 动态查询显示 |
小雨 发表于 2009/2/22 14:26:49 | using System;using System.Data;using System.Data.SqlClient;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;
public partial class EquipmentReturn : System.Web.UI.Page{ protected string userid; static SqlDataSource ds; protected void Page_Load(object sender, EventArgs e) { if (Session["UserId"] == null) { Response.Redirect("default.aspx"); } if (!Page.IsPostBack) ds = null; else { this.GridView1.DataSource = ds; this.GridView1.DataBind(); } }
//查找 protected void Button1_Click1(object sender, EventArgs e) { if (this.DropDownList_Type.SelectedIndex == 0)//codeid { SqlDataSource1.SelectCommand = "SELECT [BrId], [CodeId], [DisDegree], [IsRenew], [state], [ReturntDate], [BrDeId] FROM [BorrowReturnDetail] WHERE ([state] = '外借' and [CodeId] LIKE '%" + this.TextBox5.Text.Trim() + "%')"; } else { SqlDataSource1.SelectCommand = "SELECT [BrId], [CodeId], [DisDegree], [IsRenew], [state], [ReturntDate], [BrDeId] FROM [BorrowReturnDetail] WHERE ([BrId] =" + this.TextBox5.Text.Trim() + ")";
} SqlDataSource1.Select(new DataSourceSelectArguments()); ds = SqlDataSource1; this.GridView1.DataSource = ds; this.GridView1.DataBind();
} protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.EditIndex = -1; this.GridView1.PageIndex = e.NewPageIndex; if(this.GridView1.DataSource==null) this.GridView1.DataSource = ds; this.GridView1.DataBind();
} protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { this.GridView1.EditIndex = e.NewEditIndex; if (this.GridView1.DataSource == null) this.GridView1.DataSource = ds; this.GridView1.DataBind();
} protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = GridView1.Rows[e.RowIndex]; SqlDataSource1.UpdateCommand = "UPDATE [BorrowReturnDetail] SET [DisDegree] ='" + ((TextBox)row.Cells[5].Controls[0]).Text + "',[state] = '" + ((TextBox)row.Cells[6].Controls[1]).Text + "', [ReturntDate] = getdate() WHERE [BrDeId] = " + row.Cells[1].Text; SqlDataSource1.Update(); ds = SqlDataSource1; GridView1.EditIndex = -1; this.GridView1.DataBind(); } protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView1.EditIndex = -1; if (this.GridView1.DataSource == null) this.GridView1.DataSource = ds; this.GridView1.DataBind();
}
//统一修改,GRIDVIEW之外的按扭 protected void Button2_Click(object sender, EventArgs e) { ds.UpdateCommand = "UPDATE [BorrowReturnDetail] SET [DisDegree] ='' ,[state] = '空闲', [ReturntDate] = getdate() WHERE [BrId] = " + GridView1.Rows[0].Cells[2].Text; ds.Update(); SqlDataSource1=ds; this.GridView1.DataBind(); }}
|
阅读全文(4673) | 回复(0) | 编辑 | 精华 |
|