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_Loadobject sender, EventArgs e { if IsPostBack { DataBound; } } protected void Button1_Clickobject sender, EventArgs e { if TextBox1.Text ““ bi.BranchName TextBox1.Text; bi.BranchShortName TextBox2.Text; BllProvider.BranchInfoManageP.InsertBranchbi; } } private void DataBound { List list; list BllProvider.BranchInfoManageP.GetAllBrachInfos; if list.Count 0 { this.GridView1.DataSource list; this.GridView1.DataBind; } } protected void Button1_Click1object sender, EventArgs e { //ui 上已经做了验证 BranchInfo bi new BranchInfo; bi.BranchName TextBox1.Text.Trim; bi.BranchShortName TextBox2.Text.Trim; bool result BllProvider.BranchInfoManageP.InsertBranchbi; if result { DataBound; } else { //失败 } } protected void GridView1_RowDeletingobject sender, GridViewDeleteEventArgs e { int no Convert.ToInt32GridView1.DataKeys[e.RowIndex].Values[0].ToString; bool b BllProvider.BranchInfoManageP.DeleteBranchInfoByIdno; if b { DataBound; } } protected void GridView1_SelectedIndexChangedobject sender, EventArgs e { } protected void GridView1_PageIndexChangingobject sender, GridViewPageEventArgs e { this.GridView1.PageIndex e.NewPageIndex; DataBound; } protected void GridView1_RowEditingobject sender, GridViewEditEventArgs e { GridView1.EditIndex e.NewEditIndex; DataBound; } protected void GridView1_RowUpdatingobject sender, GridViewUpdateEventArgs e { //不好用可以 findcotrol 方法; intstuno Convert.ToInt32GridView1.DataKeys[e.RowIndex].Values[0].ToString; stringnewBranchName TextBoxGridView1.Rows[e.RowIndex].FindControl“TextBox3“.Text; stringnewBranchShortName TextBoxGridView1.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.UpdateBranchInfoByIdbi { //成功 DataBound; //DataBind; } else { //失败 } } protected void GridView1_RowCancelingEditobject sender, GridViewCancelEditEventArgs e { GridView1.EditIndex -1; DataBound; } protected void Button2_Clickobject sender, EventArgs e { } protected void GridView1_RowDataBoundobject sender, GridViewRowEventArgs e { if e.Row.RowType DataControlRowType.DataRow { e.Row.Attributes.Add“onmouseover“, “ccthis.style.backgroundColor;this.style.backgroundColor