C#平时记载
目录目录 XML DeleteTime 2 gridview 各种绑定(增删改查) 2 定义控件,gv 显示数据 5 字符串转换成整数 . 8 排序 . 9 导入 Excel 9 导出 Excel 13 方 1 13 方 2 14 DDL 绑定数据 . 15 利用循环定义控件 . 15 获取立项批复年月字符串 . 15 连接数据库字符串 . 16 XMLDeleteTimeXMLDeleteTime Gpi_DeleteTime IS NOT NULL Gpi_DeleteTime IS NULL gridviewgridview 各种绑定(增删改查)各种绑定(增删改查) using System; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Web; usingSystem.Web.UI; usingSystem.Web.UI.WebControls; usingMyOffice.BLL; usingMyOffice.Model; usingMyOffice.Framework; //gridview 各种绑定(增删改查) public partial class PeoPleManage_Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataBound(); } } protected void Button1_Click(object sender, EventArgs e) { if (TextBox1.Text != ““ bi.BranchName = TextBox1.Text; bi.BranchShortName = TextBox2.Text; BllProvider.BranchInfoManageP.InsertBranch(bi); } } private void DataBound() { List list; list = BllProvider.BranchInfoManageP.GetAllBrachInfos(); if (list.Count != 0) { this.GridView1.DataSource = list; this.GridView1.DataBind(); } } protected void Button1_Click1(object sender, EventArgs e) { //ui 上已经做了验证 BranchInfo bi = new BranchInfo(); bi.BranchName = TextBox1.Text.Trim(); bi.BranchShortName = TextBox2.Text.Trim(); bool result = BllProvider.BranchInfoManageP.InsertBranch(bi); if (result) { DataBound(); } else { //失败! } } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int no =Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString()); bool b = BllProvider.BranchInfoManageP.DeleteBranchInfoById(no); if (b) { DataBound(); } } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { this.GridView1.PageIndex = e.NewPageIndex; DataBound(); } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; DataBound(); } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { //不好用:可以 findcotrol 方法; intstuno = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString()); stringnewBranchName= ((TextBox)GridView1.Rows[e.RowIndex].FindControl(“TextBox3“)).Text; stringnewBranchShortName= ((TextBox)GridView1.Rows[e.RowIndex].FindControl(“TextBox4“)).Text; BranchInfo bi = new BranchInfo(); bi.BranchName = newBranchName; bi.BranchShortName =newBranchShortName; bi.BranchId =stuno; GridView1.EditIndex = -1; if (BllProvider.BranchInfoManageP.UpdateBranchInfoById(bi)) { //成功! DataBound(); //DataBind(); } else { //失败! } } protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView1.EditIndex = -1; DataBound(); } protected void Button2_Click(object sender, EventArgs e) { } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add(“onmouseover“, “cc=this.style.backgroundColor;this.style.backgroundColor=