从数据库填充Gridview [英] Populating Gridview from database

查看:68
本文介绍了从数据库填充Gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个由数据库填充的gridview。 gridview中只有一列带有选择链接。我试图在用户点击Select时从gridview中检索一个值。我已经尝试了GridView1.SelectedValue.Cells(0).Text和Gridview1.SelectedRow.Cells(1)。按钮单击代码中的文本,我得到对象变量或未设置块变量。和NullReferenceException由用户代码处理。任何帮助将不胜感激。这不是家庭作业。我在2003年有ASP.NET和VB6。



这就是我所拥有的:

Hello all, I have a gridview being populated by a database. Just one column in gridview with a select link. I am trying to retrieve a value from the gridview when the user clicks on Select. I have tried GridView1.SelectedValue.Cells(0).Text and Gridview1.SelectedRow.Cells(1).Text in the code for button click and I am getting "Object variable or With block variable not set." and NullReferenceException Unhandled by user code. Any help would be greatly appreciated. This is not home work. I had ASP.NET and VB6 back in 2003.

This is what I have:

Dim query As String = "select Approved from tablename where [name] = '" & Session("name") & "' And Book= '" & GridView1.SelectedValue.Cells(0).Text & "'"







谢谢你,

D-Bar




Thank-you,
D-Bar

推荐答案

GridView1.SelectedValue gives the datakey value of Selected Row not the actual row but  Gridview1.SelectedRow.Cells(1).Text should work,check whether any row is selected or not,for that check the selected index. 
Can try it too:
Gridview1.Rows(Gridview1.SelectedIndex).Cells(0).Text;


这篇关于从数据库填充Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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