加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 循环通过gridview并获取数据键值

发布时间:2020-12-16 07:34:06 所属栏目:asp.Net 来源:网络整理
导读:我试图循环遍历gridview的行并检索每行的数据键值,然后执行一些代码来运行sql查询.如何获取变量中每行的数据键值?现在我收到一条错误消息说: value of type system.web.ui.webcontrols.datakey cannot be converted to integer. 这是我的代码: Protected
我试图循环遍历gridview的行并检索每行的数据键值,然后执行一些代码来运行sql查询.如何获取变量中每行的数据键值?现在我收到一条错误消息说:

value of type system.web.ui.webcontrols.datakey cannot be converted to integer.

这是我的代码:

Protected Sub Page_Load(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.Load
    For Each row As GridViewRow In GridView1.Rows
        Dim therowindex As Integer = row.RowIndex

        Dim theid As Integer = GridView1.DataKeys([therowindex])

        'execute some more code running queries using the data key value.
    Next
End Sub

解决方法

你必须使用 Value财产.

Dim theid As Integer = Integer.Parse(GridView1.DataKeys(therowindex).Value.ToString())

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读