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?
Use following function private int GetColumnIndex(string columnName, GridView gridView)
int i = 0;
foreach (DataControlField dc in gridView.Columns)
if (dc.HeaderText == columnName)
} 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]
FROM dbo.Table1, dbo.Table2
WHERE Table1.Id = Table2.IdTable1
AND Table1.Name LIKE '%' + @Name + '%'
And my c# code is something like this:
Database db = Databas...How to set the column name in the gridview while using an expression
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.
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.Rows["link_name1"].ToString() == null
// Hide pnlLinks2
<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.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.Cells["1"]Can some body help..regardsSara
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
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).
I'm not sure you can. What are you trying to accomplish? There might
be another way of doing it.
Download an evaluation version of DataWindow .NET 1.5 Today!:
DataWindow.NET code examples available on CodeXchange:
PowerBuilder 10.5 Bet...To set/not to set 'Visible' property of datawindow columns ?
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 ?
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...
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
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
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:
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...