gridview の templatefield 内のボタンで関数を実行し、フィールドの 1 つに基づいて eval を送信しようとしています。すでにいくつかの方法を試しましたが、仕事をすることができませんでした。
アップロードされたファイルとこれらのファイルへのパスに関する情報を含む mssql データベースがあります。特定のファイルをそのパスでダウンロードできるボタンを各行に追加したいと思います。
これは sqldatasource と gridview です。
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:igroup20_test2ConnectionString %>"
SelectCommand="SELECT [f_name], [f_date], [f_description], [f_path], [f_num] FROM [uploaded_files]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
AutoGenerateColumns="False"
>
<Columns>
<asp:BoundField DataField="f_name" HeaderText="Name"
SortExpression="LastName" />
<asp:BoundField DataField="f_date" HeaderText="Date"
SortExpression="FirstName" />
<asp:BoundField DataField="f_description" HeaderText="Description"
SortExpression="Title" />
<asp:TemplateField HeaderText="download">
<ItemTemplate>
<asp:Button ID="btn" runat="server" CssClass="btn btn-primary" Text="Download" OnClick='<%# Eval("f_path", "download_file(\"{0}\");") %>' />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
これは関数の背後にあるコードです:
protected void download_file(object sender, EventArgs e,string val)
{
filename = "Server side exc 2PLATINA.JPG";
string path = val;
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename='someName'" );
Response.TransmitFile(val);
Response.End();
}
もう 1 つの興味深い点は、同じ ID を持つ複数のボタンに例外がないのはなぜですか?