Grid view hiding columns and changing header text

Hi I have a web page where the columns displayed in a gridview depends on the settings in web config. I itterate through the columns and check the header text and if its the "name" of the value which is stored in web  config, it sets the visibility appropriately. I thought this was a pretty robust approach - if new columns were added, irrespective of postion, the displayed columns would still be those the user expected from web config. So the next request was that the header text was configuerable.... Ive searched the grid view for some sort of key on the columns (other than ordinal position) and cant see one. Anyone suggest a way forward?


2/26/2009 2:31:09 PM 72751 articles. 3 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 35

Besides the index such as grid.Columns[index] i don't think you can reference a column by name. Are you looking for a method to change or modify the header text or I am misunderstanding?

foreach (TemplateField TempField in grid.Columns)

       // logic to configure header text based on web config 

       if (TempField.HeaderText == "Test")


       TempField.HeaderText = "text";



2/26/2009 2:48:09 PM

hi Pak

In part - I understand how to change the header text - but that means i loose the attribute I was keying to for visibility. I'm starting to think that dynamically loading the control is the only way. However that seems to loose a bunch of functionality in the IDE.  

2/26/2009 4:50:08 PM

Anything in design time can be done at runtime dynamically just remember that.

This is just me, but if you're able to have any access to your database (if you're using one) I'd recommend storing columns in the database and dynamically generating the grid that way. The web.config shouldn't be used for this purpose.

Look into dynamically generating gridview


2/26/2009 5:00:30 PM

Hi Pak - thanks for the thought, the vast majority and all web access is done via stored procs - all 3500 of them. So yes there is "a" db involved - not unusually with 3GB data from 5-8 years of operations. I would be very reluctant to forego the security of only granting  permissions to selected stored procs to granting select on tables and the like to the web user = authenticated or not..  

2/26/2009 10:32:11 PM

Similar Artilces:

How to set the Grid View Column Header text non visible?
Hi all, I had a Grid View that is bind to a datatable. The data table will generate column from 1 to 100. But I would not like to show the number 1 to 100 in the Grid View. May I know how to mask off the Column Header? I know one way is to set the Fore Color and Back Color to be the same color. But I do not know how to do it. Can someone please help? Thanks if you're not wanting to show the header at all just turn off the header by setting the ShowHeader property to false;  you can do this through either the design view or code view.  if there are certain elements th...

showing grid view header text without no column added
how can i get grid view header text without adding any column jewelhere:how can i get grid view header text without adding any column Atleast you will need one Column So that there is a Header. Else you do Autogenerate Columns = true So that you dont need to add columns But where are you Viewing it?? in designer??MAKMark as Answer if this reply helps youMVP ASP/ASP.NetASP.Net Hosting : Host DepotMy Site : ASPSnippets Hi jewelhere, A work around is to create a dummy DataTable with the data column you need, and add one datarow (no matter it is null or not) into it...

Changing column header text of a gridview inside user control
Hi,I have an ascx file with a gridview, and I need to change the header text of the gridview's column in the code-behind. Something like that:foreach (DataControlField col in GridView1.Columns){ col.HeaderText = GetString(col.HeaderText);}However, no matter where I place that code, the header texts return to their original value, and that's what's being displayed.What could be the reason for that? And how can it be solved?  ...Anyone? I'm having the feeling that I'm missing something quite basic here, any help would be very appreciated. Amit00: col.HeaderT...

