Add columns to datagrid in runtime

I am having a problem of adding a multiple templete columns to a datagrid. What i want to do is that whenever the user clicks a button a new templete column similar to the one in the exixting datagrid is added to that datagrid in rumtime.

I am using th code

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim st As String
        Dim col As New TemplateColumn
        dt = Session("state")
        col = New TemplateColumn
        col = DataGrid1.Columns.Item(3)
        DataGrid1.Columns.AddAt(dt.Columns.Count - 2, col)
        col.HeaderText = "Price " + CStr(dt.Columns.Count - 2) + " (Rs.)"
        st = "Price" + CStr(dt.Columns.Count - 2)
        Session("state") = dt
        DataGrid1.DataSource = dt
    End Sub
 But Whenever i am executing i am finding that only one column is added. The next time i click the button then only the header text is changing and no extra column is added to the datagrid. Please suggest me how to add multiple tempete column. Also I have another problem....There is  a  label on the header template. Each time i add a column, I want to change the text of the label. So please help me out....
3/19/2007 2:09:26 PM 72751 articles. 3 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 41
Get it on Google Play
Get it on Apple App Store

Dear, friend: 

Make sure you do not bind your DDL on each postback in Page_Load() event.

protected void Page_Load()
            //Bind your DDL

I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be of assistance


Best Regards,
Rex Lin
Microsoft Online Community Support

If there is any question or the issue is not resolved, please feel free to mark the thread as not resolved
3/20/2007 7:21:03 AM

Similar Artilces:

Dynamic add control to a DataGrid ItemTemplate column
Basically I need to add from 1-N buttons in a column of a datagrid depending on data from the current row.  I'm assuming I'm missing something simple.  I can trace through and it goes through the code where it adds the buttons they just don't show up and I look at the source and they aren't there either. Here's the abbreviated code:aspx -------------------------------- <asp:datagrid id="dgAnimals" runat="server" ShowFooter="True" AutoGenerateColumns="False" OnItemCommand="dgAnimals_ItemCommand" GridLines="None"> <Columns> ...

Hello, I was wondering if it is possible to add a DropDownList control within a DataGrid control? Here's what I'm trying to do...I have one column in the DataGrid that I wish to allow the user sto select one of two options.I wish to do this by providing a DropDownList control within the <columns> tag of the DataGrid. I figured I could use a TemplateColumn control and within that add the DropDownList.I found out that does not work (not allowed). I also tried to get creative and add a script "block" within the TemplateColumn, but that did not work ei...

Adding web controls to a Datagrid at runtime
I need to create (at runtime) a new row of different web controls (such as DropDownLists, TextBoxes ,and Labels) in a datagrid. When the user click on "Add" button a new row is added to the Datagrid wich it has a DropDownList at the first column. The user select a record from this DropDown and depending what the user has selected the others controls bind different tables from the database, and disable or enable other controls in the same row. Also, every row has a check box column where the users first can check in order to delete one or more rows when the Delete button is clicke...

help plz: add button control to datagrid in runtime
Hi. I have a dropdownlist with some courses listed. If the user selects a course that has no tests completed by him a label is shown indicating that. But if he has already completed some tests then a datagrid is generated on the fly listing: test name, test score and date of completion. Till now I have no problem. I created a placeholder with 2 panels, one with the label and the other with the datagrid. Then I have a procedure that creates them every page load. When the user selects an option in the dropdownlist the postback procedure determines what panel turns visible. If it is the pane...

Add .Net Control to Web Custom Control
 I want to add .NET Control (like: TextBox, Button...) to Web Custom Control.How i can do it? Alphavn That's called a composite control -- "Mark As Answer" if my reply helped you -- Hello Guys What gunteman said, that is one approach and in most cases the right one.But its also possible to add child controls to a Control thats inherit from WebControl itself. Be sure to implement INamingContainer to that inherited Control too, thats the important point of that approach.--Microsoft MVP - Visual Developer ASP / ASP.NET-

How to place a DataGrid Control with in a DataGrid Control
Hi, I want to place a DataGrid control in a DataGrid control can any one plz tell me the procedure to place the control Thanks in Advance Krisamigo <!---<asp:DataGrid ID=dg_List runat=server><Columns><asp:TemplateColumn><ItemTemplate><asp:DataGrid ID=dg_List2 Runat=server></asp:DataGrid> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> ---> Hardik Joshi...

this.Controls.Add does not add control to child collection (this.Controls.Count == 0)
Ok, as silly as it may sound, I have a situation where I am creating a CompositeControl in ASP.NET 2.0, C#. I have the following code in the CreateChildControls() method that build the control's child control collection: 1    for (int i = 0; i < _menus.Count; i++)2    this.Controls.Add(_menus[i]);3    4    foreach (FloatingMenu menu in _menus)5    {6    Label lbl = new Label();7    lbl.ID = string.Concat("GroupQ", menu.ID);8    lbl.CssClass = "menuIt...

