Gridview : how to add / remove column in runtime

Hi, i would like to add / remove grid columns based on a certain condition. Is it possible?


8/31/2006 4:56:37 AM 72751 articles. 3 followers. Follow

6 Replies

Similar Articles

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

Hi~ You can first give the grid full columns, then use GridView.Columns.RemoveAt() to remove specific columns in condition~

你好! Just FYI o_O
8/31/2006 7:34:31 AM

Great. It works.

thanks alot.

9/1/2006 1:31:15 AM
I am facing the problem that the template fields added statically disappear when i remove a dynamically added bound field from a GridView
3/18/2007 9:04:07 PM


i wanted to export my datagrid into an Excel file , ofcourse i didn't want the hidden fileds to appear in the file ( such as IDs columns ) 

when used ur method mentioned above , it deleted only the data cells in the column , but the column it self ( the header ) remains in the target excel file

what i want to do is to eliminate these columns in the excel . is there anyway i can do that but the way u mentioned ?

thnx 4 ur attention.


11/20/2007 7:06:43 PM


before calling you export to excel method

write the following lines

GridView1.Columns[7].HeaderText = "";




7/31/2008 12:23:07 PM

Hi Gordon, This is Manohar.I've same problem with GridView control in 2.0.I have a grid view with textboxes in each cell filled with data.Some how on a button click i need to remove a particular column might be at position 3 out of 7 columns without affecting data in the gridview cells controls.I'm tryin to remove them with



It works fine but the problem is the text boxes data is missing when i bind the gridview.PLease help me in this problem I would be very grateful to you if u can help me in this


The sample code is here


 Protected Sub gvPriceModes_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
        Dim txtBox As TextBox
             Dim i As Integer

        If e.Row.RowType = DataControlRowType.DataRow Then
            For i = 0 To gvPriceModes.Columns.Count - 1
                txtBox = New TextBox
                txtBox.MaxLength = 10
                txtBox.Attributes.Add("onKeyPress", "javascript:return isNumeric();")
                If i = 0 Then
                End If
        End If
    End Sub

5/4/2009 5:20:48 AM

Similar Artilces:

remove a gridview column dynamically, removes controls in template columns
I have a interface with a treeview and a gridview. The gridview has two templatefields that handles insert/update/deletes. The gridview is handling editing of different tables so I create the other columns in the gridview dynamically as boundfields. The user selects the table to edit in the treeview. The problem I am having happens when the user selects a table to edit the second time. The code that executes removes all bound fields, (dynamically added when user selected the first table in the treeview), but not the two template fields, and then adds boundfields specifi...

Add/Remove BoundField in Gridview with sorting on runtime throws an "column not found" exception
Hi, I am trying to allow user to see a hit count for each URL showing the gridview. Because displaying hit count is a lengthy operation, so i made it optional. The way how i made happen is by adding/removing boundfield on runtime. When i add the column, i will call a different sql script which will return an additional "count" column. The code works fine as long as i don't sort it by "count". However, if I sort the gridview by "count" and choose to remove the column on runtime, then call the databind() method, it will throw an exception sayi...

Add controls at runtime to gridview
Hello friends, I am working on a web application using Visual studio 2005 and C#. in the database I have table having a primary column ID and a image path column Another column is the sanem of the image. Now what I want to do is to create a gridview and display images in the gidview may be 5 in one row. How to do this?Another thing I want to do is add controls to each cell, I want to add literal control to each sell. I want to add paypal buttons below each image. How thaht can be done? I guess that can be done at runtime adding controls.  Please let me know what can be done for t...

