作者Eric30 (eric)
看板C_Sharp
标题Re: [问题] DataGrid在Binding之前的动作
时间Mon Sep 5 10:19:11 2005
※ 引述《diamondking (天剑流星)》之铭言:
: ※ 引述《diamondking (天剑流星)》之铭言:
: : 标题: [问题] DataGrid在Binding之前的动作
: : 时间: Fri Sep 2 15:59:06 2005
: : 请问,假设今天有一DataGrid,内含许多控制项,
: : 其中有一DropDownList的Items,我想先系结至某Hashtable。
: : 之後,再设定整个DataGrid的DataSource至别的table1,
: : 最後,将该DropDownList的SelectedValue系结至table1的某栏位,
: : 该如何达到这种需求呢?
: : 也就是说,如何让DataGrid中的DropDownList控制项之
: : Items属性及SelectedValue属性,系结至不同的资料来源。
: : --
: : 推 tomex:先取得资料(datatable/row),於databound事件指定 140.119.52.211 09/03
: 不过目前最大困难是,我DropDownList是放在其中一个样板资料行中,
: 而在後置程码中,完全抓不到该控制项。
在设计阶段是抓不到没错
但是就像版主说的 可以写在runtime才执行的ItemDataBound这个event里
在event中用FindControl()去找到你放在样版资料行里面的DropDownList
并把资料bind上
程式应如 :
private void DataGrid1_ItemDataBound(object sender,DataGridItemEventAgrs e)
{
DropDownList loDdl = (DropDownList)e.Item.FindControl("DropDownList1");
// 此时就可用 loDdl 物件做想做的事 :)
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.138.30