Solved

Datagrid - Case Statement

Posted on 2004-04-19
3
302 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Data Saving 5 56
Iterate a dictionnary to change values 4 53
Host asp.net pages 5 25
Error on Add method 1 38
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 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

21 Experts available now in Live!

Get 1:1 Help Now