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
362 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now