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 dynamic template columns in gridview


Posted Date: 23 Jun 2008    Resource Type: Code Snippets    Category: ASP.NET GridView

Posted By: shakti singh tanwar       Member Level: Diamond
Rating:     Points: 5



Dataset ds = getDataset(); // Some function to retrieve data
DataTable dt = ds.Tables[o];

for ( int i=1 ; i <= dt.Columns.Count -1 ; i++)//Loop through columns collection
{
// Creating Template Column

TemplateColumn templateColumn = new TemplateColumn();

string columnName = dt.Columns[i].ColumnName;


templateColumn.HeaderTemplate = new DataGridTemplate(ListItemType.Header,columnName);


// Adding the Rows to the DataGrid

for ( int j=0; j<= dt.Rows.Count - 1 ; j++)

{

string value= dt.Rows[j][i].ToString();

templateColumn.ItemTemplate = new DataGridTemplate(ListItemType.Item,value);


}


myDataGrid.Columns.Add(templateColumn);


}






Responses

Author: Roshan R Mhatre    23 Jul 2008Member Level: Gold   Points : 1

Its not working..
it gives error to

Dataset ds = getDataset(); // Some function to retrieve data
DataTable dt = ds.Tables[o];

myDataGrid.Columns.Add(templateColumn);





Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

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: Creating dynamic bound columns
Previous Resource: paging, sorting, link button in GridView
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

doors in nj

Contact Us    Privacy Policy    Terms Of Use