如何从控制到另一个控件传递数据? [英] How to pass data from a control to another control?
问题描述
我有我想传递一个对象控件,以便它从一个数据库文件名来设置它的数据属性的asp文字元素。下面是我的了:
I have a asp Literal element that I want to pass to an object control to set its data property so that it pulls a filename from a database. Here's what I got:
<asp:FormView ID="Formview1" runat="server" DataSourceID="AccessDataSource1">
<ItemTemplate>
<object type="video/x-ms-wmv" data='<%= strFileName %>'
width="450" height="380">
<!-- this param is required for anyone using IE--><param name="src" value='<%= Filename %>' />
<param name="autostart" value="false" />
<param name="controller" value="true" />
</object>
</ItemTemplate>
</asp:FormView>
背后code:
Partial Class VideoPlayer
Inherits System.Web.UI.Page
Protected strFileName As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim con As New OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim vidID As Integer = Integer.Parse(Request.QueryString("ID"))
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = |DataDirectory|/webvideos.mdb"
con.ConnectionString = dbProvider & dbSource
con.Open()
Dim strSQL As String = "SELECT * FROM Videos WHERE ID=" & vidID
strFileName = "videos/TrainingVideos/" & Eval("Filename")
con.Close()
End Sub
End Class
你知道吗?我希望它是简单的,哈哈。
Any idea? I hope it is simple, lol.
推荐答案
我没有处理过的%的咚咚数据绑定标签,但你可以做到这一点:
I've not dealt with the "percent pound" databind tags, but you may be able to do this:
<object type="video/x-ms-wmv" data='<%# "videos/TrainingVideos/" & Eval("Filename") %>'
width="450" height="380">
<!-- this param is required for anyone using IE-->
<param name="src" value='<%# "videos/TrainingVideos/" & Eval("Filename") %>' />
<param name="autostart" value="false" />
<param name="controller" value="true" />
</object>
如果没有 - 您可以将您的文件名+路径加载到页面加载服务器端的一个受保护的全球范围的变量(如 strFilepath
),或宣布一个保护函数,返回文件名+路径(您可能要缓存,如果你将要调用了很多) - 再去做像这样:
If not - you can load your filename + path into a protected global-scope variable (e.g. strFilepath
) on the server side in the page load, or declare a protected function that returns the filename + path (which you may want to cache if you are going to be calling it a lot) - then do it like so:
<object type="video/x-ms-wmv" data='<%= getFilepath() %>'
width="450" height="380">
<!-- this param is required for anyone using IE-->
<param name="src" value='<%= getFilepath() %>' />
<param name="autostart" value="false" />
<param name="controller" value="true" />
</object>
然后像这样在code背后:
and then something like this in the code behind:
Protected Function getFilepath() As String
Return "file path/filename"
End Sub
或
Protected Dim strFilepath As String
Public Sub Page_Load()
strFilePath = "file path/filename"
End Sub
随着&LT;%= strFilepath%GT;
有意义吗?
这篇关于如何从控制到另一个控件传递数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!