我想在gridview中添加一个动态列,但我们希望只允许一列作为写模式,然后才能实现 [英] i want to add a dynamic column in gridview but we want to allow only one column as a write mode then how it is possible
问题描述
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();
推荐答案
为什么多个帖子?在这里回复:如何在网格中创建可编辑列,其中自动生成的列由其他网格填充 [ ^ ]
添加预先定义的所需列。
Why multiple posts? Replied you here: how to create editable column in grid with autogenerated column filled by other grid[^]
Add the needed column defined before hand.
这篇关于我想在gridview中添加一个动态列,但我们希望只允许一列作为写模式,然后才能实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!