高手进!!动态创建控件,状态保存 获取问题
海飞 2009-12-25 03:13:16 创建控件代码:
protected void RGSelectGoods_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e)
{
if (e.Item.ItemType == Telerik.WebControls.GridItemType.Item || e.Item.ItemType == Telerik.WebControls.GridItemType.AlternatingItem)
{
Telerik.WebControls.GridDataItem dataItem = e.Item as Telerik.WebControls.GridDataItem;
Guid goodsId = new Guid(dataItem.GetDataKeyValue("GoodsId").ToString());
IList<FieldInfo> fieldInfoList = field.GetFieldByGoods(goodsId, true);
int cellIndex = 0;
int i = 0;
string hiddenValue = null;
foreach (Telerik.WebControls.GridTableCell cell in e.Item.Cells)
{
cellIndex = e.Item.Cells.GetCellIndex(cell);
if (cellIndex >= 6)
{
foreach (FieldInfo fieldInfo in fieldInfoList)
{
if (fieldInfo.FieldId.ToString().CompareTo(cell.Text) == 0)
{
if (fieldInfo.IsCompField == 2 || fieldInfo.IsCompField == 1)
{
Telerik.WebControls.RadComboBox rads = new Telerik.WebControls.RadComboBox();
rads.ID = "RCB_Field" + cellIndex.ToString();
cell.Controls.Add(rads);
rads.Height = Unit.Pixel(300);
rads.Width = Unit.Pixel(75);
rads.ItemTemplate = LoadTemplate("ChildFieldIControl.ascx");
rads.DataSource=fieldInfo.ChildFields;
rads.DataTextField="FieldValue";
rads.DataValueField="FieldId";
rads.DataBind();
//取的时候出了问题
protected void SelectGoods_Click(object sender, EventArgs e)
{
//if (CheckBox_CheckStock.Checked == true)
// IsCheckStock = true;
//else
// IsCheckStock = false;
Up = false;
IList<GoodsStockInfo> goodsStockList = GoodsStockList;
GoodsInfo goodsInfo = new GoodsInfo();
IList<FieldInfo> fieldInfoList = new List<FieldInfo>();
List<Guid> fields = new List<Guid>();
string[] itemFieldValue = null;
foreach (Telerik.WebControls.GridDataItem dataItem in RGSelectGoods.Items)
{
if ((dataItem.FindControl("CheckGoods") as CheckBox).Checked)
{
if (dataItem.Cells.Count >= 6)
{
object[] objs = new object[] { };
for (int i = 6; i < dataItem.Cells.Count ; i++)
{//??问题就在下边这句话 radComboBox 取不出控件
Telerik.WebControls.RadComboBox radComboBox = (Telerik.WebControls.RadComboBox)dataItem.Cells[i].FindControl("RCB_Field"+i.ToString());