我如何在asp.net.i中使用request.querystring有一个linkbutton,这是在转发器控件中。我想播放相应链接的视频_click.i想要将相应链接的fileID传递给功能,我该怎么做?
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<asp:LinkButton runat="server" ID="LnkBtn"
OnClick="ButtonShowVideo_Click"><%#Eval("FileName")%>
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
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 fileID**)
Repeater1.DataBind()
End Sub
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
答案 0 :(得分:1)
这对你没有帮助:
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<asp:LinkButton runat="server" ID="LnkBtn"
OnClick="ButtonShowVideo_Click"><%#Eval("FileName")%>
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
因为它不会将FileName放入查询stirng中。而是使用这种方法:
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<asp:LinkButton runat="server" ID="LnkBtn"
CommandArgument='<%#Eval("FileName")%>'
OnClick="ButtonShowVideo_Click"><%#Eval("FileName")%>
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
在代码背后:
Protected Sub ButtonShowVideo_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ButtonShowVideo.Click
Dim btn as LinkButton = sender as LinkButton
if(btn is not null) then
if(NOT string.IsNullOrEmpty(btn.CommandArgument)) then
dim vid as integer = Convert.ToInt32(btn.CommandArgument)
Repeater1.DataSource = GetSpecificVideo(vid)
Repeater1.DataBind()
end if
end if
End Sub
答案 1 :(得分:0)
如果您打算使用查询字符串,则单击按钮可以执行以下任一操作:
那么你发现哪些问题具有挑战性?