Solved

Datagrid - Case Statement

Posted on 2004-04-19
3
304 Views
Last Modified: 2010-04-15
I Have a datagrid that is being populated via a dataset from a sproc -

Essentially, I have a column that contains a list of numeric values - what I want to do is create a case statement that says somthing similar to:

if column value = 1 then datagrid column = "500MHz"
else
if column value = 2 then datagrid column = "550MHz"

- I need to know how to create the case statement and then what I need to put in for the column text value to display the results?

Anyhelp is greatly appreciated!!!
0
Comment
Question by:tbaseflug
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 500 total points
ID: 10860448
tbaseflug,
you can solve this problem inside OnItemBound event.
eg:

void dgData_ItemDataBound(Object sender, DataGridItemEventArgs e)
{
  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem )
 {
     Label lblColumn = (Label)e.Item.FindControl("lblColumn");
   
    int colValue=(int)DataBinder.Eval( e.Item.DataItem, "yourDBFieldName" )
   
     switch(colValue)
    {
       case 1: lblColumn.Text="500MHZ";break;
       case 2: lblColumn.Text="550MHZ";break;
    }
 }
}

Regards
x_com
0
 

Author Comment

by:tbaseflug
ID: 10860776
x_com -

Thanks!  Works great - also, wanted to ask what I would do if I had 2 conditions to check - would I us2e an if else statement?
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 10860896
tbaseflug,
If you only had 2 conditions, i'll advise you to use
If..else instead of Case statement. Less job to checking the additonal condition.
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question