Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hye..

I have a gridview which is bound to a database with 2 primary keys.
Examples of the data are:

RefNo (PK) : 201207
LotNo (PK) : 4400
LotSize : 1000

Refno (PK) : 201207
LotNo (PK) : 4401
LotSize : 2000

VB code:
  Dim i As Integer = CType(e.CommandArgument, Integer)
Session("DATAKEYSELECT") = gdPartReg.DataKeys(i).Value.ToString()
If gdPartReg.DataKeys(i).Value.ToString() = Session("DATAKEYSELECT") Then
                    gdPartReg.Rows(i).BackColor = Drawing.Color.LightBlue
                Else
                    gdPartReg.Rows(i).BackColor = Drawing.Color.Empty
                End If


My gridview has a SELECT column. When I select the first row, and debug the code, I only got the RefNo as the datakey.
So, when I select the second row, it still highlight the first row because the Session("DATAKEYSELECT") is still 201207.

How can I modify my code so that I can retrieve the row with different keys (RefNo, LotNo).
TQ For ur response.
Posted

1 solution

Common way is to way have a field which is the combination of both the fields. So if your class is

C#
class Something
{
   string Key1 { get; set; }
   string Key2 { get; set; }
}


Change it to

C#
class Something
{
   string Key { get { return string.Format("{0}|{1}", Key1, Key2); } set { } }
   string Key1 { get; set; }
   string Key2 { get; set; }
}


Now you can use "Key" as the primary key field for the grid and now you can uniquely identify every row.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900