.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to change the column name of gridview dynamically

Posted By: jay     Posted Date: May 12, 2010    Points:2   Category :ASP.Net
Hi
i am using below code

SqlDataAdapter da = new SqlDataAdapter("select * from mytable",con);
da.Fill(ds);

GridView1.DataSource = ds.Tables[0];

GridView1.DataBind();
----->
here i want to change the gridview column name as first and second how to do it


Responses
Author: Venkat             
Posted Date: May 12, 2010     Points: 5   

Hi,

Use your own column of GridView and can assign the Header text of the gridview. Go to Properties of the GridView-->Columns-->Add the column and set the DataBound to the DB Column name and Header Text Property.

And Dont forget to se the AutoGeneratedColumns property to false of the gridview



Mark As Answer if this solve your problem
Warm Regards,
Venkat
Author: BangaruBabuPureti             
Posted Date: May 13, 2010     Points: 5   

Hi

Place Grid View On The Form - Select Gridview ->Press F4 -> Select Columns Attribute In Properties Window -> Now Field DialogBox Opens -> Select BoundField and Press Add Button -> Add Required No Of Bound Fields u want->For Each Bound fields apply properties HeaderText and DataField---->That Much Simple It Is





BangaruBabu Pureti
http://bangarubabupureti.spaces.live.com/
Author: Lalij Mer             
Posted Date: May 13, 2010     Points: 5   

If you want to programatically then you can use this code sample

sqlcommand cmd=new sqlcommand("Select forecast.tlkpdatecaptions.fldcaption from forecast.tlkpdatecaptions where XXXXXX") 
// this will retrun a collection of weeks.
using(sqlconnection con=new sqlconnection("your con-string"))
{
cmd.connection=con;
con.Open();
sqldatareader rder;
rder=cmd.ExecuteReader();
int tmp=0;
while(rder.Read())
{
yourdatagrid.columns[tmp].HeaderText=rder[tmp].ToString();
tmp++;
}
}


show here more information will help

http://geekswithblogs.net/michelotti/archive/2006/03/30/73896.aspx

http://www.codeproject.com/KB/aspnet/create_template_columns.aspx?msg=3243111

Please Check my answer if you help....
Thank You...

Lalit.
Author: TotalDotNet             
Posted Date: August 16, 2010     Points: 5   

You can use the code like

var bookquery = from k in XElement.Load(MapPath("book.xml")).Elements("book")
join m in XElement.Load(MapPath("Library.xml")).Elements("Library")
on (String)k.Element("bookid") equals (String) m.Element("bookid")
select new bookclass{
bookid=(String) m.Element("bookid"),
Title=(String) k.Element("title"),
AuthorName=(String) k.Element("author").Element("first-name"),
AuthorSurName = (String)k.Element("author").Element("last-name"),
Price=(String) k.Element("price")
};
GridView1.DataSource = bookquery;
GridView1.DataBind();



For more details go through the Example in

http://www.totaldotnet.com/LinQ/LinqToXml.aspx


Regards
TotalDotNet



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend