.net 自用代码大全天天收藏(C#版) _02

这篇博客介绍了.NET C#中处理数据的方法,包括数组操作、AJAX函数、导出Excel的功能,以及一些页面交互处理如删除、更新事件。同时还涉及到错误处理和控件查找。此外,还展示了如何使用CheckBox和GridView进行数据操作,并提供了AJAX的JavaScript函数示例。
摘要由CSDN通过智能技术生成

 Comm o_Comm = new Comm();
o_Comm.PagerButtonClick(grvQuery, "Frist", this.Master);

两个一维数组处理要删除的资料:可以扩展为一个二维数组。
string[] ms_CheckDataPK_Group = ms_CheckDataPK.Split(';');
if (ms_CheckDataPK_Group.Length != 0)
{
                for (int i = 0; i < ms_CheckDataPK_Group.Length; i++)
                {
                    string[] mo_PM048TB_Data = ms_CheckDataPK_Group[i].Split(',');
                    mo_PM048TB.TASK_CODE = mo_PM048TB_Data[0].Trim().ToString();
                    if (!mo_PM048TB_Data[1].Trim().ToString().Equals(""))
                        mo_PM048TB.LOG_DATE = Convert.ToDateTime(mo_PM048TB_Data[1].Trim().ToString());
                    mo_PM048TB.USER_CODE = mo_PM048TB_Data[2].Trim().ToString();
                    mo_PM048TB.TASK_KIND = mo_PM048TB_Data[3].Trim().ToString();
                    mo_BLLPM048TB.Delete(mo_PM048TB);
                }
}

AJAX的使用函数:
        private void Query(string s_aUserCode)
        {

            PMUC01 o_PMUC01 = new PMUC01();
            DataSet o_ds = new DataSet();
            string s_UserName = string.Empty;
            try
            {
                o_ds = o_PMUC01.Query(Request["UserCode"].ToString());

                if (o_ds != null && o_ds.Tables[0].Rows.Count > 0)
                {
                    s_UserName = o_ds.Tables[0].Rows[0]["USER_CHNAME"].ToString();
                }
                else
                {
                    s_UserName = "";
                }
                Response.Clear();
                Response.Write(s_UserName);
                Response.Flush();
                Response.Close();
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }
//Ajax的JS:
function GetNameById(obj)
{
    LeachInputChinese();
    var userCode=obj.value;
    if(userCode=="")
    {
        return true;
    }
    else
    {
        var reqURL = 'PMTM02Q.aspx?UserCode=' + userCode;
        var oHttpReq = GetXmlHttpRequest();
        oHttpReq.open("POST",reqURL,false);
        oHttpReq.send("");
        var result = oHttpReq.responseText;
        document.getElementById("ctl00_cphPage_txtUSER_CHNAME").value=result;
    }
}

导出Excel的代码:
private bool ExportExcel()
{
            try
            {

                Response.ClearContent();
                Response.Charset = "UTF8";
                Response.AddHeader("content-disposition", "attachment; filename=PMTM02.xls");
                Response.ContentType = "application/excel";
                Response.ContentEncoding = System.Text.Encoding.UTF7;
                StringWriter o_sw = new StringWriter();
                HtmlTextWriter o_htw = new HtmlTextWriter(o_sw);
                GridView o_GridView = new GridView();
                o_GridView = this.grvQuery;
                o_GridView.RowDataBound += new GridViewRowEventHandler(o_GridView_RowDataBound);
                o_GridView.DataSource = (DataTable)ViewState["DT"];
                o_GridView.AllowPaging = false;
                o_GridView.DataBind();
                o_GridView.RenderControl(o_htw);
                Response.Write(o_sw.ToString());
                Response.End();
                return true;
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
                return false;
            }
}
override一个事件,导出Excel所需的:
#region VerifyRenderingInServerForm
        /// <summary>
        /// VerifyRenderingInServerForm
        /// </summary>
        /// <param name="control"><

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值