This is a migrated thread and some comments may be shown as answers.

[Solved] Manipulate values shown in grid

2 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Clive Hoggar
Top achievements
Rank 1
Clive Hoggar asked on 31 Jul 2009, 11:13 AM
Hi

I have a grid bound to an sqldatasource that displays a list of wines. No insert or update involved.
One of the fields contains the number of bottles per unit of sale: eg 1, 6 or 12.
I want display in that field, instead of the numbers, some words that correspond to these numbers eg:

Database value              Show text
 1                                  '1 bottle'
 6                                  'Case of 6 bottles'
 12                                'Case of 12 bottles'

Can you suggest how I could go about achieving this is the most efficient way?

Thanks

Clive

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 31 Jul 2009, 11:38 AM
Hello Clive,

You can try out the following code to access the text and change it:
c#:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            if (item["ColumnUniqueName"].Text == "1"
            { 
                item["ColumnUniqueName"].Text = item["ColumnUniqueName"].Text + " Bottle"
            } 
            else 
            { 
                item["ColumnUniqueName"].Text = "Case of " +item["ColumnUniqueName"].Text + " bottles"
            } 
        } 
   } 

Thanks
Shinu.
0
Clive Hoggar
Top achievements
Rank 1
answered on 31 Jul 2009, 05:39 PM
Thanks Shinu for quick response!

I work in VB so I used the Telerik Converter to get my version but I had to add the
 "Handles RadGrid1.SelectedIndexChanged" to the top line in order for it to work.
So in vb it is like this in my final version:

Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemDataBound  
 
        If TypeOf e.Item Is GridDataItem Then  
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)  
            If item("UnitOfSale").Text.Trim = "1" Then  
                item("UnitOfSale").Text = item("UnitOfSale").Text.Trim + " bottle"  
            Else  
                item("UnitOfSale").Text = item("UnitOfSale").Text.Trim + " bottles"  
            End If  
        End If  
 
    End Sub 

best regards

Clive
Tags
Grid
Asked by
Clive Hoggar
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Clive Hoggar
Top achievements
Rank 1
Share this question
or