使用vb在gridview中使用2个主键选择数据
Hye ..
我有一个gridview绑定到具有2个主键的数据库.
数据示例为:
RefNo(PK):201207
批号(PK):4400
LotSize:1000
Refno(PK):201207
批号(PK):4401
LotSize:2000
VB代码:
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
我的gridview有一个SELECT列.当我选择第一行,和调试代码,我只得到了引用号为datakey.
因此,当我选择第二行时,它仍然突出显示第一行,因为Session("DATAKEYSELECT")仍为201207.
如何修改代码,以便可以使用不同的键(RefNo,LotNo)检索行.
TQ对于您的响应.
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.
常见的方法是拥有一个字段,这是两个字段的组合.因此,如果您的班级是
Common way is to way have a field which is the combination of both the fields. So if your class is
class Something
{
string Key1 { get; set; }
string Key2 { get; set; }
}
将其更改为
Change it to
class Something
{
string Key { get { return string.Format("{0}|{1}", Key1, Key2); } set { } }
string Key1 { get; set; }
string Key2 { get; set; }
}
现在,您可以将"Key"用作网格的主键字段,并且可以唯一地标识每一行.
Now you can use "Key" as the primary key field for the grid and now you can uniquely identify every row.