zoukankan      html  css  js  c++  java
  • DataGrid ItemCommand & ItemDataBound Operate

     ******************* Create Table *******************

    dtData.Rows.Clear();

          //Detail Table

    public static void AddColumns(ref DataTable table)

    {

    table.Columns.Add("BusinessType",typeof(string));

    table.Columns.Add("BusinessUnit",typeof(string));

    table.Columns.Add("SourceCode",typeof(string));

    table.Columns.Add("UserName",typeof(string));

    table.Columns.Add("SONO",typeof(string));

    table.Columns.Add("CustomerCode_Market",typeof(string));

    table.Columns.Add("Customer_Plantid",typeof(string));

    table.Columns.Add("InvoiceNo",typeof(string));

    table.Columns.Add("OCNO_PLNo",typeof(string));

    table.Columns.Add("ItemNo",typeof(string));

    table.Columns.Add("PCS",typeof(string));

    table.Columns.Add("CTNS",typeof(string));

    table.Columns.Add("CBM",typeof(string));

    table.Columns.Add("KGS",typeof(string));

    table.Columns.Add("ClosingDate",typeof(string));

    table.Columns.Add("JobNO",typeof(string));

    table.Columns.Add("DestinationID",typeof(string));

    table.Columns.Add("Status",typeof(string));


    }


    public static void updColumns(ref DataTable table)

    {

    table.Columns.Add("BusinessType",typeof(string));

    table.Columns.Add("BusinessUnit",typeof(string));

    table.Columns.Add("SourceCode",typeof(string));

    table.Columns.Add("UserName",typeof(string));

    table.Columns.Add("SONO",typeof(string));

    table.Columns.Add("CustomerCode_Market",typeof(string));

    table.Columns.Add("Customer_Plantid",typeof(string));

    table.Columns.Add("InvoiceNo",typeof(string));

    table.Columns.Add("OCNO_PLNo",typeof(string));

    table.Columns.Add("ItemNo",typeof(string));

    table.Columns.Add("PCS",typeof(string));

    table.Columns.Add("CTNS",typeof(string));

    table.Columns.Add("CBM",typeof(string));

    table.Columns.Add("KGS",typeof(string));

    table.Columns.Add("ClosingDate",typeof(string));

    table.Columns.Add("JobNO",typeof(string));

    table.Columns.Add("DestinationID",typeof(string));

    table.Columns.Add("FID",typeof(string));

    table.Columns.Add("Status",typeof(string));


    ****************** Datagrid ItemCommand Operator **************************

    DataRow[] drsDel = dtData.Select(string.Format("FID in ({0})", FID.ToString())); 

    //直接在集合中删除 foreach (DataRow drDel in drsDel)

    { dtData.Rows.Remove(drDel); }

    if( FID > 0)

    {  m_objSQLBLL.DeleteTADetail(FID.ToString());

    txtHiddenFID.Value += FID.ToString() + ","; }

    private void dg_FCL_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

    {
    if (e.CommandName == "Delete")
    {
    AddColumns(ref dtData);
    int intRow=0;
    foreach(DataGridItem dgi in dg_FCL.Items)
    {
    intRow += 1;
    DataRow dr1 = dtData.NewRow();
    dr1["BusinessType"]=((DropDownList)(dgi.FindControl("dropBusinessType"))).SelectedValue;
    dr1["BusinessUnit"]=((DropDownList)(dgi.FindControl("dropBusinessUnit"))).SelectedValue;
    dr1["SourceCode"]=((DropDownList)(dgi.FindControl("dropSourceCode"))).SelectedValue;
    dr1["UserName"]=((TextBox)(dgi.FindControl("txtUserName"))).Text.ToString();
    dr1["SONO"]=((TextBox)(dgi.FindControl("txtSONO"))).Text.ToString();
    dr1["CustomerCode_Market"]=((TextBox)(dgi.FindControl("txtCustomerCode_Market"))).Text.ToString();
    dr1["Customer_Plantid"]=((TextBox)(dgi.FindControl("txtCustomer_Plantid"))).Text.ToString();
    dr1["InvoiceNo"]=((TextBox)(dgi.FindControl("txtInvoiceNo"))).Text.ToString();
    dr1["OCNO_PLNo"]=((TextBox)(dgi.FindControl("txtOCNO_PLNo"))).Text.ToString();
    dr1["ItemNo"]=((TextBox)(dgi.FindControl("txtItemNo"))).Text.ToString();
    dr1["PCS"]=((TextBox)(dgi.FindControl("txtPCS"))).Text.ToString();
    dr1["CTNS"]=((TextBox)(dgi.FindControl("txtCTNS"))).Text.ToString();
    dr1["CBM"]=((TextBox)(dgi.FindControl("txtCBM"))).Text.ToString();
    dr1["KGS"]=((TextBox)(dgi.FindControl("txtKGS"))).Text.ToString();
    dr1["ClosingDate"]=((TextBox)(dgi.FindControl("txtClosingDate"))).Text.ToString();
    dr1["JobNO"]=((TextBox)(dgi.FindControl("txtJobNO"))).Text.ToString();
    dr1["DestinationID"]=((DropDownList)(dgi.FindControl("dropDestinationID"))).SelectedValue;
    dr1["Status"]=((Label)(dgi.FindControl("lblHEStatus"))).Text.ToString();
    dtData.Rows.Add(dr1);
    }
    dtData.Rows.Remove(dtData.Rows[e.Item.ItemIndex]);

    this.dg_FCL.Visible = true;
    this.dg_FCL.DataSource = dtData.DefaultView;
    this.dg_FCL.DataBind();
    }
    }

     ****************** Datagrid ItemDataBound Operator **************************

     private void dg_FCL_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)

    {

    if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)

    {              

    DropDownList listBusinessType = new DropDownList();

    listBusinessType= (DropDownList)(e.Item.FindControl("dropBusinessType"));

    DataView dv = m_objSQLBLL.GetBusinessType();


    if ( !( ViewState[Constants.VENDOR_CODE].ToString().Trim() == "09420" || ViewState[Constants.VENDOR_CODE].ToString().Trim() == "09421" 

    || ViewState[Constants.VENDOR_CODE].ToString().Trim() == "09422" || ViewState[Constants.VENDOR_CODE].ToString().Trim() == "09415"

    || ViewState[Constants.VENDOR_CODE].ToString().Trim() == "09407"

    ) )

    {

    dv.RowFilter = " BusinessType in ('DI-US','DI-INT','TRADE')";

    }


    listBusinessType.DataSource = dv;

    listBusinessType.DataTextField = "BusinessName";        

    listBusinessType.DataValueField = "BusinessType";

    listBusinessType.DataBind();

    listBusinessType.SelectedValue = ((string)DataBinder.Eval(e.Item.DataItem, "BusinessType"));

    DropDownList listBusinessUnit = new DropDownList();

    listBusinessUnit= (DropDownList)(e.Item.FindControl("dropBusinessUnit"));

    DataView dvBusinessUnit = m_objSQLBLL.GetBusinessUnit();

    listBusinessUnit.DataSource = dvBusinessUnit;

    listBusinessUnit.DataTextField = "BusinessUnit";        

    listBusinessUnit.DataValueField = "BusinessUnit";

    listBusinessUnit.DataBind();

    listBusinessUnit.SelectedValue = ((string)DataBinder.Eval(e.Item.DataItem, "BusinessUnit"));



    DropDownList listSourceCode = new DropDownList();

    listSourceCode= (DropDownList)(e.Item.FindControl("dropSourceCode"));

    DataView dvSourceCode = m_objSQLBLL.GetSourceCode();

    listSourceCode.DataSource = dvSourceCode;

    listSourceCode.DataTextField = "SourceCode";        

    listSourceCode.DataValueField = "SourceCode";

    listSourceCode.DataBind();

    listSourceCode.SelectedValue = ((string)DataBinder.Eval(e.Item.DataItem, "SourceCode"));


    //20100328

    DropDownList listDestinationID = new DropDownList();

    listDestinationID= (DropDownList)(e.Item.FindControl("dropDestinationID"));

    DataView dvDestination = m_objSQLBLL.GetDestinationForPlant();

    listDestinationID.DataSource = dvDestination;

    listDestinationID.DataTextField = "DestinationAddr";        

    listDestinationID.DataValueField = "DestinationID";

    listDestinationID.DataBind();

    listDestinationID.SelectedValue = ((string)DataBinder.Eval(e.Item.DataItem, "DestinationID"));


    if(dg_FCL.Items.Count == 0) 

    {

    ((ImageButton)(e.Item.FindControl("Imagebutton1"))).Visible = false;

    }


    ((ImageButton)(e.Item.FindControl("Imagebutton1"))).Attributes.Add("onclick", "return confirm('Are you sure to delete the record ?');");

    }

    }

  • 相关阅读:
    android选择时间攻略
    安卓通知的基本用法
    个人作业----软件工程实践总结
    第三次作业——《K米评测》
    第二次结对编程作业——毕设导师智能匹配
    原型设计与需求分析
    作品调研
    软件工程的实践项目课程的自我目标
    软件工程实践总结作业20161231
    K米测试
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/1800561.html
Copyright © 2011-2022 走看看