How to remove columns from Gridviews at runtime?
 HelloI am working with Gridview. Now I am adding the columns in Gridviews at runtime. Now I want to remove the all columns at runtime. Actually I am using the same GridView for different data sources. So I need to remove all columns at runtime. Here is the code for removing columns, which I wrote:for (Int16 i = 0; i < _GridView.Columns.Count; i++)                {                    _GridView.Columns.RemoveAt(i);&nb...

add/remove GridView columns programatically
 HI,I have a gridview on  form where I am setting the SelectCommand in code.  Based on the criteria, there may be either 8 or 9 columns.  I have the gridview defined form the designer with the 8 columns.  If I need the ninth I say:dim bf as new BoundFieldbf.HeaderText = "Operator"bg.DataField = "Operator"me.GridView1.Columns.add(bf)All is good. But the next time they change the criteria and run it, I will go through this code again, and it adds a second "Operators" column.  How can I check to see if it is already there, and not exec...

add specific columns to the gridview at runtime
I configure the gridview's datasource at run time and set the AutoGenerateColumns property to False.  How do I add the specific columns to the gridview? thanks Try something like GridView1.Columns.Add(DataControlFieldValue). Randy Mr. Randy what do you mean by DataControlFieldValue? Is the name of the field in the stored proceure? thanks:) This is the column that you want to add. It has to be of the type DataControlFieldValue. You will have to build this control yourself. Take a look at and search on GridView, ASP.NET, 2.0, column and you should find ...

how to add the dynamic controls at runtime
i have a gridview out of which in one column i need to populate controls dynamically.EX: i have gridview with 3 columns out of my THIRD column contains controls row (of third column) can contain text box, second row (of third column) can contain drop down etc...can anyone give me an idea or snippet how to tackle this case??Thanks a lot in advance Hi dude,  You need to write the code in the RowDataBound event of the GridView. Go to the properties of the GridView, click the events above - you know like the orange lightining, seek for the RowDataBound event there and...

Add new gridview controls at runtime
I've looked through a lot of posts regarding my problem and I haven't been able to find exactly what I need.I hope I can explain it well enough. I've created a gridview based on a simple one table SQL Data Source and it lists all the data just fine. One of the constraints that I'm dealing with is that the gridview is dynamic depending on what level of the organization tree they click on. The second problem is that when the user wants to edit the data, some of it is based on drop downlists and not straight text. The last problem is that I want to be able to update any field in...

Add Button Control to Gridview Column
Hi, How do I add a button control to the Gridview column? Upon clicking on the button, it will update the database. I'm using Gridview for displaying or rows and Detailsview for displaying details upon selection of any rows. What this button does is if users clicks on the button "Confirm", the code behind will update the database with a status flag and the row will disappeared from the current gridview. I can do the row to disappeared using Databind() as once the "Confirm" button click, it will not satisfy my Gridview Select condition and it won't be there. However, I had a Select col...

Add Custom Control to GridView Column Header
I am trying to add a custom control to the column header in a grid view. I am doing this on RowDataBound, but that might be incorrect. The ultimate goal is to have the Custom Control appear next tot the HeaderText and still allow the HeaderText to sort the columns. Here is my code:1 If e.Row.RowType = DataControlRowType.Header Then 2 Dim oCell As System.Web.UI.WebControls.TableCell 3 For Each oCell In e.Row.Cells 4 Dim oHelp As New admin_controls_HelpItem 5 oHelp.ID = "hlpItem" 6 oHelp.Help...

How to add a rating control inside a gridview column??
Anybody could help me with adding a rating control on a gridview and bound it to the data I retrieve from the database?? Thanks in advance!!   You just need a template column.  Then you can bind the rating control to the integer field that represents the rating. Here's an example of the databinding<cc1:Rating ID="Rating1" runat="server" CurrentRating='<%#Bind("Priority") %>' MaxRating="5" StarCssClass="ratingStar" WaitingStarCssClass="savedRatingStar" FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar" RatingAlign="Vertical" RatingDirection=...

how to add extra row and column in gridview at runtime
i want to add a new column as well as row in my gridview... sample layout of my gridview is                    user   igd   w9  total                      x        3      5    8                     y ...

How do I programatically add or remove gridView columns after DataBind?
I have constructed a dataset that includes a table populated from an IBM iSeries (AS400) midrange DB2 database using the iSeries DB2 Provider for .NET.  (Yay!  That in itself was a bit of a challenge!) Now I've bound that dataset to a gridView, but I want to add a column that includes a hyperlink, and I want to remove a couple of columns. How can I do that programatically in the code-behind? Hi  ScottDarth , May be you are using a GridView whose AutoGenerateColumns is set to true(which is the default). If u want to choose the columns from your dataset then u have...

Gridview control removing consecutive spaces in column output
 Hi, i am using a simple GridView to retrieve data from a SQL view, and if there are consecutive spaces in the string in a particular column, something (asp?) is removing the 2nd space, and then the output has only 1 space, which is incorrect for this string. Interestingly, if I retrieve the same column with a specific select statement in a code behind file, and then output it via either response.write, or in a text box, it does the same thing.   I have debugged while doing this and in the Autos window, the string is correct (with two consecutive spaces), then when it is ...

Web resources about - Gridview : how to add / remove column in runtime -

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012 - Upcoming stories is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 1/4/2016 8:30:44 AM