问题如题!!首先有两个页面:一个是列表页就是datagrid绑定数据的页面;另一个就是管理页面这个页面是用户按自个需要提交所需显示列!

解决方案 »

  1.   

    private void BindData_pnlCCExchg()
    {
    try
    {
    ComLogOutput.WriteLogFile("BindData_pnlCCExchg Begin");

    // get TripCCExchg info
    DataSet dsExc = new TripReportDB().GetTripCCExchg(is_serial.Value,gs_cmpy.Value,"Y"); dg_CCExchg.DataSource = dsExc.Tables[0];
    dg_CCExchg.DataBind();

    if(dsExc.Tables[0].Rows.Count !=0)
    {
    txt_CCExchg_Re.Text = dsExc.Tables[0].Rows[0]["REMARK"].ToString();
    } Session["dsp_TripReport_CCExchg"] = dsExc.Tables[0];

    ComLogOutput.WriteLogFile("BindData_pnlCCExchg end");
    }
    catch(Exception ex)
    {
    ComLogOutput.WriteLogFile(ex); lbl_Err.Text = ex.Message;
    }
    }private void btn_CCExchg_Insert_Click(object sender, System.EventArgs e)
    {
    try
    {
    ComLogOutput.WriteLogFile("btn_CCExchg_Insert_Click Begin");

    if(this.Session["dsp_TripReport_CCExchg"]==null)
    {
    BindData_pnlCCExchg();
    }

    DataTable dtSource = (DataTable)Session["dsp_TripReport_CCExchg"] ;

    for( int i = 0 ; i < this.dg_CCExchg.Items.Count ; i ++ )
    {
    DataGridItem dgi = this.dg_CCExchg.Items[i]; // get update value
    UC_Curr  uc_curBuy2 = (UC_Curr)dgi.FindControl("dg_CCExchg_CurrBuy");
    UC_Curr  uc_curSel = (UC_Curr)dgi.FindControl("dg_CCExchg_CurrSell");
    TextBox AmtSell = (TextBox)dgi.FindControl("dg_CCExchg_txt_AmtSell");
    TextBox AmtBuy = (TextBox)dgi.FindControl("dg_CCExchg_txt_AmtBuy");
    TextBox  ratio = (TextBox)dgi.FindControl("dg_CCExchg_txt_RatioAB");
    TextBox  ratio_base = (TextBox)dgi.FindControl("dg_CCExchg_txt_RatioHKD");
    TextBox  attachment = (TextBox)dgi.FindControl("dg_CCExchg_txt_Receipt");
    CheckBox CompanyRate = (CheckBox)dgi.FindControl("dg_CCExchg_chk_CompanyRate"); if(AmtSell.Text != "" && ComStyleCheck.IsDecimail(AmtSell.Text))
    {
    dtSource.Rows[i]["amt_sell"] = AmtSell.Text;
    } if(AmtBuy.Text != "" && ComStyleCheck.IsDecimail(AmtBuy.Text))
    {
    dtSource.Rows[i]["amt_buy"] = AmtBuy.Text;
    } if(ratio.Text != "" && ComStyleCheck.IsDecimail(ratio.Text))
    {
    dtSource.Rows[i]["ratio"] = ratio.Text;
    } if(ratio_base.Text != "" && ComStyleCheck.IsDecimail(ratio_base.Text))
    {
    dtSource.Rows[i]["ratio_base"] = ratio_base.Text;
    }
    dtSource.Rows[i]["CURR_BUY"] = uc_curBuy2.GetSelectValue;
    dtSource.Rows[i]["CURR_SELL"] = uc_curSel.GetSelectValue;
    dtSource.Rows[i]["attachment"] = attachment.Text;
    dtSource.Rows[i]["COMP_RATE"] = CompanyRate.Checked?"T":"F";

    }

    // insert a new row to datagrid
    DataRow dr = dtSource.NewRow();

    dtSource.Rows.Add(dr);

    dr["attachment"] = "A-";
    dg_CCExchg.DataSource = dtSource;
    dg_CCExchg.DataBind();

    ComLogOutput.WriteLogFile("btn_CCExchg_Insert_Click end");
    }
    catch(Exception ex)
    {
    ComLogOutput.WriteLogFile(ex);

    lbl_Err.Text = ex.Message;
    }
    }
    // delete button click
    if(e.CommandName== "Delete")
    {
    DataTable dtSource = (DataTable)Session["dsp_TripReport_CCExchg"] ; UC_Curr  uc_curBuy = (UC_Curr)dg_CCExchg.Items[e.Item.ItemIndex].FindControl("dg_CCExchg_CurrBuy"); if(!CheckExchgUpdate(uc_curBuy.GetSelectValue))
    {
    return;
    }

    for( int i = 0 ; i < this.dg_CCExchg.Items.Count ; i ++ )
    {
    DataGridItem dgi = this.dg_CCExchg.Items[i]; // get update value
    UC_Curr  uc_curBuy2 = (UC_Curr)dgi.FindControl("dg_CCExchg_CurrBuy");
    UC_Curr  uc_curSel = (UC_Curr)dgi.FindControl("dg_CCExchg_CurrSell");
    TextBox AmtSell = (TextBox)dgi.FindControl("dg_CCExchg_txt_AmtSell");
    TextBox AmtBuy = (TextBox)dgi.FindControl("dg_CCExchg_txt_AmtBuy");
    TextBox  ratio = (TextBox)dgi.FindControl("dg_CCExchg_txt_RatioAB");
    TextBox  ratio_base = (TextBox)dgi.FindControl("dg_CCExchg_txt_RatioHKD");
    TextBox  attachment = (TextBox)dgi.FindControl("dg_CCExchg_txt_Receipt");
    CheckBox CompanyRate = (CheckBox)dgi.FindControl("dg_CCExchg_chk_CompanyRate"); if(AmtSell.Text != "" && ComStyleCheck.IsDecimail(AmtSell.Text))
    {
    dtSource.Rows[i]["amt_sell"] = AmtSell.Text;
    } if(AmtBuy.Text != "" && ComStyleCheck.IsDecimail(AmtBuy.Text))
    {
    dtSource.Rows[i]["amt_buy"] = AmtBuy.Text;
    } if(ratio.Text != "" && ComStyleCheck.IsDecimail(ratio.Text))
    {
    dtSource.Rows[i]["ratio"] = ratio.Text;
    } if(ratio_base.Text != "" && ComStyleCheck.IsDecimail(ratio_base.Text))
    {
    dtSource.Rows[i]["ratio_base"] = ratio_base.Text;
    }
    dtSource.Rows[i]["CURR_BUY"] = uc_curBuy2.GetSelectValue;
    dtSource.Rows[i]["CURR_SELL"] = uc_curSel.GetSelectValue;
    dtSource.Rows[i]["attachment"] = attachment.Text;
    dtSource.Rows[i]["COMP_RATE"] = CompanyRate.Checked?"T":"F";
    } // delete a row  from datagrid
    dtSource.Rows.RemoveAt(e.Item.ItemIndex); dg_CCExchg.DataSource = dtSource;
    dg_CCExchg.DataBind(); ComLogOutput.WriteLogFile("dg_CCExchg_ItemCommand end");
    }
    }