转换的GridView场打进DROPDOWNLIST [英] Convert gridview field into Dropdownlist
本文介绍了转换的GridView场打进DROPDOWNLIST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个领域的GridView转换为一个DropDownList,
但我需要为此在codebehind,我不能在apsx添加一个TemplateField(但它可以在运行时执行创建...)
我填充我的网格与此code:
i need to convert a field in gridview to a dropdownlist, but i need to do this in codebehind, and I cannot add a templatefield in apsx(but it could be created at run time execution...) I populate my grid with this code:
foreach (var item in response.Select(x => x.idMatriz).Distinct())
{
dr = dt.NewRow();
for (int i = 0; i < colunas; i++)
{
dr[i] = response.Where(x => x.Propriedade == dt.Columns[i].ToString() && x.idMatriz == item).Select(x => x.Valor).FirstOrDefault();
}
dt.Rows.Add(dr);
}
它的工作原理,但我需要这个行业是一个下拉....
任何帮助吗?
It works but i need this fileds be a dropdown.... any help?
推荐答案
它看起来像所有你需要做的是动态创建一个模板字段,并把它添加到GridView。
It looks like all you need to do is dynamically create a template field and add it to the gridview.
var field = new TemplateField {HeaderText = col.ColumnName}
gridView.Columns.Add(field);
在此之后,在GridView上的行创建的事件创建及导线上下拉列表。
After that, on the row created event of the gridview create and wire up the dropdown.
public void DynamicGridView_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.DataRow)
{
return;
}
var grid = sender as GridView;
if (grid == null)
{
return;
}
for (var i = 0; i < grid.Columns.Count; i++)
{
var column = grid.Columns[i] as TemplateField;
if (column == null)
continue;
var cell = e.Row.Cells[i];
var dropdown = new DropDownList();
cell.Controls.Add(dropdown);
}
}
这篇关于转换的GridView场打进DROPDOWNLIST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文