Click here to Skip to main content
15,883,801 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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

C#
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
Updated 30-Jan-13 1:18am
v2

1 solution

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.
 
Share this answer
 
Comments
Software Engineer 892 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900