dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Memberssrirama
musathik
Abul Bashar Sardar
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » Code Snippets » ASP.NET GridView

Dynamic GridView


Posted Date:     Category: ASP.NET GridView    
Author: Member Level: Gold    Points: 7


Adding Columns in Gridview Dynamically.



 


Adding Columns in Gridview Dynamically.


void BindData()
{

try
{
SqlConnection con = new SqlConnection(@"server=.\sqlexpress;database=TestDB;Integrated Security=SSPI;");
DataSet ds = new DataSet();

con.Open();

SqlDataAdapter da = new SqlDataAdapter("select id,name,flag from EmpData", con);

da.Fill(ds);


BoundField BC1 = new BoundField();
BC1.HeaderText = "ID";
BC1.DataField = "id";
GridView1.Columns.Add(BC1);

BoundField BC2 = new BoundField();
BC2.HeaderText = "Name";
BC2.DataField = "name";

GridView1.Columns.Add(BC2);

GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
catch (Exception e)
{
Response.Write(e.Message.ToString());
con.Close();
}

}





Did you like this resource? Share it with your friends and show your love!


Responses to "Dynamic GridView"
Author: Pal (Parthiv) Patel    14 Aug 2010Member Level: Gold   Points : 0
NICE CODE BUDDY

KEEP IT UP

POST GOOD POST AND EARN MONEY



Author: Siva Prasad    25 Mar 2012Member Level: Gold   Points : 0
Yeah, We can add columns dynamically in grid view. Nice code friend. I hope you don't mind. Finally block is missing to release unused objects.


Guest Author: Dhruva     05 Apr 2012
Good one


Guest Author: vinita shakyawar     28 Jun 2012
plz send source code for this dynamic gridview to my email id:vinita.shakyawar@rediffmail.com


Author: Atul Sharma    05 Oct 2012Member Level: Silver   Points : 0
i want in gridview that export data into excel sheet..can u give me code...


Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Grid view save edit and update
    Previous Resource: 3-Tier Architecture
    Return to Resources
    Post New Resource
    Category: ASP.NET GridView


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Gridview  .  Dynamic Columns  .  Add Columns  .  



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.