Download the pdf file on the server store in folder


Take link button in update panel.
Apply trigger to Link Button.
Write the Follwing Code in the link button click event.


 System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;  
         response.Clear();  
         response.AddHeader("Content-Disposition", "attachment; filename=" + "ABC.pdf" + ";");  
         response.ContentType = "application/excel";  
         response.TransmitFile("~//Downloadable//ABC.pdf");  
         response.End();  


Note: You can change 'response.ContentType = "application/excel";' for excel document,also change file name that u want to download from server folder(eg.ABC.pdf to ABC.csv).
Read More »

Add Resoluion Specific Media CSS

Add The follwing Code to Css file include the Class in that
you can change min & max width as per requirement.

@media screen and (min-width: 1100px) and (max-width:1300px)
{
         .abc
         {

          }
            #xyz
           {

            }
}
Read More »

How to Add Check Box Select,Select All, Unselect and Unselect All Functionality in Gridview Column


First Add Check Box column in Gridview as Follows
 <asp:GridView runat="server" ID="grv" AutoGenerateColumns="false" GridLines="Vertical"  
     BorderWidth="0" AllowPaging="true" PagerStyle-HorizontalAlign="Center" OnRowCreated="grvClassCaption_RowCreated">  
     <Columns>  
       <asp:TemplateField HeaderStyle-HorizontalAlign="Center" HeaderText="Select All" ItemStyle-HorizontalAlign="Center"  
         HeaderStyle-CssClass="GridHeader" ItemStyle-Width="200px">  
         <HeaderTemplate>  
           <asp:CheckBox ID="chkHeader" runat="server" Text="Select All" Onclick="SetCheckBoxes(this)" />  
         </HeaderTemplate>  
         <ItemTemplate>  
           <asp:CheckBox ID="chkBox" runat="server" Text="Select" Onclick="ChangeHeader()" />  
         </ItemTemplate>  
       </asp:TemplateField>  
       <asp:TemplateField HeaderStyle-HorizontalAlign="Center" HeaderText="Name" ItemStyle-HorizontalAlign="Center"  
         HeaderStyle-CssClass="GridHeader" ItemStyle-VerticalAlign="Top" ItemStyle-CssClass="GridColumn"  
         ItemStyle-Width="200px">  
         <ItemTemplate>  
           <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name")%>'></asp:Label>  
         </ItemTemplate>  
       </asp:TemplateField>  
     </Columns>  
   </asp:GridView>  
   <div>  
     <asp:Button ID="Button1" runat="server" Text="SAVE" OnClick="BtnSave_Click" />  
   </div>  

And ADD Following Script to the header of page
 <script type="text/javascript">  
     function ChangeHeader()  
     {  
       var Parent = document.getElementById("<%=grv.ClientID %>");  
       var chkList = Parent.getElementsByTagName('input');  
       chkList[0].checked = true;  
       for (i = 1; i < chkList.length; i++) {  
         if (!chkList[i].checked) {  
           chkList[0].checked = false;  
         }  
       }  
     }  
     function SetCheckBoxes(chkHeader)   
     {  
       var Parent = document.getElementById("<%=grv.ClientID %>");  
       var chkList = Parent.getElementsByTagName('input');  
       if (chkHeader.checked) {  
         for (i = 0; i < chkList.length; i++) {  
           chkList[i].checked = true;  
         }  
       }  
       else {  
         for (i = 0; i < chkList.length; i++) {  
           chkList[i].checked = false;  
         }  
       }  
     }  
 </script>  

On SAVE button click Check the check box Condition
  protected void BtnSave_Click(object sender, EventArgs e)  
     {  
         int count = 0;  
         for (int i = 0; i < grv.Rows.Count; i++)  
         {  
           GridViewRow row = grv.Rows[i];  
           bool isChecked = ((CheckBox)row.FindControl("chkBox")).Checked;  
           if (isChecked)  
           {  
             count++;  
           }  
         }  
         if (count != 0)  
         {  
           SaveData(); //save the data to database  
         }  
 }  
Read More »

How to Apply IE Specific CSS in ASP.net Application

First add the following meta tags on master page or content page ,where we are using particular CSS class.

 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

 <!--[if IE 8 ]> <html class="ie8"> <![endif]-->

For eg. Class abc 

And in CSS file write class as follows
And write browser specific properties in this class.

.ie8 .abc
{

//class style here

}
Read More »

Function To Convert Object of List Type into Datatable Object


public DataTable ConvertToDataTable<T>(IList<T> data)
        {
            PropertyDescriptorCollection properties =
               TypeDescriptor.GetProperties(typeof(T));
          
            foreach (PropertyDescriptor prop in properties)
            {
              
                table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
              
            }
            foreach (T item in data)
            {
                DataRow row = table.NewRow();
                foreach (PropertyDescriptor prop in properties)
                    row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
                table.Rows.Add(row);
            }
            return table;
        }
Read More »