How to set visible property of Gridview columns using column name instead of index

How to  set visible property of Gridview  columns using column name instead of indexCrying

0
janacpp
9/30/2007 7:23:00 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies
1004 Views

Similar Articles

[PageSpeed] 12

Dear janacpp,

the columns collection of gridview has no indexer for column name.

So you can do something like that:

 in your code section you want to set the visible property add this code :

GridView1.Columns[GridView1.Columns.IndexOf(GetField("FieldName"))].Visible=false;

 where FieldName is the name of your field.

and add this function:

DataControlField GetField(string name)

{

DataControlFieldCollection fields = GridView1.Columns.CloneFields();for (int i = 0; i < fields.Count; i++)

{

if (fields[i].HeaderText == name)

{

return fields[i];

}

}

return null;

}

 

I hope this may help.

 

Regards,

Ahmed


Regards,
Ahmed Mahmoud

---------------------------------------------
Remember to click on Mark as answer on the post that helped you
0
sangob
9/30/2007 11:21:47 AM
Reply:

Similar Artilces:

Index of column by the Name of Column in GridView
Hi.How can I get the Index of column in GridView if column name is known? Hi, Use following function  private int GetColumnIndex(string columnName, GridView gridView) { int i = 0; foreach (DataControlField dc in gridView.Columns) { if (dc.HeaderText == columnName) { return i; } i++; } return -1; } Please mark post as answer if it helped youMy Blog...

Showing my own column names instead of database column names in datagridview-windows app. C#.net
HiI already bind a DataGridView to a databse. My DataGridView is showing column names as it is in the table. I want to show user-friendly column names in the grid instead of column names in the database table. Please help me in this reagard. Thanx in advance Your statement indicates to me that your columns are dynamically added to the grid, that's why it's showing the database column names. You can show user-friendly column names by changing your query like so: SELECT fName as 'First Name' FROM Users.DarmarkMark as Answer, if this reply answers your post. Go to "E...

Reference gridview column index using column headers
 Greetings,I have several GridViews all showing different collections of similar product data.  Due to changes in codes used to distinguish properties such as color and size, I'm having to write several rules into the row databound events.  The issue I'm having is that the group who will be using the application haven't finalized the order of the columns, so everytime I reorder the columns, I have to changes all the column indexes in my code behind so that the rules are being applied to the right columns. I'd like to know if there is a way to reference the colu...

How to use a full column name (table name and column name) with a DataReader
Hi, I have a problem retrieving the data with a DataReader from a stored proc that performs a join of two table with the same column's names but different data. Let me explain with an example: I have two tables: Table1: Id, Name Table2: Id, Name, IdTable1 The sproc is something like this: CREATE PROCEDURE [dbo].[SearchByName] (@Name nvarchar(40)) AS BEGIN SELECT * FROM dbo.Table1, dbo.Table2 WHERE Table1.Id = Table2.IdTable1 AND Table1.Name LIKE '%' + @Name + '%' END And my c# code is something like this: Database db = Databas...

How to set the column name in the gridview while using an expression
Hello I wanted the date to be displayed in a particular format in the gridview. To satisfy that I framed the query(it is written in the underline manner) as below. But because it is as an expression if i place the column's datafield as gps_datetime, it does not work. How do I  rectify it. cn.Open();  string S1 = "SELECT GPSDATA.IGNITION, GPSDATA.REGISTRATIONNO, VEHICLE_SUPERUSER.SUPERUSERID, GPSDATA.LOCATION, GPSDATA.SPEED,convert(nvarchar,GPSDATA.GPS_DATETIME,101)+' '+convert(nvarchar,GPSDATA.GPS_DATETIME,108) FROM GPSDATA INNER JOIN VEHICLE_SUPERUSER ON GPSDA...

