如何在gridview中发生问题的getrid

编程入门 行业动态 更新时间:2024-10-14 04:26:21
本文介绍了如何在gridview中发生问题的getrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个gridview现在我想以编程方式添加控件 所以当我添加控件并执行文本框控件时显示如 System.Web。 UI.WebControls.TextBox 和复选框控件显示如System.Web.UI.WebControls.TextBox 如何结束以下是我的代码所以请建议我在哪里我错了

I have a gridview now i want to programatically add controls to it so when i add controls to it and executing textbox control is displaying like System.Web.UI.WebControls.TextBox and checkbox control is displaying like System.Web.UI.WebControls.TextBox how to over come this below is my code so please suggest me where i am wrong

private void loadDynamicGrid() { DataTable table = new DataTable(); TextBox tx = new TextBox(); CheckBox ab = new CheckBox(); table.Columns.Add("Dynamic grid", typeof(string)); table.Columns.Add("Drug", typeof(Control)); // Here we add five DataRows. table.Rows.Add("student first name:", tx); table.Rows.Add("student last name:", tx); table.Rows.Add("going to school"+ ab,ab); table.Rows.Add("school name", tx); table.Rows.Add("Grade:"); foreach (DataColumn col in table.Columns) { //Declare the bound field and allocate memory for the bound field. BoundField bfield = new BoundField(); //Initalize the DataField value. bfield.DataField = col.ColumnName; //Initialize the HeaderText field value. bfield.HeaderText = col.ColumnName; //Add the newly created bound field to the GridView. GrdDynamic.Columns.Add(bfield); //TextBox t = new TextBox(); } this.GrdDynamic.DataSource = table; //Bind the datatable with the GridView. GrdDynamic.DataBind(); } protected void Button1_Click1(object sender, EventArgs e) { GrdDynamic.Visible = true; int grid = Convert.ToInt32(TextBox1.Text); for (int i = 0; i < grid; i++) { loadDynamicGrid(); } Panel1.Controls.Add(GrdDynamic); }

推荐答案

当我们向gridview添加动态文本框,复选框或任何控件时必须在列中添加特定行,而不是在数据表中 [ ^ ]。 When we add dynamic textbox,checkbox or any control to gridview we have to add in a specific row with column, not in datatable[^]. TextBox tx = new TextBox(); // this line of code create an object of TextBox, where is the ID, runat, etc. attributes.

然后当你尝试在DataTable中添加TextBox时(这是错误的)

then when you try to add TextBox in DataTable(which is wrong)

table.Rows.Add("student first name:", tx); // tx object will take as string and save System.Web.UI.WebControls.TextBox in datatable column.

为了向GridView添加控件首先将templatefield添加到gridview而不是在rowdatabound上创建具有ID的特定类的控件以添加templatefield。 这是链接 [ ^ ]将帮助你

更多推荐

如何在gridview中发生问题的getrid

本文发布于:2023-10-24 20:27:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524928.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发生   如何在   gridview   getrid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!