Advertisement

07.14.2008 at 02:09AM PDT, ID: 23561999
[x]
Attachment Details

Reference GridView DataKey in RowDataBound

Asked by G0ggy in Programming for ASP.NET, Microsoft Visual Basic.Net, .NET Framework 2.x

Tags:

Hi all,

I'm trying to get the current row DataKey in the RowDataBound event for my GridView. The idea is that it checks the current row DataKey against a small DataTable to see if the value exists, if it does then the row is back coloured green or red if it doesn't. The attached code does not work, but hopefully you can see what I'm trying to achieve. Please do not post the CommandArgument (e.CommandArgument) as this is NOT a RowCommand so that is not available in this context. Unless you know different of course!

TIA.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
If e.Row.RowType = DataControlRowType.DataRow Then
            'Current GridView row ID
            'Dim test2 As String = gvwPrerequisiteCourses.SelectedDataKey.Value
            Dim gridViewClassID As Integer = Convert.ToInt32(e.Row.Cells(0).Text)
 
            For Each row As DataRow In dtUsersCompletedCourses.Rows
                If row("courseID") = gridViewClassID Then
                    e.Row.BackColor = Drawing.Color.Green
                Else
                    e.Row.BackColor = Drawing.Color.Red
                End If
            Next
        End If
[+][-]07.14.2008 at 02:11AM PDT, ID: 21996619

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, Microsoft Visual Basic.Net, .NET Framework 2.x
Tags: VB.NET
Sign Up Now!
Solution Provided By: G0ggy
Participating Experts: 0
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628