?
Solved

Trying to manipulate the displayed value in a GridView column

Posted on 2009-07-01
2
Medium Priority
?
285 Views
Last Modified: 2013-12-17
 I have a column I am creating in a GridView. Now the values retrived from the database for this column are integers.(1,2,3,4) I am trying to run a test for the integer retrieved and then manipulate the DataFormat string of the column based on the test. So if the value retrieved is 1, then write "Customer Complaint".
  However currently my tests (The switch case) do not seem to be running. Question becomes what column property do I actually need to test on as currently testing on the .DataField property does not seem to work. Running a test with a series of IF statements currently yields the same result. Any direction would be greatly appreciated.

Jason
BoundField correspondencetype_i = new BoundField();
        correspondencetype_i.HeaderText = "Correspondence Type";
        correspondencetype_i.DataField = "correspondencetype_i"
 
        switch (correspondencetype_i.DataField)
        {
            case "1":
                correspondencetype_i.DataFormatString = "Customer Complaint";
                break;
 
            case "2":
                correspondencetype_i.DataFormatString = "Technical Support";
                break;
 
            case "3":
                correspondencetype_i.DataFormatString = "Customer Suggestion";
                
                break;
 
            case "4":
                correspondencetype_i.DataFormatString = "Repair(RMA)";
                break;
        }

Open in new window

0
Comment
Question by:jazzcatone
[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 Comments
 
LVL 22

Accepted Solution

by:
prairiedog earned 2000 total points
ID: 24755068
Do you have to add the BoundField dynamically?
 
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24755289
You should add BoundField in your Markup and not in code-behind.
Then in your RowDataBound Event handler do something like below:

protected void GridView4_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DataRowView dv = (DataRowView)e.Row.DataItem;
            string value = "";
            //yourColumnIndex below is the column in your record returned from DB that is being bound to this field
            int dbValue = Convert.ToInt32(dv.Row.ItemArray[yourColumnIndex])
            switch (dbValue )
            {
                case 1:
                    value = "Customer Complaint";
                    break;
                case 2:
                    value = "Technical Support";
                    break;
              //and so on
            }
            //yourColumnIndexToReplace is the column in the GV for which you want to replace the value.
            e.Row.Cells[yourColumnIndexToReplace].Text = value;
        }
    }
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

777 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