如何获取Gridview动态创建的项目模板的价值 [英] how to get value of dynamic created item template of Gridview

查看:79
本文介绍了如何获取Gridview动态创建的项目模板的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经动态创建了一个只有一行的gridview,并且还动态创建了项目模板,并设置了行硬核的值

当我尝试获取row的值时,我什么也没得到

所以我如何获得gridview动态创建的项目模板的值


我用于创建itemtemplate的代码是



  foreach (DataColumn col  in  dt.Columns中的列)
            {
                // 声明绑定字段并为绑定字段分配内存.
                TemplateField bfield =  TemplateField();
 
                // 初始化DataField值.
                bfield.HeaderTemplate =  GridViewTemplate(ListItemType.Header,col.ColumnName);
 
                // 初始化HeaderText字段值.
                bfield.ItemTemplate =  GridViewTemplate(ListItemType.Item,col.ColumnName);
 
                // 将新创建的绑定字段添加到GridView.
                GrdDynamic.Columns.Add(bfield);
            } 

解决方案

在获取值之前必须绑定gridview

如果通过按钮获取值,请单击

然后添加GrdDynamic.DataBind();在click事件中,然后检索tha值

i have created gridview with one row dynamically and created item template also dynamically and setting a value of row hardcore

when i trying to get the value of row so i didn''t get anything

so how can i get the value of dynamic created item template of gridview


my Code for creating itemtemplate is



foreach (DataColumn col in dt.Columns)
            {
                //Declare the bound field and allocate memory for the bound field.
                TemplateField bfield = new TemplateField();
 
                //Initalize the DataField value.
                bfield.HeaderTemplate = new GridViewTemplate(ListItemType.Header, col.ColumnName);
 
                //Initialize the HeaderText field value.
                bfield.ItemTemplate = new GridViewTemplate(ListItemType.Item, col.ColumnName);
 
                //Add the newly created bound field to the GridView.
                GrdDynamic.Columns.Add(bfield);
            }

解决方案

You have to bind your gridview before getting the values

If you getting the values on a button click

then add GrdDynamic.DataBind(); in the click event and then retrieve tha values


这篇关于如何获取Gridview动态创建的项目模板的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