本文主要是介绍GridView中采用来LinkButton修改表格中的数据(绑定数据在TextBox中),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
【实例1】直接在数据库中读取
protected void alter_Click(object sender, EventArgs e)//修改
{
Panel1.Visible = true;
LinkButton lbt = (LinkButton)sender;
DataControlFieldCell dcf = (DataControlFieldCell)lbt.Parent;
GridViewRow gvr = (GridViewRow)dcf.Parent;
//选中行标注颜色
foreach (GridViewRow gvr1 in GV_PF.Rows)
{
gvr1.BackColor = System.Drawing.Color.Empty;//没有颜色,透明
}
gvr.BackColor = (System.Drawing.Color)(new System.Drawing.ColorConverter()).ConvertFromString("#669999");
decimal id = Convert.ToDecimal(gvr.Cells[10].Text.Trim());
id_main = id;
private BLL.OriginalCertificate.AlterOriginalCertificate B_AlterOriginalCertificate = new BLL.OriginalCertificate.AlterOriginalCertificate();
Entity.TB_OriginalCertificate E_TB_OriginalCertificate = B_AlterOriginalCertificate.getEntity(id_main);// 得到一个对象实体(model层)
txt_Explain.Text = E_TB_OriginalCertificate.Explain;
txt_Bills.Text = E_TB_OriginalCertificate.Bills.ToString();
txt_TotalMoney.Text = E_TB_OriginalCertificate.TotalMoney.ToString();
txt_Idea.Text = " 验收人:" + E_TB_OriginalCertificate.Idea_Test
+ "\n\r 主席:" + E_TB_OriginalCertificate.Idea_Chairman;
*****************************************************************************************
【实例2】直接在GridView中读取
protected void lbnAlertClick(object sender, EventArgs e) //修改记录
{
GridViewRow gvr = (GridViewRow)((DataControlFieldCell)(((LinkButton)(sender)).Parent)).Parent;
//选中行标注颜色
foreach (GridViewRow gvr1 in gvList.Rows)
{
gvr1.BackColor = System.Drawing.Color.Empty;//没有颜色,透明
}
gvr.BackColor = (System.Drawing.Color)(new System.Drawing.ColorConverter()).ConvertFromString("#9900FF");
绑定数据在TextBox中
txtName_File.Text = gvr.Cells[2].Text;
txtSummary.Text = gvr.Cells[3].Text;
txtRemark.Text = gvr.Cells[4].Text;
ViewState["index"] = gvr.Cells[0].Text;
ViewState["Id"] = gvr.Cells[1].Text; //ID
trAlert.Style.Value = "";
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
添加【修改】按钮
protected void btnAlert _Click(object sender, EventArgs e) //修改按钮操作
{
if (txtName_File.Text.Trim() != "" &&txtSummary.Text.Trim() != "")
{
Entity.TB_ProductionPlan E_ProductionPlan = new Entity.TB_ProductionPlan();
E_ProductionPlan.Id = Convert.ToDecimal(ViewState["Id"].ToString());
E_ProductionPlan.Name_File = txtName_File.Text.Trim();
E_ProductionPlan.Summary = txtSummary.Text.Trim();
E_ProductionPlan.Id_ReportPerson = Convert.ToDecimal(Session["USER_ID"]);
E_ProductionPlan.Date_Report = DateTime.Now;
if (B_ProductionPlanAlert.update(E_ProductionPlan)) //更新一条记录
{
msgBox.Show(this, "修改成功!");
}
}
}
这篇关于GridView中采用来LinkButton修改表格中的数据(绑定数据在TextBox中)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!