Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Datagrid - Case Statement

Posted on 2004-04-19
3
Medium Priority
?
312 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

772 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