public void dwx(object sender, CommandEventArgs e) { if (e.CommandName == "dw") { LinkButton lb = sender as LinkButton; DataListItem dlrow = lb.NamingContainer as DataListItem; string id = ((Label)dlrow.FindControl("Label9")).Text; connection(); SqlCommand com = new SqlCommand("select FileName,FileType,Filedata from Newsu where Newsid=@id", con); com.Parameters.AddWithValue("@id", id); SqlDataReader dr = com.ExecuteReader(); if (dr.Read()) { Response.Clear(); Response.Buffer = true; Response.ContentType = dr["FileType"].ToString(); Response.AddHeader("content-disposition", "attachment;filename=" + dr["FileName"].ToString()); Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.BinaryWrite((byte[])dr["Filedata"]); Response.End(); } } }
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Panel ID="Panel1" runat="server" BackColor="White" Width="320px" Height="792px" ScrollBars="Both" Visible="true" > <asp:DataList ID="DataList1" runat="server" BackColor="White" ToolTip="Download file" DataKeyField="Newsid" Font-Names="Segoe UI" Width="300px" onitemdatabound="DataList1_ItemDataBound" GridLines="Both" > <AlternatingItemStyle BackColor="#CCCCCC" /> <ItemTemplate> <div class="headitem"> <div class="heads"> <asp:Label ID="Label6" runat="server" Text='<%# Eval("Emailattach") %>' Visible="false" ></asp:Label> <asp:Label ID="Label2" runat="server" Text='<%# Eval("Subject") %>' Font-Names="Segoe UI" Font-Size="Medium" ForeColor="White"></asp:Label></div> <asp:LinkButton ID="ImageButton1" runat="server" Height="21px" BorderStyle="Solid" BorderColor="#2A2A2A" Width="22px" OnCommand="dwx" CommandName="dw" > <img src="images/a.png" /> </asp:LinkButton> </div> <br /> <div class="line"> <asp:Label ID="Label3" runat="server" Text='<%# Eval("Line") %>' Font-Names="Segoe UI" ></asp:Label> <asp:Label ID="Label7" runat="server" Text='<%# Eval("Departmentdesc") %>' Font-Names="Segoe UI" Font-Size="Smaller"></asp:Label> <br /> <br /> <asp:Label ID="Label4" runat="server" Text='<%# Eval("Email")%> ' ></asp:Label> <asp:Label ID="Label8" runat="server" Text='<%#Eval("Phone") %> ' ></asp:Label> <div class ="times"> <asp:Label ID="Label5" runat="server" Text='<%# Eval("Newstime") %>'></asp:Label> <asp:Label ID="Label9" runat="server" Text='<%# Eval("Newsid") %>' Visible="false"></asp:Label> </div> </div> </ItemTemplate> </asp:DataList> </asp:Panel> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Ticker1" EventName="Tick" /> </Triggers> </asp:UpdatePanel>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)