Solved

Datagrid - Case Statement

Posted on 2004-04-19
3
301 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now