如何通过函数将Gridview标签传递给后面的代码 [英] How to pass a Gridview label to code behind via a function

查看:67
本文介绍了如何通过函数将Gridview标签传递给后面的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我是VB和Visual Studio的新手,非常感谢帮助从GridView专栏访问数据。

I am new to VB and Visual Studio and would greatly appreciate help in accessing data from a GridView Column.

我需要通过函数将Gridview标签传递给后面的代码,或者直接从后面的代码中的函数检索Gridview标签。该函数是GetVideoLink(),我将其编码为将视频的位置返回到GridView中的视频控件源
。视频保存在表格中,并通过SqlDataSource使用电子邮件作为唯一标识符进行检索。每个视频和相应的电子邮件都保存在同一个GridView列中。 Gridview仅显示包含视频和电子邮件的行。
如果我在后面的代码中对电子邮件进行硬编码,或者如果我通过该函数将硬编码的电子邮件传递给后面的代码,则此代码有效。 

I need to EITHER pass a Gridview label to the code behind via a function OR retrieve the Gridview label directly from the function in the code behind. The function is GetVideoLink() and I coded it to return the location of a video to the video controls source in the GridView. The video is held in a table and it is retrieved via SqlDataSource using the email as a unique identifier. Each video and corresponding email are held in the same GridView column. The Gridview only displays rows that have a video and email. This code works if I hard-code the email in the code behind or if I pass the hard-coded email to the code behind via the function. 

我的初始方法是传递"EmailLabel.Text"。通过GetVideoLink()函数返回后面的代码。 

My initial approach was to pass "EmailLabel.Text" to the code behind via the GetVideoLink() function. 

我的第二种方法是直接从后面的代码中检索GridView标签,这似乎涉及更多,这就是为什么我的原因首选项是将电子邮件的值传递给函数(每行调用一次函数)。

My second approach was to retrieve the GridView label directly from the code behind, which seems much more involved, and which is why my preference would be to pass the value of the email to the function (the function is called once for each row).

当我尝试使用任何一种方法运行时,我得到错误"对象引用未设置为对象的实例"。 

When I try to run with either approach, I get the error "object reference not set to an instance of an object ". 

这是我的第二种方法的当前代码的一部分(我加粗了相关项目):

This is the portion of the current code for my second approach (I bolded the relevant items):

前端代码:

< asp:TemplateField HeaderText =" Video" SortExpression =" Video1">

<asp:TemplateField HeaderText="Video" SortExpression="Video1">

代码背后(FindControl行不起作用)

CODE BEHIND (the FindControl line does not work)

非常感谢你的帮助,

Anne

推荐答案

嗨Anne_G,

Hi Anne_G,

由于此论坛正在讨论并询问有关Visual Basic编程的问题

Since this forum is discussing and asking questions about the Visual Basic programming

语言,IDE,库,示例和工具。而你的问题与asp.net有关。有关asp.net的链接,请参考:
https://forums.asp.net/

language, IDE, libraries, samples, and tools . And your issue is more related to asp.net. This link about asp.net, please refer that: https://forums.asp.net/

感谢您参与论坛活动。

最诚挚的问候,

Cherry


这篇关于如何通过函数将Gridview标签传递给后面的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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