Solved

Datagrid - Case Statement

Posted on 2004-04-19
3
308 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

623 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