高手进!!动态创建控件,状态保存 获取问题

海飞 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());
...全文
120 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
海飞 2009-12-25
  • 打赏
  • 举报
回复
Telerik.WebControls.RadComboBox radComboBox = (Telerik.WebControls.RadComboBox)dataItem.Cells[i].FindControl("RCB_Field"+i.ToString());
=---------------------
是 NULL值
---------------
后边的两为朋友,我的cell数是没问题的。就是从第6列开始,都是程序自动创建的,然后动态家载控件,
-------------
动态的控件 状态是ViewStat是不保存的。
----------------------
需要重写几个方法。重写什么不太明白。
huoyanna91accp 2009-12-25
  • 打赏
  • 举报
回复
i应该从5开始吧
huoyanna91accp 2009-12-25
  • 打赏
  • 举报
回复
count=6 i不是应该从5开始吗
Lovely_baby 2009-12-25
  • 打赏
  • 举报
回复
Telerik.WebControls.RadComboBox radComboBox = (Telerik.WebControls.RadComboBox)dataItem.Cells[i].FindControl("RCB_Field"+i.ToString());

断点大众、到这句上看看是什么值??

62,254

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