使用vb在gridview中使用2个主键选择数据 [英] select data with 2 primary keys in gridview using vb

查看:75
本文介绍了使用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.


这篇关于使用vb在gridview中使用2个主键选择数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