Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > GridView - how do i modify bound data column by column?

Reply
Thread Tools

GridView - how do i modify bound data column by column?

 
 
TS
Guest
Posts: n/a
 
      08-10-2007
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


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      08-11-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>
>



 
Reply With Quote
 
 
 
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      08-13-2007
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 ((E-Mail Removed), 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.

 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      08-16-2007
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 ((E-Mail Removed), 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.

 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to represent the data in a not bound control via bound control Mario Krsnic ASP .Net 0 06-23-2006 07:38 AM
Move bound column to right of dynamic column in datagrid? John E. ASP .Net 3 03-25-2005 09:19 PM
How do you alternate images in a data bound column of a data grid control? C Newby ASP .Net 7 04-02-2004 05:00 PM
Bound Column or Template Column (w dAdapater?) in DataGrid Ravichandran Mahalingam ASP .Net Datagrid Control 0 01-09-2004 03:30 PM



Advertisments