Setting visible property of a panel control inside of a template column
In my DataGrid I have one column template. In the template I have two panel controls. If there is no data in the dataset for pnlLink2 then I want to set pnlLink2.Visible = true. How can I do that? I have this so far if (LinksDataSet(renumber).Tables[0].Rows[0]["link_name1"].ToString() == null { // Hide pnlLinks2 } <asp:templatecolumn> <itemtemplate> <asp:panel id="pnlLink1" runat="server"> <asp:hyperlink id=link1 runat="server" text='<%# DataBinder.Eval(Container,"DataIte...

Gridview
Gridview - how to find a column by it's column name rather than it's Cell index Hello Friendshow to find a column by it's column name rather than it's Cell indexi.e i want to do something likestrFirstName = Grid1.Rows[2].Cells["FirstName"]In the project i am working on gets customized to different customers....so the position of the columns keep changing depending on the customers requirement.hardcoding..like below is a pain to maintainif i use Grid1.Rows[2].Cells["1"]Can some body help..regardsSara Hi, columns do not get associated names exactly like that. Nearest equivalent w...

Get a Clicked Column Index Integer value for a GridView column using the Sorting Event Handler
I am creating a GridView nested within a UpdatePanel and I got the sorting, paging all down to a sciene using the GridView events handlers. Now, I stumbled to a minor problem that I can't seem to figure out how to go about it. When sorting, I would like the heading color of the clicked sorted column to change (using CSS). I can't seem to dynamically pass the value of the clicked column index to the method. I am using the following reference to change the color of the column but I cannot seem to retreive the value of the clicked index in integer value: GridView1.Columns(trying to...

Use DataBinder.Eval(Object, String) Method with the column index, not the column's name
I can save a lot of processing if I can use the Column Index instead of the Column Name: <%#DataBinder.Eval(CType(Container, DataGridItem).DataItem, <Column Index number here instead>)%>  Is it possible? then you can directly use <%# Container.DataItem(0)%>, <%# Container.DataItem(1)%> Raghu(MCSD.NET, MCAD.NET, MCDBA)[Don't forget to click on Mark as answer on the post that helped you ] Thanks Raghu ! I did not realise that "Container" refered to the DataSource like that. Raghu, do you know how to get the name of the column from <%# Cont...

Get Name of DW Identity Column (column.identity property requires looping thru all columns)
I need to locate the identity column for a DW. Only method i see is use of the columnName.Idenity property - which requires you to traverse all the DW columns and then look up the identity property for each until one is yes. Is there a way just to get the identity column directly - or the Primary Key. thanks, Dave As one can see in he syntax, sorry no. I played around with it this week also as I am using DW.Net2.0 with DataSets and a DataSet can not create update commands from a SQL statements where one has 2 tables. But, now, with the help of DW.Net it can do it ...

DW Designer Column Name vs. Database Column name use in expressions
Can you access the DW Designer column name in expressions (I have used the database column name, but have had no luck figuring out how to access the Designer column name). thanks, David I'm not sure you can. What are you trying to accomplish? There might be another way of doing it. Regards, Dave Fish Sybase TechWave 2005! www.sybase.com/techwave Download an evaluation version of DataWindow .NET 1.5 Today!: www.sybase.com/datawindow.net DataWindow.NET code examples available on CodeXchange: http://datawindownet.codexchange.sybase.com PowerBuilder 10.5 Bet...

To set/not to set 'Visible' property of datawindow columns ?
Hello, If I have a datawindow and I have say 10 columns in the datawindow, which retrieve data, but need not be displayed... Is it advisable to set the 'Visible' property to '0' for such columns or does it have no performance impact at all ? TIA, Ganesh It's probably more advisable to delete the DW Column Objects. Deleting the objects in the presentation layer just means that the values are not visible; these data set column values are still accessible through Get/SetItem()'s, dw expressions, etc... Good luck, Terry [TeamPS] and Sequel...

How to set column width /align in gridview column?
Is it possible to set the column width and align text for one column to the right?  I have three gridviews on one page, and I'm trying to get them aligned.. which isn't easy to do.  Never make important decisions on a Monday! Friend, refer here http://forums.asp.net/t/1021818.aspx other alternative Alternative Good luck!Please Don't forget to click "Mark as Answer" on the post that helped you.This can be beneficial to other community members reading the thread. If the Column is BoundField then you can set the width and alignment this way below:<as...

Searching all columns without using column name
Hi, I am developing a search engine for my application and I need to grab the entire row from the table if I found the search field in any of the columns and the search is not defined to one table. Please let me know how to search all columns in table without using column names indivdually. If the data is in a DataSet, you can access rows and columns using indexes: myDS.Tables[0].Rows[0][0] will get the first row, first column. .Rows and .Columns have a .Count property that can allow you to get all columns and rows: if ( myDS.Tables.Count>0 ) { for ( int loop...

Web resources about - How to set visible property of Gridview columns using column name instead of index - asp.net.presentation-controls

Property - Wikipedia, the free encyclopedia
This article may require copy editing for grammar, style, cohesion, tone, or spelling . You can assist by editing it . In abstract, property ...

Property - Wikipedia, the free encyclopedia
In abstraction, property is that which belongs to or with something, whether as an attribute or as a component of said thing. For the significant ...

RBA governor Glenn Stevens welcomes slowing property market
The easing of property markets is welcome and essential says RBA governor Glenn Stevens.

Stamp duty spiralling out of control: Property Council puts pressure on state leaders
ACT rakes in more than twice as much from property sales than in 2000, Deloitte report finds.

China stocks rise, led by property shares - DailyTelegraph Search Search
CHINA stocks have climbed, led by property and resources shares, amid signs that insurers are scrambling for stakes in real estate majors and ...

China stocks rise, led by property shares
CHINA stocks have climbed, led by property and resources shares, amid signs that insurers are scrambling for stakes in real estate majors and ...

$863m stamp duty windfall for NSW Government on back of asset sales and property
The Baird government is expecting a massive stamp duty bonanza but warn it may be the last for some time as the property market cools.

Men face court after $30,000 worth of suspected stolen property seized in Griffith
Two men are set to face the ACT Magistrates Court on Saturday morning in relation to stolen property and burglary charges.

Perth bushfire: Wattle Grove property lost in blaze but warning now downgraded
A bushfire burning in Perth's south-east destroys one derelict house and a shed, but is no longer threatening lives and homes.

Vandals spray-paint Hawthorne mosques, leave fake grenade on property
Two mosques in Hawthorne were vandalized and police say both incidents are being investigated as hate crimes.

Resources last updated: 12/22/2015 6:59:57 AM