2016-05-04 39 views
0

現在、データバインディングに問題があります。私はまだデータバインディングを行う正しい方法を持つ方法を学んでいます。問題はDataBindingです。 'System.Data.Common.DataRecordInternal'には、 'fileName'という名前のプロパティが含まれていません。DataBinding: 'System.Data.Common.DataRecordInternal'に 'fileName'という名前のプロパティが含まれていません

私が理解している限り、データバインディングは、バックエンドコーディングで集計する必要があるfileNameですが、私は同じにしましたが、エラーはまだ発生します。以下は私のaspx.csコーディングです。ここで

protected void DownloadFile(object sender, EventArgs e) 
    { 
     int id = int.Parse((sender as LinkButton).CommandArgument); 
     //byte[] bytes; 
     string fileName; 
     string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Ulysses"].ConnectionString; 
     using (SqlConnection con = new SqlConnection(connectionString)) 
     { 
      using (SqlCommand cmd = new SqlCommand()) 
      { 
       cmd.CommandText = "SELECT TOP 10 OLE_LINK_FILE_NAME FROM OLE_LINK"; 
       //cmd.Parameters.AddWithValue("@Id", id); 
       cmd.Connection = con; 
       con.Open(); 
       using (SqlDataReader sdr = cmd.ExecuteReader()) 
       { 
        sdr.Read(); 
        fileName = sdr["OLE_LINK_FILE_NAME"].ToString(); 
       } 
       con.Close(); 
      } 
     } 
     Response.Clear(); 
     Response.Buffer = true; 

     Response.Charset = ""; 
     Response.Cache.SetCacheability(HttpCacheability.NoCache); 
     //Response.ContentType = contentType; 
     Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName); 
     //Response.BinaryWrite(bytes); 
     Response.Flush(); 
     Response.End(); 
    } 

は私のHTMLコーディングです:実際に私は、パラメータファイル名で欠場でしたコーディングから、

<asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White" 
RowStyle-BackColor="#A1DCF2" AlternatingRowStyle-BackColor="White" AlternatingRowStyle-ForeColor="#000" 
AutoGenerateColumns="false"> 
<Columns> 
    <asp:BoundField DataField="OLE_LINK_FILE_NAME" HeaderText="File Name"/> 
    <asp:TemplateField ItemStyle-HorizontalAlign = "Center"> 
     <ItemTemplate> 
      <asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="DownloadFile" 
       CommandArgument='<%# Eval("fileName") %>'></asp:LinkButton> 
     </ItemTemplate> 
    </asp:TemplateField> 
</Columns> 

?あなたがGridView1のために設定されている

+0

ダウンロード時にエラーが表示されますか? – Imad

+0

ページも表示できません。自動的にエラーが表示されます。 – namasayadin

答えて

1

データソースは、System.Data.Common.DataRecordInternalのリストであり、私はあなたのクラスSystem.Data.Common.DataRecordInternal名前fileNameと性質を持っていないいずれか、またはそれは範囲が限られていると思います。存在する場合は、publicにしてください。

下記からご連絡ください。ダウンロードリンクのコマンド引数には、fileNameOLE_LINK_FILE_NAMEに置き換える必要があります。

+0

私はC#に慣れていませんが、私のエラーはSystem.Data.Common.DataRecordInternalに関するVisual Studioの表示であるため、あなたの答えは正しいと思います。 私はaspx.csページでそれを見ることができないので、どこで変更しますか? – namasayadin

+0

System.Data.Common.DataRecordInternalを.csファイル内に書き出し、F12キーを押すと、クラス定義に移動します。 1つの質問、それはinbuildクラスですか、誰かがそれを書いていますか? – Imad

+0

質問2:グリッドにバインドしている構造を記述することはできますか? – Imad

関連する問題