我有来自SQL Table的名称的附件列表,当我选择一个文件时,它从服务器下载它。我需要选择名称并获取文件名(Value Feild) 我能够顺利运行它,但是当我从列表中选择它时,它给我原始文件名。 有代码:
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
列[名称]是显示的名称,列[文件]是附件 感谢您的帮助 感谢。
答案 0 :(得分:0)
您需要添加ListItem类型的对象以填充Text和Value属性。正确的代码是:
While Reader.Read()
If Reader.HasRows Then
attlist.Items.Add(new ListItem(Reader("Name").ToString(),Reader("File").ToString()))
End If
End While