Replace Desired Charecter in String

Following is The function ,Use to replace the special Charecters in String by "_". 


 protected static string replaceBadChars(string input)  
     {  
       StringBuilder sb = new StringBuilder(input);  
       string[] chars = new string[27] { "%", " ", "&", "!", "`", "$", "*", "(", ")",  
         "{", "}", "[", "]", "/", "\\", "|", ";", "'", "\"", "<", ">", "?", "+", "#", "=", ".", "-" };  
       foreach (string st in chars)  
       {  
         sb.Replace(st, "_");  
       }  
       return sb.ToString();  
     }  
Read More »

How to add & access Connectionstring in .net


In app.config or web.config add the following code


 <configuration>  
  <connectionStrings>  
   <add name="Conn" connectionString ="Data Source=.\sqlexpress;Initial Catalog=SAM;User Id=sa;  
   Password=abc;integrated Security=true"/>  
  </connectionStrings>  
 </configuration>  


In codebehind file (.cs file) add the follwing line to access the connection string from config file

 string constring = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString.ToString();  


Note: for ConfigurationManager class add assembly refrence to refrence folder
Read More »

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 »