2016-04-12 18 views
0

SQLテーブルの名前を持つ添付ファイルの一覧があります。ファイルを選択すると、そのファイルをサーバーからダウンロードします。私が必要とするもの名前を選択してファイル名を取得する(値Feild) これをスムーズに実行できましたが、リストから選択すると元のファイル名が表示されます。 コードがあります:VB.NETリストボックスからのクリックで値を取得

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

TextおよびValueプロパティを満たすには、ListItem型のオブジェクトを追加する必要があります。正しいコードは次のようになります:

While Reader.Read() 
    If Reader.HasRows Then 
     attlist.Items.Add(new ListItem(Reader("Name").ToString(),Reader("File").ToString())) 
    End If 
End While 
+0

ありがとうございます。 –

関連する問題