現在、データバインディングに問題があります。私はまだデータバインディングを行う正しい方法を持つ方法を学んでいます。問題は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
のために設定されている
ダウンロード時にエラーが表示されますか? – Imad
ページも表示できません。自動的にエラーが表示されます。 – namasayadin