Solved

How Do I change a Datagrid Column value to a different Value from the same Dataset depending on another field value from the Dataset

Posted on 2008-06-26
1
366 Views
Last Modified: 2008-09-12
How Do I change a Datagrid Column value to a different field Value from the same Dataset depending on another field value from the Dataset.

I have a dataset that is created from a stored procedure. The stored procedure can not be changed.
I have bound the datagrid's columns to the Grid. The problem I am having is how to change a column value (not header) depending on a different value from same dataset. The dataset contains a refID field and it also contains the 4 possibilities that coincide with the ref ID.
example:
If RefID = 1 get Datatset Field(1)
if RefID = 2 get Dataset Field(2) etc.

I am assuming that I need to do this in ItemDataBound but I don't have any idea as to how.

here is the binding code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here
            Dim aMGR As New aMGR
            dgGrid.DataSource = aMGRGetDetails()
            dgGridDataBind()
 End Sub

Any information would be greatly appreciated.
0
Comment
Question by:ckwizard77
1 Comment
 

Accepted Solution

by:
ckwizard77 earned 0 total points
ID: 21876392
I took the value that will be displayed in the first column of the grid at 0 index and used a select case statement. If the case matched then I changed the cell value in cell(1) to the dataItem I needed.

Private Sub dgErrors_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgErrors.ItemDataBound
             If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
                Select Case Trim(e.Item.Cells(0).Text).ToUpper
                    Case "ONE"
                        e.Item.Cells(1).Text = e.Item.DataItem("field3")
                     Case "TWO"
                        e.Item.Cells(2).Text = e.Item.DataItem("field4")
                    Case "THREE"
                        e.Item.Cells(2).Text = e.Item.DataItem("field4")
                    Case "FOUR"
                        e.Item.Cells(2).Text = e.Item.DataItem("field5")
                    Case Else
                        e.Item.Cells(2).Text = "N/A"
                End Select
            End If
        End Sub
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

840 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