Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
?
370 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

Technology Partners: 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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

650 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