?
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
Medium Priority
?
371 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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 article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
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…
Suggested Courses
Course of the Month16 days, left to enroll

850 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