how to hide column data but keep column header text
 Hello,i want to hide my column data programmatically (C#) but still keep the column and its header.Like if i have a column with header "Title". All the data in this column must not be visible.any suggestion? Thank you  If it is all the data in a given column, then one way of doing it, would be to change: SELECT A, B, C, TITLE FROM TABLEtoSELECT A, B, C, TITLE, '' AS TITLE2 FROM TABLE Duplicate the Title column and change the data that is displayed in the second to TITLE2. For those that are allowed to see the data, show the first, for those tha...

How to know the Column number based on Column header in Grid View
Hi I have a gridview with 3 columns. Say : id, Name and skill. I want to know the column number of Column headers(May be Name,Skill or id)... Thanks Archan I don't think there is any inbuilt way to do it. You have to loop through and compare the header text and get the index. private int GetColumnIndex (string headerText) { int idx = 0; foreach (DataControlField gcf in GridView1.Columns) { if (gcf.HeaderText == headerText) { break; } idx++; } return idx; } Mark replies as answers if they helped you solve the problem. Hi siva Thanks for your ...

Enabling button after text changed on text box from form view control
I'm using form view to display some text box that contains user's personal info. There are "save" buttons for each text box which are disable as default. I want to enable them when text is changed on the the text box. I don't know how to write the the JavaScript function to do this task and i also don't know how to call the function from the the textbox control (onchange or ontextchange?). Here is the formview code: <asp:FormView ID="FormView1" runat="server" DataSourceID ="personalSQL"> <ItemTemplate > <ta...

Gridview scrolling with Fixed Header
Hi   I want to keep the Headers fixed and  scroll the GridView . I am using the following the code.  <HeaderStyle HorizontalAlign="Left" ForeColor="Black" CssClass="Freezing" BackColor="#E0E0E0" />.Freezing { position:relative ; top:auto; /* top:this.offsetParent.scrollTop-1; */ /* top:expression(this.Parent.scrollTop); */z-index: 10; }  It works fine for Bound columns . It does not work for Dropdown columns. when i scroll the grid Dropdown box hides the Header text. My code is below.  <div class="&...

want to set fixed Grid view width and text column should be displayed within the column
 Hi friends,               I have grid view in my aspx page which gets the data from sql and display same as like in that, But i want to display the whole grid view to be displayed with the fixed width ,Hence i changed the autogenerate column to "FALSE"  and set my own header grid view displayed in the below format...---------------------------------------------------------------------------------------------------------|    id        |  header1    &nbs...

grid view-hide column after add new hyperlink column
I define a grid and bound a data with one column - "productName" after that I add hyperlinkfiled to the grid - now I can see 2 columns - the new colums dispaly first now I try to hide the original column "productname" but i have an error : out of range here is my code:GridView gv = new GridView(); HyperLinkField Hyperlink1 = new HyperLinkField(); gv.AutoGenerateColumns = false;  ;;<--  I enter this line - I hope it help - but is not help.  gv.DataSource = category.Products;   //add hyper link field to gridgv.DataKeyNames = new string[] { &q...

Hiding grid view column
Ive googled this problem and tried the solution below but i keep getting the error: Specified argument was out of the range of valid values.Parameter name: index Im not sure how to hide a primary key column in my gridview which is at index 1 in my SQL statement which is as follows: SqlDataAdapter ad = new SqlDataAdapter("SELECT Book.Book_ID, Book_ID_Internal AS [Book Internal ID], Title, Subtitle, ISBN, Date_Issued AS [Issued Date], Book_Status AS [Status], Borrower_ID AS [User ID], CONVERT(CHAR(10),Date_Due_Back,103) AS [Date Due_ Back] FROM Book, Loan WHERE Book.Book_ID = Loan.Book...

Grid View Column Hiding
I have a grid view which is bound by the sqldatasource has a column empid which i want in the grid view since i m picking up the value from the grid view like gr.cells[2].text ....but i dont want empid column to be displayed in the gridview....i.e. my purpose is to just pick the value of empid in each gridview rows ...i tried keeping the column empid in the grid view databounded and making visible="false" but its not receiving the value of empid in this suggest me a way in which i can capture the value of empid and same time not to display the column ...

To hide the column of grid view
How can i set the visible property of column of grid view inseted of giving the the index value i want to give the column name. I used the following to set the visible property of grid view column GridView1.Columns[0].Visible = false; I want to give like the following format.Please help me sir GridView1.Columns["EmployeeName"].Visible = false; EmployeeName is the Grid view column name test this? protected void GridView1_DataBound(object sender, EventArgs e) { GridView gridView = (GridView)sender; GridViewRowCollection growArr = (GridViewRowCollection)gri...

How to hide a column in grid view...
Dear Guys,                I am useing  ASP .NET  2.0 with  C#.    actually I have got a web service which returns a dataset with one table on it.  on my consuming application I am binding my data gird with a grid view  I am useing the following code                 localhost.Service myser = new localhost.Service();       DataSet ds;         ds = myser.GetForums...

Is there a way to add extra control to header of a Grid column, but still keep the default column name? thanks
I am using Grid, and I add template field <asp:TemplateField HeaderText="name" SortExpression="something">if I want to have special header, I can use HeaderTemplate, but with HeaderTemplate added ,the headertext will not show, if there a way I can just add a control beside the headertext? since I don't want to handle the column sort. thanks I am sure there is a better way to do this, but in the past I have used the following method although I left out the commandname and arguments protected void GridView1_DataBound(object sender, EventArgs e) { string celltext = GridView1.H...

Web resources about - Grid view hiding columns and changing header text -

Changing room - Wikipedia, the free encyclopedia
A changing room , locker room , dressing room (usually in a sports, theater or staff context) or changeroom (regional use) is a room or area ...

Beyond Timeline: The Changing Face Of Facebook Ads
Despite the hype, timeline may not be the most exciting, or important change coming on March 30. Expanded advertising opportunities may unlock ...

Robert Scoble - Micromedia, how it's changing what we blog - Facebook
Jeremiah Owyang wrote an interesting piece about micromedia and how it's changing what we do on blogs and how we distribute media (er, ideas, ...

8 Ways the Changing Facebook Home Page Will Affect Application Virality
For developers who live and die by the changes Facebook makes to the way information flows through the service, every little Facebook tweak has ...

Changing Lanes (@chginglanes) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Changing the way business decisions are made
We believe that social data has unlimited value, and near limitless application. Today, we’re taking an important step toward unleashing this ...

The Right and Wrong Reasons for Changing Jobs
... your profile is a clue to the folks at LinkedIn that you’re thinking of switching jobs, so don’t be The Right and Wrong Reasons for Changing ...

We're Changing Our Name (Back) to Stack Overflow
We are Stack Overflow. You may know us from such popular websites as Stack Overflow Q&A, Stack Overflow Careers, The Stack Exchange Q&A Network, ...

The Tao of Twitter: Changing your life and business 140 characters at a time - Amazon
It's time to take the mystery out of Twitter. Twitter may be the most powerful business and personal networking platform ever created but it ...

App Store - Voices 2 ~ fun voice changing!
Read reviews, get customer ratings, see screenshots, and learn more about Voices 2 ~ fun voice changing! on the App Store. Download Voices 2 ...

Resources last updated: 1/4/2016 11:53:03 PM