如何动态添加或删除列在DATAGRID数据绑定后!谢谢请教了! 问题如题!!首先有两个页面:一个是列表页就是datagrid绑定数据的页面;另一个就是管理页面这个页面是用户按自个需要提交所需显示列! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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"); } } 新手...做的计算器 提示有错误 高手看看 如何将图片保存成8位、256色、BMP格式的图片? System.Web.HttpUtility.HtmlDecode(location)无效? 怎样获取一段字符串的最后一行数据,用什么方法 新手提问,这个怎么写? 获取嵌套框架中的html源码 请问哪有电子版C,C#的资料下载? DataView中的多个过滤条件怎么设置? 关于文件的读写问题 请教一个关于remoting的问题! 如何在FrameWork精简版里调用其它的程序! 我点翻页为什么要执行选择的事件????
{
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");
}
}