Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
How to Change Gridview Headers using Code
=========================================
 
hi frnds,
 
I want to change gridview header names using sql query
 
for example in database i have a field called Username, FirstName, LastName
 
but i want to display it as UserName , First Name , Last Name.
 

I want to use it as FirstName as First Name this should be in Query
 
I want to use AS Operator
 
This is my code....in this i want to use AS
 
private void LoadGridview()
    {
 SqlConnection con = new SqlConnection(_connString);
 

 SqlCommand cmd = new SqlCommand("Select UserName,Firstname,LastName from UserInfo",con);
 
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
      
        GVUserInfo.DataSource = ds;
        GVUserInfo.DataBind();
    }
 

Please help, thanks
Posted 29-Jan-13 18:38pm
Edited 30-Jan-13 1:18am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I think you want to do
 
Select FirstName as [First Name]
 

etc.
 
The square brackets should allow you to have spaces in the column name.
  Permalink  
Comments
Software Engineer 892 at 30-Jan-13 0:45am
   
Thank you sir for ur help, its working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 510
1 CPallini 330
2 OriginalGriff 215
3 George Jonsson 120
4 ChauhanAjay 104
0 OriginalGriff 6,464
1 Sergey Alexandrovich Kryukov 5,915
2 CPallini 5,175
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100