Search This Blog

Friday, September 3, 2010

C# to give download link in gridview control

Source code fot gridview:-

   1:  <asp:GridView ID="grdsearch" runat="server" AutoGenerateColumns="False">
   2:                             
   3:<Columns>
   4: <asp:BoundField HeaderText="Full Name" DataField="FullName"/>
   5: <asp:BoundField HeaderText="Email ID" DataField="Email"/>
   6: <asp:BoundField HeaderText="Gender" DataField="Sex"/>
   7: <asp:BoundField HeaderText="Education" DataField="Education"/>
   8: <asp:BoundField HeaderText="Skills" DataField="Skillsetdetails"/>
   9: <asp:BoundField HeaderText="Total Experience" DataField="Totalexperience"/>
  10: <asp:BoundField HeaderText="Relvent Experience" DataField="Relventexperience"/>
  11: <asp:BoundField HeaderText="Address" DataField="Address"/>
  12: <asp:BoundField HeaderText="Previous Company Detail" DataField="Previousemployerdetail"/>
  13: <asp:BoundField HeaderText="Mobile Number" DataField="Mobileno"/>
  14: <asp:BoundField HeaderText="Availability" DataField="Availability"/>
  15: <asp:BoundField HeaderText="Currentctc" DataField="Currentctc"/>
  16: <asp:BoundField HeaderText="Expectedctc" DataField="Expectedctc"/>
  17: <asp:BoundField HeaderText="Preferred Location" DataField="StateName"/>
  18: <asp:BoundField HeaderText="Resume Name" DataField="ResumeName"/>
  19: <asp:TemplateField>
  20:  <ItemTemplate>
  21: <asp:LinkButton ID="LinkButton1" runat="server" Text="Resume Download" 
    CommandArgument='<%#Eval("Attachment")%>' OnCommand="btnDownload_Click">
  22:   
  23: asp:LinkButton>
  24:     ItemTemplate>
  25: asp:TemplateField>
  26:                  
  27:  Columns>
  28:  asp:GridView>

C# code to make file download on linkbutton click:-

 protected void btnDownload_Click(object sender, System.Web.UI.WebControls.CommandEventArgs e)
        {
            //Response.Write(e.CommandArgument.ToString());
            //Response.Write(e.CommandName.ToString()  );

            string queryString = e.CommandArgument.ToString();
            Response.Redirect(queryString);

        }

1 comment: