Note that there are some explanatory texts on larger screens.

plurals
  1. POsend parameter to server function from gridview using eval on button click (template field)
    primarykey
    data
    text
    <p>I'm trying to make a button inside templatefield in gridview run a function and send eval based on one of the fields. already tried several methods, but could not make it to do the job.</p> <p>I have a mssql database which contains info about files uploaded and paths to these files. I would like to add a button to each row that will allow me to download the specific file by it's path.</p> <p><strong>this is the sqldatasource and the gridview:</strong></p> <pre><code> &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:igroup20_test2ConnectionString %&gt;" SelectCommand="SELECT [f_name], [f_date], [f_description], [f_path], [f_num] FROM [uploaded_files]"&gt;&lt;/asp:SqlDataSource&gt; &lt;asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" &gt; &lt;Columns&gt; &lt;asp:BoundField DataField="f_name" HeaderText="Name" SortExpression="LastName" /&gt; &lt;asp:BoundField DataField="f_date" HeaderText="Date" SortExpression="FirstName" /&gt; &lt;asp:BoundField DataField="f_description" HeaderText="Description" SortExpression="Title" /&gt; &lt;asp:TemplateField HeaderText="download"&gt; &lt;ItemTemplate&gt; &lt;asp:Button ID="btn" runat="server" CssClass="btn btn-primary" Text="Download" OnClick='&lt;%# Eval("f_path", "download_file(\"{0}\");") %&gt;' /&gt; &lt;/ItemTemplate&gt; &lt;ItemStyle HorizontalAlign="Center" /&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p><strong>this is the code behind function:</strong></p> <pre><code>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(); } </code></pre> <p>another small interesting thing, how come there is no exception about the multiple buttons with the same id?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload