473,569 Members | 2,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

changing values in a column on a databound datagrid

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
6 1975
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.co m

"spmm_pls" <sp******@yahoo .com> wrote in message
news:f5******** *************** ***@posting.goo gle.com...
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
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:templateco lumn ItemStyle-VerticalAlign=" Top"
ItemStyle-Width="70" ItemStyle-HorizontalAlign ="left"
ItemStyle-Cssclass="sideb ar2">
<itemtemplate >
<asp:Label CssClass='<%# SelectDaysLeftC ssClass(
((Accident)Cont ainer.DataItem) ) %>' Runat="server" Text='<%#
((Accident)Cont ainer.DataItem) .Status %>' ID="Label2">
</asp:Label>
</itemtemplate>
</asp:templatecol umn>

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 SelectDaysLeftC ssClass( Accident accident)
{
//If closed get the "blue" one
if ( accident.Status == Accident.Accide ntStatus.Closed )
return "textblueRe al";
//The record is open, if overdue red, normal otherwise
if ( accident.DaysLe ft > -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.goo gle.com...
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
OK, I'll adjust my SP. Thanks to both. I might have a look at the
color thingy later on.
Nov 16 '05 #4
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
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.co m

"spmm_pls" <sp******@yahoo .com> wrote in message
news:f5******** *************** **@posting.goog le.com...
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
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.goog le.com...
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2151
by: PeterZ | last post by:
Hi, In the past I've successfully databound a conventional Winforms checkbox to a number column in an Oracle table, where 1 represents true and 0 represents false. The checkbox would be ticked if the value was 1 and unticked if the value was 0 - earth shattering news I know! :-) HOWEVER...... I tried doing the same thing but in a...
3
2990
by: Doug | last post by:
Hi I have the following code (not mine) that populates a datagrid with some file names. But I want to replace the datagrid with a combo box. private void OnCurrentDataCellChanged(object sender, System.EventArgs e) {try{ DataSet ds = dgMembers.DataSource as DataSet;
2
2616
by: damonf | last post by:
I'm currently trying to add an ASP hyperlink to a template column in a datagrid. The normal hyperlink column doesn't give me the ability to add attributes to the item. In my grid there are four columns. Three are databound to a dataset and one is a template column. I need to be able to access each item in the template column (getting...
15
3746
by: John Blair | last post by:
Hi, Code attached but the line that gives me an error is MyDataGrid.Columns(2).Visible = False It actually gives me an error for any value instead of 2 even when 9 bound columns of data exist. How do i hide a column? Thanks. MyConnection = New SqlConnection("server=(local);database=pubs;Trusted_Connection=yes") MyCommand = New...
1
1874
by: Ken Varn | last post by:
I have a problem where my DataGrid would not maintain the ViewState of my databound rows. I finally narrowed down the problem. If my first column is a template column, the view state for the DataGrid items is not maintained on postback for some reason. I basically re-created my DataGrid again just to make sure this was indeed the problem....
4
1426
by: velu | last post by:
I have created a table MSSQL that contain values and published into Datagrid. The table is typically like this.. Tbl Article Rating Count 1 3 3 2 0 0 3 2 1 4 4 5
3
3524
by: TPhelps | last post by:
I have a sample of an unbound (autogeneratecolumns is true) sortable/pagable datagrid that works. I want to change one of the columns to a hyperlink. The examples I find use a bound column. I can get this to work; however, the column header on the datagrid is not a link/sortable. What am I missing? Thanks in advance.
1
1994
by: Mike | last post by:
Hello all, Is there a way to change the ItemTemplate based on the data that is being shown? For instance, I have a dataset, contains two fields (NAME, STATE). I want to show all the records from the dataset using a standard item template, but when STATE="TX", I want that row to show up in a certain color.
2
1504
by: KerryL | last post by:
How do I update the value of a databound column within my datagrid from within the SelectedIndexChanged event of a dropdownlist, also found within my datagrid? I believe I need to determine the row I'm on but I don't know how to get that.
0
7695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.