C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Interview   Jobs   Projects   Offshore Development    
Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing | Talk to Us |



My Profile

Gifts

Active Members
TodayLast 7 Days more...







Creating columns dynamically in gridview


Posted Date: 07 Aug 2008    Resource Type: Code Snippets    Category: ASP.NET GridView

Posted By: Athira Appukuttan       Member Level: Diamond
Rating:     Points: 7



This code sample explains how to create columns in a GridView control dynamically in ASP.NET. The code is written in C#. This function can be called whenever we need to create new columns in GridView.


public DataTable Getcallcoveragesummaryallheader()
{
string strDate;
DataTable dtCallCoverage = new DataTable();

DataColumn dCol = new DataColumn("Employee Name", typeof(System.String));
dtCallCoverage.Columns.Add(dCol);

dCol = new DataColumn("Call Details", typeof(System.String));
dtCallCoverage.Columns.Add(dCol);

if (drpYear.SelectedValue != "")
{
for (int ColIndex = 1; ColIndex <= 12; ColIndex++)
{
string cYear = drpYear.SelectedValue;
strDate = Convert.ToString(ColIndex) + "/" + 1 + "/" + cYear;
DateTime chkDate = Convert.ToDateTime(strDate);
string CMonthName = chkDate.ToString("MMM");
dCol = new DataColumn(CMonthName);
dtCallCoverage.Columns.Add(dCol);
}
} GridDisplay.Visible = true;
string sPrevname = string.Empty;
string mstrCall = "Technical,Technical Avg,Commercial,Commercial Avg,Total";
string[] strCall = mstrCall.Split(',');
foreach (string strCallHeader in strCall)
{
DataRow drow = dtCallCoverage.NewRow();
drow["Employee Name"] = thomas;
}
drow["Call Details"] = strCallHeader;
sPrevname = "thomas;
dtCallCoverage.Rows.Add(drow);
}
DataRow dRow1 = dtCallCoverage.NewRow();
dRow1["Call Details"] = "Average Per Day";
dtCallCoverage.Rows.Add(dRow1);


return dtCallCoverage;
}


The code sample below is an example on how to call the above function.


DataTable dtReport = Getcallcoveragesummaryallheader();
gridview.DataSource = dtReport;
gridview.DataBind();




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Creating columns dynamically in gridview  .  Create columns dynamically in GridView with C#  .  Create columns dynamically in GridView in ASP.NET  .  Create columns dynamically in GridView  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Editing, Deleting Gridview in VB.net 2.0
Previous Resource: Exporting DataGrid to Excel in c#
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET GridView


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing

Contact Us    Privacy Policy    Terms Of Use