我有一个用于视频上传的网络应用程序,因为我想在链接中显示视频click.i写了一个函数来显示视频。我想将视频的id传递给函数。我怎么能去做? 任何人都可以帮助我吗?
这是我的代码
Private Function
GetSpecificVideo(ByVal i As Object) As
DataTable
'pass the id of the video
Dim connectionString As String =
ConfigurationManager.ConnectionStrings("UploadConnectionString")
.ConnectionString
Dim adapter As New SqlDataAdapter("SELECT FileName,
FileID,FilePath " + "FROM FileM WHERE
FileID = @FileID", connectionString)
adapter.SelectCommand.Parameters.Add("@FileID",
SqlDbType.Int).Value = DirectCast(i, Integer)
Dim table As New DataTable()
adapter.Fill(table)
Return table
End Function
Protected Sub ButtonShowVideo_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ButtonShowVideo.Click
Repeater1.DataSource = GetSpecificVideo(****here i want to get the ID****)
'the video id (2 is example)
Repeater1.DataBind()
End Sub
答案 0 :(得分:1)
有很多方法可以为链接设置CommandArgument
(或者更确切地说就是代码所示的按钮)。
ASPX:
<ItemTemplate>
<asp:LinkButton ID="lnkVideo" runat="server"
CommandArgument='<%# Eval("VideoID")%>'
OnClick="ButtonShowVideo_Click">Watch Video</asp:LinkButton>
</ItemTemplate>
代码: private sub void GetVideos() '获取视频(S) '创建链接或在网格中获取链接并为其设置命令论据 lnk1.CommandArgument = ID_OF_VIDEO 结束子
现在处理点击:
Protected Sub ButtonShowVideo_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ButtonShowVideo.Click
var btn = sender as Button 'or Link or LinkButton
if(btn is not null) then
if(NOT string.IsNullOrEmpty(btn.CommandArgument)) then
var vid = Convert.ToInt32(btn.CommandArgument)
Repeater1.DataSource = GetSpecificVideo(vid)
Repeater1.DataBind()
end if
end if
End Sub