?
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
?
369 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
[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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

770 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