且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获取Gridview动态创建的项目模板的价值

更新时间:2023-09-18 20:04:58

在获取值之前必须绑定gridview

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

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

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