如何在GridView控件在运行时动态添加Texbox? [英] How to add dynamic Texbox in GridView at RunTime?

查看:156
本文介绍了如何在GridView控件在运行时动态添加Texbox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在GridView控件从code动态添加控件一样文本框。

I would like to add controls like textBox in GridView from code on the fly.

在我的项目,我有一个网格在我不能决定多行和列如何在那里。所以,我只是给它的数据源。该工作的罚款。

In my project i have one Grid in that i can't decide how many rows and columns are there. so that i just give it DataSource. This working fine.

GridView G = new GridView();
G.DataSourse = dt;
G.DataBind();

现在我想要做这样的事情,在的GridView 所有控件文本框控制,这样我可以写在该文本框。

now i want to do such thing that in Gridview all the controls are Textbox control so that i can write in that textbox.

TextBox t= new TextBox();
G.Contorls.Add(t);

这会抛出异常...

也有人对此有什么想法?

do anyone have any idea about this???

在此先感谢..

问候
阿米特维亚斯

Regards Amit Vyas

推荐答案

为什么不ItemTemplate中做它在设计时

Why not do it in design time with ItemTemplate

   <asp:GridView ID="GrdDynamic" runat="server">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:TextBox runat="server" ID="Name" Text='<%#Eval("Name") %>'></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

修改

下面是上的动态添加模板列

这篇关于如何在GridView控件在运行时动态添加Texbox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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