欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

.net 自用代码大全天天收藏(C#版)_01 .netCC++C#Excel 

程序员文章站 2022-07-16 14:01:43
...

PMTM01:
RowCommand事件:
if (e.CommandName == "imgbtn")
{
ImageButton img = (ImageButton)(e.CommandSource);
string sTemp = ((Label)(img.FindControl("lblID"))).Text;
...
}
增加一个Session
Session.Add("PM01Q", this.ViewState["01"]);
//偉递修改ID
string sTemp = ((Label)(img.FindControl("lblID"))).Text;
Response.Redirect("PMTM01M.aspx?s_PROGR_CODE_01Q=" + sTemp + "", true);
//得到上一個頁面偉過來的修改ID
if (Request.QueryString["s_PROGR_CODE_01Q"] != null)
{
s_PROGR_CODE = Request.QueryString["s_PROGR_CODE_01Q"].ToString().Trim();//得到上一個頁面偉過來的修改ID
}

使用AlertMessage1控件:
this.AlertMessage1.AddOkMsg(Resources.WebResource.X012);//修改成功

后台注册控件的onblur事件:
txtSDPLAN_HOUR.Attributes.Add("onblur", "if(ctl00_cphPage_txtSDPLAN_HOUR.value==''){}else if(!isNumeric(ctl00_cphPage_txtSDPLAN_HOUR.value )){ AddMsg(getMsg('J00023'));}");

//添加一個全部的選項 在第一项位置:
drpPROGR_KIND.Items.Insert(0, new ListItem("", "0"));
//設置選中項,下標從0開始
drpPROGR_KIND.Items[i_ItemIndex].Selected = true;

***一种不错的写法:
通过GetModel()返回一个已经装载好的对象.
private Boolean isUpdate()
{
com.thoughtchina.pms.BLL.PM045TB o_PM045TB = new com.thoughtchina.pms.BLL.PM045TB();
com.thoughtchina.pms.Model.PM045TB o_Model = GetModel();
try
{
o_PM045TB.Update(o_Model);
return true;
}
catch
{
return false;
}
}

转换日期格式:
Convert.ToDateTime(o_DA.Rows[0]["SDEXEC_END"].ToString()).ToString("yyyy/MM/dd")

给GRV中的控件注册JS事件:
if (this.PMSGRID1.Rows.Count != 0)
{
((CheckBox)(PMSGRID1.HeaderRow.Cells[0].Controls[1])).Attributes.Add("onclick", "fun_SelectAllCheck(this);");
}

Equals的前后比较内容:
!"".Equals(s_ItemName)

Context:
o_Model = (com.thoughtchina.pms.Model.PM045TB)this.Context.Items["04"];
this.Context.Items.Add("04",(com.thoughtchina.pms.Model.PM045TB)o_Model45);

txtBIRTHDAY.Value = o_PM.SDPLAN_START == new DateTime() ? "" : o_PM.SDPLAN_START.ToString("yyyy/MM/dd");

PMTM01的循环删除:
or (int i = 0; i < PMSGRID1.Rows.Count; i++)
{
GridViewRow row = PMSGRID1.Rows[i];
bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;
if (isChecked)
{
string strSelect = ((Label)row.FindControl("lblID")).Text.ToString().Trim();
//組合SQL語句//執行
o_PM045TB.Delete(ms_ProjectCode, strSelect);
}
}

使用StringWriter 输出Excel:(数据为字符串并接)
StringWriter o_SW = new StringWriter();
string s_Str = string.Empty;
s_Str = "QMS版本:060330 ";
o_SW.WriteLine(s_Str);
o_SW.Close();
Response.Clear();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment; filename=PMTM01.xls");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("BIG5");
Response.Write(o_SW);
Response.End();

服务器下拉框的绑定与运用代码:
drpPROGR_KIND.Items.Clear();//清空下拉框的內容
drpPROGR_KIND.DataSource = o_DS.Tables[0];//綁定結果集
drpPROGR_KIND.DataTextField = "ENTRY_VALUE";//顯示的字段
drpPROGR_KIND.DataValueField = "ENTRY_KEY";//綁定VALUE值
drpPROGR_KIND.DataBind();
drpPROGR_KIND.Items.Insert(0, new ListItem("", "0"));//添加一個全部的選項
drpPROGR_KIND.Items[i_ItemIndex].Selected = true;//設置第一項為選中項,下標從0開始

RowDataBound事件:
if (e.Row.RowIndex > -1)
{
if (e.Row.Cells[30].Text.Length > 8)
{
e.Row.Cells[30].Attributes.Add("title", e.Row.Cells[30].Text);
e.Row.Cells[30].Text = e.Row.Cells[30].Text.Substring(0, 8).ToString() + "...";
}
}
表头:
if (e.Row.RowIndex == 0)
{
((CheckBox)(PMSGRID1.HeaderRow.Cells[0].Controls[1])).Attributes.Add("onclick", "fun_SelectAllCheck(this);");
}