Should I use DataGrid(add dynamic control) or just dynamic control?
Hi, I am debating between using just dynamic control's or actually adding the control's dynamically into a datagrid.  I have tried with just adding dynamically, but I am having so much trouble because the selectedindexchanged even it firing for no reason.  I have asked a lot of people, but nobody knows the answer for that and I searched in the web and I am not getting anything either. Now someone suggested to use DataGrid and add the control's dynamically.  In each row, I have a dynamic column, which could be 2 and above.  It will depends on a number that I get fromt he ...

How to add the data present in the controls to a table control without any database involvement.
Hi All,i am four controls where i will write the text and once i click the add button those should get added to the table .i want 6 columns fixed in the table and rows as many as required.i tried doing that taking a table server control and able to load the table.but the problem is whenver i am adding a new row the old one is gfetting overwritten by this and at the end i am getting only one row.  System.Web.UI.WebControls.Table t1 = new System.Web.UI.WebControls.Table();  i have declared the below one global TableRow tr; TableCell tc1; TableCell tc2; TableCell tc...

Dynamic DataGrid Help. Add Column Add Results, Cast Error?
Hello, Ok I'm a little new to datasources and grids and ADO still in .NET.  I've gotten pretty far though with that I'm trying to do but I can't seem to get the last part of this, maybe someone can help me. I know this post is long, sorry, I hate long posts with code in it. At least I didn't say, "help with my code" and paste it. Goal: Dynamicly create datagrid based off CSV file, run function and put results in a new column in the datagrid in the row corresponding to the line item. What I'm doing, is.. I'm reading a CSV file using. Dim sConnectionString As String = "Provider=M...

How to generate the crystal reports designing in runtime in dotnet (Add controls in runtime)
How to generate the crystal reports designing in runtime in dotnet means how to Add controls in runtime in dotnet...

DataGrid add columns
I have Dataset with N columns (F1, F2...FN). I want to create this columns in my DataGrid (AutoGenerateColumns is false). What I do: _____________________________________________________________________ Dim intCount As Int16 Dim AddColumn As New BoundColumn While intCount < DataSetObj.Tables(0).Columns.Count AddColumn.HeaderText = DataSetObj.Tables(0).Columns(intCount).ColumnName AddColumn.DataField = DataSetObj.Tables(0).Columns(intCount).ColumnName Me.DataGridObj.Columns.Add(AddColumn) intCount = intCount + 1 End While Me.Da...

How to add a column during runtime?
I have a need to issue a change to the database - add a column to a table dynamically. This has to be done during the PB runtime (v5) via a powerscript to a SSA runtime (v5). What's the best way? TIA, YA In article <>, says... > I have a need to issue a change to the database - add a column to a > table dynamically. This has to be done during the PB runtime (v5) via a > powerscript to a SSA runtime (v5). What's the best way? > TIA, > YA > If your transaction object is maintaining a connection...

Add controls in textbox ( TextBox1.Controls.Add(); )
hi to alli want to know about TextBox1.Controls.Addit is possible to add controls in a textbox like placeholder i am using  this much of code for add linkbutton in a textbox 1 LinkButton lb = new LinkButton();2 lb.Text = "Linkbutton1";3 lb.ID = "link1";4 5 TextBox1.Controls.Add(lb);6 7 Response.Write (TextBox1.Controls.Count);8 Response.Write(TextBox1.Controls.ToString());this code run without any error when i count a control in textbox then it will disply me a 1 but on the page it will not display any controls in a textbox if this is...

Web resources about - Add columns to datagrid in runtime -

Want to preview our new DataGrid for Xamarin.Forms?
tl;dr Zumero.DataGrid is a Xamarin.Forms control for displaying data in rows and columns. If you would be interested in testing and previewing ...

Mad King DataGrid
This post is about scrolling in WPF and the egocentric DataGrid control. I’ll give the project background but if all you’re interested in is ...

Stack Overflow
Stack Exchange log in - careers - chat - meta - about - faq Questions Tags Users Badges Unanswered Ask Question Top Questions interesting 295 ...

Microsoft Silverlight - Wikipedia, the free encyclopedia
Microsoft Silverlight is an application framework for writing and running rich Internet applications , with features and purposes similar to ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Casaba Security » Products » X5s Testing Tool For Finding XSS Vulnerabilities
Security analysis, consulting, development and testing partners who understand your business strategy.

CodeGuru - Microsoft developers related ideas, articles, tips, tricks, comments, downloads, and so much ...
CodeGuru is where developers can come to share ideas, articles, questions, answers, tips, tricks, comments, downloads, and so much more related ...

Caliburn Micro: WPF, Silverlight, WP7 and WinRT/Metro made easy.
A small, yet powerful framework designed for WPF, Silverlight and WP7. It implements a variety of UI patterns for solving real-world problems. ...

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 11 Jul 2012 11636: first draft of license proliferation committee report
FYI,the first draft report of the OSI's License Proliferation Committee.To join the OSI's license proliferation discuss email list, send anemail ...

Resources last updated: 12/5/2015 8:54:21 AM