By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,975 Members | 1,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,975 IT Pros & Developers. It's quick & easy.

changing values in a column on a databound datagrid

P: n/a
Hi,

Could some1 please tell me what the best way is to adjust the value of
a column in my databound datagrid (in ASP.NET)

For example my database returns the values 1,2 and 3 in the column
Priority. But 1,2 and 3 actually represent "Low", "Medium" and "High".
So instead of a column filled with 1,2,3's I want a column filled with
Low,Medium,High's. How do I do that??

Can (should) this be done in my C# code, or do I have to adjust my
stored procedure on which the datagrid is based?

thanks!
Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
spmm_pls,

Personally, I would change the stored procedure to return not only the
value in the enumeration, but the description as well. It would probably be
best for the database to do this, as it requires another join, but it is
definitely better than opening up another connection to get these values,
and better than looping through your result and assigning the items.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"spmm_pls" <sp******@yahoo.com> wrote in message
news:f5**************************@posting.google.c om...
Hi,

Could some1 please tell me what the best way is to adjust the value of
a column in my databound datagrid (in ASP.NET)

For example my database returns the values 1,2 and 3 in the column
Priority. But 1,2 and 3 actually represent "Low", "Medium" and "High".
So instead of a column filled with 1,2,3's I want a column filled with
Low,Medium,High's. How do I do that??

Can (should) this be done in my C# code, or do I have to adjust my
stored procedure on which the datagrid is based?

thanks!

Nov 16 '05 #2

P: n/a
Hi,

As Nicholas suggested it's better if you can do it in the SP, now in the
case that the meaning of the values are not saved in the DB or just that you
want to display it someway different ; like a different color depending of
the priority ; you can use a code like this:

in the aspx page:

<asp:templatecolumn ItemStyle-VerticalAlign="Top"
ItemStyle-Width="70" ItemStyle-HorizontalAlign="left"
ItemStyle-Cssclass="sidebar2">
<itemtemplate>
<asp:Label CssClass='<%# SelectDaysLeftCssClass(
((Accident)Container.DataItem) ) %>' Runat="server" Text='<%#
((Accident)Container.DataItem).Status %>' ID="Label2">
</asp:Label>
</itemtemplate>
</asp:templatecolumn>

As you can see I use a method to return the correct CssClass of the label
depending of the element being binded.
BTW, I bind the grid to a strong typed collection, but its the same if a
datagrid/datatable is used.

later in the code behind :
protected string SelectDaysLeftCssClass( Accident accident)
{
//If closed get the "blue" one
if ( accident.Status == Accident.AccidentStatus.Closed )
return "textblueReal";
//The record is open, if overdue red, normal otherwise
if ( accident.DaysLeft > -1 )
return "text";
else
return "textred";

}

The same thing you can use to display an interpretation of a value from the
database.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"spmm_pls" <sp******@yahoo.com> wrote in message
news:f5**************************@posting.google.c om...
Hi,

Could some1 please tell me what the best way is to adjust the value of
a column in my databound datagrid (in ASP.NET)

For example my database returns the values 1,2 and 3 in the column
Priority. But 1,2 and 3 actually represent "Low", "Medium" and "High".
So instead of a column filled with 1,2,3's I want a column filled with
Low,Medium,High's. How do I do that??

Can (should) this be done in my C# code, or do I have to adjust my
stored procedure on which the datagrid is based?

thanks!

Nov 16 '05 #3

P: n/a
OK, I'll adjust my SP. Thanks to both. I might have a look at the
color thingy later on.
Nov 16 '05 #4

P: n/a
Oh, by the way, the meaning of the values indeed is not stored in the
db. I adjusted the SP like this: SELECT CASE Priority WHEN 1 THEN
'Low' WHEN 2 THEN 'Medium' etc..

Is this a good idea??
Nov 16 '05 #5

P: n/a
spmm_pls,

I don't think that this is a good idea. Personally, I think that you
should have another table which has the value linked up with the name. This
way, you are not bound to your stored procedure in order to generate those
values, should you need them somewhere else.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"spmm_pls" <sp******@yahoo.com> wrote in message
news:f5*************************@posting.google.co m...
Oh, by the way, the meaning of the values indeed is not stored in the
db. I adjusted the SP like this: SELECT CASE Priority WHEN 1 THEN
'Low' WHEN 2 THEN 'Medium' etc..

Is this a good idea??

Nov 16 '05 #6

P: n/a
Hi,

If this is the case then you better use my suggestion, or just add another
table as paldino suggest.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"spmm_pls" <sp******@yahoo.com> wrote in message
news:f5*************************@posting.google.co m...
Oh, by the way, the meaning of the values indeed is not stored in the
db. I adjusted the SP like this: SELECT CASE Priority WHEN 1 THEN
'Low' WHEN 2 THEN 'Medium' etc..

Is this a good idea??

Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.