How to add dynamic Texbox in GridView at RunTime?
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>
EDIT
Here is an interesting CodeProject post on dynamically adding template columns
AB Vyas
Good Programming knowledge in asp.net, MVC, C#, VB, Javascript, HTML, C, Jquery, CSS3, Angular, VueJS. I have 10 plus years of experience in Vast field of Programming, Designing, Development and Maintain Websites and various Software. I eager to know more and more related to Programming world. I also have very good knowledge in sql server. Work well with tight deadlines. Good Problem Solving skills. Specialties Website Developement Asp.net Asp.net MVC C# VB Sql Server Javascript Jquery CSS3 HTML5 Bootstrap AngularJS Advance JavaScript ECMAScript 6 OOPs VueJS FabricJS
Updated on June 04, 2022Comments
-
AB Vyas almost 2 years
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();
now i want to do such thing that in
Gridview
all the controls areTextbox
control so that i can write in that textbox.TextBox t= new TextBox(); G.Contorls.Add(t);
This will throw exception...
do anyone have any idea about this???
Thanks in advance..
Regards Amit Vyas
-
AB Vyas almost 12 yearsi appreciate your code logic. its too easy but in that there is only one Column but in my case there is no fixed columns. i can't decide number of column.. now how can i do that thing???