日期:2014-05-19  浏览次数:20759 次

GridView生成模板列以后能否绑定控件
GridView生成模板列以后,要想在该列成生一个DropDownList控件,这个控件是从数据库获取内容,内跟据库数据内容设置selectindex.请问怎么样做才行呢?

假如GridView的控件ID为GridView1,应该怎么取出成生DropDownList控件的值呢?

请高手帮下忙,给个例子或指点一二.

------解决方案--------------------
1.在GridView的模板列中添加一個DropDownList控件
2.設定DropDownList控件的DataSource和DisplayMember屬性(有需要的話也可以再添加一個ValueMember屬性)

------解决方案--------------------
我現在沒有數據環境﹐不過已經很清楚了啊﹐
=============
生成DropDownList数据时还要写入selectindex值
=============

實現你的要求最好不要只用一個DropDownList,同時再添加一個Label顯示selectindex值(也是綁定)
在模板列的選中編輯項中添加DropDownList,在一般項中添加Label,再設定DropDownList控件和Label的屬性就可以了。
------解决方案--------------------
这个,你一看就明白了
http://download.microsoft.com/download/0/f/6/0f651a0f-6f2b-4497-b061-e1b2825e22e0/MSAJAX-ToDoList-Video.zip
------解决方案--------------------
我是加一个comboxcolumn
你自己参照
this.dataGridView1.Columns.RemoveAt(iColumn);
DataGridViewComboBoxColumn comboboxColumn = new DataGridViewComboBoxColumn();
comboboxColumn = CreateComboBoxColumn(iColName);
SetDataGridViewComboBox(ref comboboxColumn);
this.dataGridView1.Columns.Insert(iColumn, comboboxColumn);
if (comboboxColumn.DataPropertyName == "AreaID ")
{
Area a = new Area();
DataTable dtArea = a.Initialize( "SELECT AreaID,AreaName FROM TArea ");
DataRow dr = dtArea.NewRow();
dr[ "AreaID "] = "0 ";
dr[ "AreaName "] = ResourceFactory.GetMultilanguage( "- ");
dtArea.Rows.Add(dr);
comboboxColumn.DataSource = dtArea;
comboboxColumn.ValueMember = dtArea.Columns[0].ToString();
comboboxColumn.DisplayMember = dtArea.Columns[1].ToString();
}
else if (comboboxColumn.DataPropertyName == "EqpName ")
{
ReceiveEqp re = new ReceiveEqp();
DataTable dtReceiveEqp = re.Initialize( "SELECT EqpName FROM TReceiveEqp ");
comboboxColumn.DataSource = dtReceiveEqp;
comboboxColumn.ValueMember = dtReceiveEqp.Columns[ "EqpName "].ToString();
comboboxColumn.DisplayMember = comboboxColumn.ValueMember;
}