如何在网格中创建可编辑列,其中包含由其他网格填充的自动生成的列 [英] how to create editable column in grid with autogenerated column filled by other grid

查看:56
本文介绍了如何在网格中创建可编辑列,其中包含由其他网格填充的自动生成的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Int32 index = 0;

DataTable dt = new DataTable();

DataRow dr;

dt.Columns.Add(名称,typeof(string));

dt.Columns.Add(Description,typeof(string));

dt.Columns.Add(MRP ,typeof(int));

dt.Columns.Add(QTY,typeof(int));

dt.Columns.Add(Discount,typeof (int));

dt.Columns.Add(IndentESM,typeof(int));

dt.Columns.Add(IndentReviewer,typeof(int ));

dt.Columns.Add(IndentFinal,typeof(int));

foreach(GridView1.Rows中的GridViewRow gvr)

{

if(((CheckBox)gvr.FindControl(CheckBox1))。选中== true)

{

博士= dt.NewRow();

dr [Name] = GridView1.Rows [index] .Cells [2] .Text;

dr [Description] = GridView1.Rows [索引] .Cells [3] .Text;

dr [MRP] = 0;

dr [QTY] = 1;

dr [Discount] = 0;

dr [IndentESM] = 0;

dr [IndentReviewer] = 0;

dr [IndentFinal] = 0;



dt.Rows.Add(dr);

//检查内容行

gvr.Visible = false;



}

index ++;

}





GridView2.DataSource = dt.DefaultView;



GridView2 .EditIndex = 5;

GridView2.DataBind();



GetData();

Int32 index = 0;
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Description", typeof(string));
dt.Columns.Add("MRP", typeof(int));
dt.Columns.Add("QTY", typeof(int));
dt.Columns.Add("Discount", typeof(int));
dt.Columns.Add("IndentESM", typeof(int));
dt.Columns.Add("IndentReviewer", typeof(int));
dt.Columns.Add("IndentFinal", typeof(int));
foreach (GridViewRow gvr in GridView1.Rows)
{
if (((CheckBox)gvr.FindControl("CheckBox1")).Checked == true)
{
dr = dt.NewRow();
dr["Name"] = GridView1.Rows[index].Cells[2].Text;
dr["Description"] = GridView1.Rows[index].Cells[3].Text;
dr["MRP"] = 0;
dr["QTY"] =1;
dr["Discount"] = 0;
dr["IndentESM"] = 0;
dr["IndentReviewer"] = 0;
dr["IndentFinal"] = 0;

dt.Rows.Add(dr);
//Do stuff with checked row
gvr.Visible = false;

}
index++;
}


GridView2.DataSource = dt.DefaultView;

GridView2.EditIndex = 5;
GridView2.DataBind();

GetData();

推荐答案

您需要为编辑功能定义TemplateFields,因此必须事先定义列。
You need to define TemplateFields for edit feature, thus have to define columns before hand.


这篇关于如何在网格中创建可编辑列,其中包含由其他网格填充的自动生成的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