Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: combine datagrid columns

Reply
Thread Tools

Re: combine datagrid columns

 
 
Davide Vernole [MVP]
Guest
Posts: n/a
 
      09-08-2004
IGotYourDotNet <(E-Mail Removed)> typed:
> I'm using a datagrid on my page and I'm getting my data from a web
> service dataset. I need to combine 2 columns and display them as 1
> column in the grid, also I have 1 column that is returned as 2 words
> such as (chevy garage) i need to remove the word garage and only
> display chevy, is there a way to do both of these?


You could do that in the method delegate for the ItemDataBound event. Try
this:

if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==
ListItemType.AlternatingItem))
{
//Combine two fields in one column
string firstField =
((DataRowView)e.Item.DataItem).Row["FirstColumn"].ToString() ;
string secondField =
((DataRowView)e.Item.DataItem).Row["SecondColumn"].ToString() ;
e.Item.Cells[0].Text = firstField + " " + secondField;

//Replace a field value before insert it in a cell
string combinedField =
((DataRowView)e.Item.DataItem).Row["CombineColumn"].ToString() ;
e.Item.Cells[1].Text = combinedField.Replace("Garage",
string.Empty).Trim();
}

where:
Cells[0] = Cell where you want to place the value of two field
Cells[1] = Cell where you want to place the cleaned value of a combine field

HTH
--
Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS Problem: How to combine three columns with round corner box? loudking HTML 1 06-04-2007 12:57 PM
Combine 2 Columns to one with punctuation DBLWizard ASP .Net 10 04-02-2005 12:07 AM
DataGrid problem - Combine 2 fields CuMPeEWeEr [No MCSD] ASP .Net 1 01-07-2005 08:21 AM
Binded Datagrid Formatting columns or hiding columns ton ASP .Net Web Controls 2 02-11-2004 04:09 AM
Columns and Inherited Datagrid...Active Schema does not support columns rob thomson ASP .Net Datagrid Control 0 09-04-2003 03:09 PM



Advertisments