[英]VB.NET Get Value on Click from List Box
I have list of attachments with Names from SQL Table where when I select a file it download it from the Server. 我有带有“ SQL表中的名称”的附件列表,当我选择文件时,会从服务器下载文件。 What I need to Select the name and get the File name (Value Feild) I was able to run it smoothly but when I select from the List it gives me the Original File name.
我需要选择的名称并获取文件名(值Feild),我能够顺利运行它,但是当我从列表中进行选择时,它会为我提供原始文件名。 There is the Code:
有代码:
Protected Sub listload()
key = CardView.GetCardValues(CardView.FocusedCardIndex, CardView.KeyFieldName)
Dim sql As String = String.Format("Select Name,[File] from tblFile where ParentType='Contract' and ParentID = '{0}' order by ID", key)
Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ProjectC").ConnectionString)
Dim SelectCommand As New SqlCommand(sql, conn)
conn.Open()
attlist.Items.Clear()
Dim Reader As SqlDataReader = SelectCommand.ExecuteReader()
While Reader.Read()
If Reader.HasRows Then
attlist.Items.Add(Reader("Name").ToString)
attlist.ValueField = Reader("File").ToString
End If
End While
conn.Close()
conn.Dispose()
End Sub
Protected Sub attlist_SelectedIndexChanged(sender As Object, e As EventArgs) Handles attlist.SelectedIndexChanged
Response.ContentType = "APPLICATION/OCTET-STREAM"
Dim Header As [String] = "Attachment; Filename=" + attlist.SelectedItem.Value
Response.AppendHeader("Content-Disposition", Header)
Dim Dfile As New System.IO.FileInfo(Server.MapPath("~/Files/Attachments/" + attlist.SelectedItem.Value))
Response.WriteFile(Dfile.FullName)
Response.[End]()
End Sub
Column [Name] is the Displayed name and Column [File] is the attachment Appreciate your help Thanks. [名称]列是显示的名称,[文件]列是附件感谢您的帮助。
You need to add objects of type ListItem to fill the Text and Value properties. 您需要添加ListItem类型的对象以填充Text和Value属性。 The correct code would be:
正确的代码是:
While Reader.Read()
If Reader.HasRows Then
attlist.Items.Add(new ListItem(Reader("Name").ToString(),Reader("File").ToString()))
End If
End While
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.