DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Fri, 10 Aug 2007 14:22:03 -0500,    posted on: microsoft.public.dotnet.framework.aspnet.webcontrols        back       

Thread Index
  1    TS am
          2    Teemu Keiski
          3    (Walter Wang [MSFT])
          4    (Walter Wang [MSFT])


GridView - how do i modify bound data column by column?   
i have a custom object list for my data source. i want to be able to
override some method so that whenever a column in row is bound, i can take
that value that gets bound, which is an integer, and decode that into it's
code table's textual value.

so if i have a collection of Car objects who have a property called Color,
which is an integer that points to a table that i can covert to its text
form:

ColorTable
1 = 'blue'
2 = 'red'

Where can i go to do this? I figured if i override OnDataBound, i could loop
thru all the rows and then thru all the columns and convert the values then,
but that means i have to do a looping operation - i figured i should be able
to do it as it gets bound???

thanks
Date:Fri, 10 Aug 2007 14:22:03 -0500   Author:  

Re: GridView - how do i modify bound data column by column?   
If you handle RowDataBound event, it is automatically called for every row 
in the data source, so you don't need to loop rows since it's already 
provided to you by handling the event. Only thing to do then is tyo deal 
with the columns in the data source. If they are fixed, you could do it 
fixed column by column and you don't have to loop.

-- 
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net


"TS" <manofsteele1@nospam.nospam> wrote in message 
news:OiUJ8O42HHA.4400@TK2MSFTNGP06.phx.gbl...

>i have a custom object list for my data source. i want to be able to
> override some method so that whenever a column in row is bound, i can take
> that value that gets bound, which is an integer, and decode that into it's
> code table's textual value.
>
> so if i have a collection of Car objects who have a property called Color,
> which is an integer that points to a table that i can covert to its text
> form:
>
> ColorTable
> 1 = 'blue'
> 2 = 'red'
>
> Where can i go to do this? I figured if i override OnDataBound, i could 
> loop
> thru all the rows and then thru all the columns and convert the values 
> then,
> but that means i have to do a looping operation - i figured i should be 
> able
> to do it as it gets bound???
>
> thanks
>
> 
Date:Sat, 11 Aug 2007 11:40:55 +0300   Author:  

RE: GridView - how do i modify bound data column by column?   
Hi TS,

There're two approaches for your objective. One is mentioned by Teemu: 
change the data after each row is bound.

Another approach is to directly convert the data to your desired one using 
a code-behind function and do this in the declarative markup with a 
TemplateField

                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Label ID="lblColor" runat="server" 
BackColor=<%# 
System.Drawing.Color.FromName(GetColor(DataBinder.Eval(Container.DataItem, 
"ColorIndex")))%> Text=<%# GetColor(DataBinder.Eval(Container.DataItem, 
"ColorIndex")) %>></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>


    protected string GetColor(object colorIndex)
    {
        switch ((int) colorIndex) {
            case 1:
                return "blue";
            case 2:
                return "red";
            case 3:
                return "yellow";
            case 4:
                return "purple";
        }

        return "white";
    }



Hope this helps.


Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Date:Mon, 13 Aug 2007 05:41:11 GMT   Author:  

RE: GridView - how do i modify bound data column by column?   
Hi TS,

I'm writing to check the status of this post. Please feel free to let me 
know if there's anything else I can help. Thanks.



Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Date:Thu, 16 Aug 2007 05:02:59 GMT   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us