Pages

Tuesday, January 10, 2012

Check / Uncheck all checkbox in treeview using jquery in asp.net

Check / Uncheck all checkbox in treeview using jquery in asp.net

Introduction : In this article i will show you how check all checkboxes in treeview using Jquery in asp.net .It is very easy just you need add code and replace id as per treeview control . For the binding the Treeview control in asp.net you can visits my previous post bind treeview in-asp.net .
Jquery for check / uncheck all checkboxes in treeview in c# :

Following is jquery code for check or uncheck all checkboxes in treeview control and HTML code in asp.net .

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TreeViewControl.aspx.cs"
    Inherits="HamidSite.TreeViewControl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" >

        $(document).ready(function () {

            $("div[id $= treeviwExample] input[type=checkbox]").click(function () {
                $(this).closest("table").next("div").find("input[type=checkbox]").attr("checked", this.checked);
            });

        });    
        
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TreeView ID="treeviwExample" ShowCheckBoxes="All"  runat="server" ImageSet="Arrows">
            <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
            <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
            <ParentNodeStyle Font-Bold="False" />
            <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px" VerticalPadding="0px" />            
        </asp:TreeView>
    </div>
    </form>
</body>
</html>


Related Other posts

Monday, January 9, 2012

Bind Treeview in asp.net c# using dataset

Bind Treeview in asp.net c# using dataset
Introduction : In this article i will show you how to bind treeview in c# using dataset . I have created complete code to bind the treeview and also table structure in image which require for the treeview control to bind in asp.net c# using dataset .
Table structure :
HTML code treeview in asp.net :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TreeViewControl.aspx.cs"
    Inherits="HamidSite.TreeViewControl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TreeView ID="treeviwExample"  runat="server" ImageSet="Arrows">
            <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
            <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
            <ParentNodeStyle Font-Bold="False" />
            <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px" VerticalPadding="0px" />            
        </asp:TreeView>
    </div>
    </form>
</body>
</html>

C# Code treeview control in asp.net :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace HamidSite
{
    public partial class TreeViewControl : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                BindTreeViewControl();
            }
        }
        private void BindTreeViewControl()
        {
            try
            {
                DataSet ds = GetDataSet("Select ProductId,ProductName,ParentId from ProductTable");
                DataRow[] Rows = ds.Tables[0].Select("ParentId IS NULL"); // Get all parents nodes
                for (int i = 0; i < Rows.Length; i++)
                {
                    TreeNode root = new TreeNode(Rows[i]["ProductName"].ToString(), Rows[i]["ProductId"].ToString());
                    root.SelectAction = TreeNodeSelectAction.Expand;
                    CreateNode(root, ds.Tables[0]);
                    treeviwExample.Nodes.Add(root);
                }
            } catch (Exception Ex) { throw Ex; }
        }

        public void CreateNode(TreeNode node , DataTable Dt)
        {
            DataRow[] Rows = Dt.Select("ParentId =" + node.Value);            
            if (Rows.Length == 0) { return; }
            for (int i = 0; i < Rows.Length; i++)
            {
                TreeNode Childnode = new TreeNode(Rows[i]["ProductName"].ToString(), Rows[i]["ProductId"].ToString());
                Childnode.SelectAction = TreeNodeSelectAction.Expand;
                node.ChildNodes.Add(Childnode);
                CreateNode(Childnode, Dt);
            }
        }
        private DataSet GetDataSet(string Query)
        {           
            DataSet Ds = new DataSet();
            try {
                string strCon = @"Data Source=Servername;Initial Catalog=Test;Integrated Security=True"; 
                SqlConnection Con = new SqlConnection(strCon);
                SqlDataAdapter Da = new SqlDataAdapter(Query, Con);
                Da.Fill(Ds);
            } catch (Exception) { }
            return Ds; 
        }
    }
}

For Check / Uncheck Checkboxes in treeview control using jquery you can visit following post :- Check / Uncheck Checkboxes in treeview control using jquery

Related Other posts

Saturday, January 7, 2012

Merge word document files in asp.net c#

Merge word document files in asp.net c#

Introduction : This article show you how to merge or combine two more doc files in Asp.net using C# .
I have created one function to merge multiple word file in c# .it is very easy to use .You just need to pass word file path arrays and save file path . Then i will save  merged word document file .

Add following dll reference to your application :

Microsoft.Office.Interop.Word


Code for merge word doc files : 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Office.Interop.Word;

namespace HamidSite
{
    public partial class MergerWorddocs : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string[] DocsFiles = new string[] { @"C:\Merfiles\Doc1.docx", @"C:\Merfiles\Doc2.docx" };
            string PathToSave =Server.MapPath("MergesDocs/MergeDoc.docx");
            Merge(DocsFiles,PathToSave,true);
            
        }
        public void Merge(string[] filesToMerge, string fileSavePath, bool insertPageBreaks)
        {  
            object missing = System.Type.Missing;
            object pageBreak = WdBreakType.wdPageBreak;
            object outputFile = fileSavePath;
           
            Application wordApplication = new Application();
            try
            {                
                Document wordDocument = wordApplication.Documents.Add(ref missing, ref missing , ref missing , ref missing);                           
                Selection selection = wordApplication.Selection;
               
                foreach (string docFile in filesToMerge)
                {
                    selection.InsertFile(docFile , ref missing , ref missing , ref missing , ref missing);
                    if (insertPageBreaks)
                    {
                        selection.InsertBreak(ref pageBreak);
                    }
                }               
                wordDocument.SaveAs(ref outputFile, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                wordDocument = null;
                wordApplication.Quit(ref missing, ref missing, ref missing);
            }
            catch (Exception ex) { throw ex; }           
        }
    }
} 



Related Other posts

Friday, January 6, 2012

Validation Using Jquery in Asp.net page

Validation Using Jquery in Asp.net page

Introduction : This article show you how to add validation using Jquery in Asp.net . Validation is easy in jquery just need add my following complete html code for Jquery validation in asp.net .



Hows  Jquery validation works in Asp.net :
 
you can download  Jquery.validate.js from http://jzaefferer.github.com/jquery-validation/jquery.validate.js
you can apply required validation by adding class to textbox like : CssClass="required". ..etc .so on you can Url validation ,date validation , digits validation ..etc using jquery . 

Complete Html Code for Jquery validation in asp.net page :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JqueryValidation.aspx.cs" Inherits="HamidSite.JqueryValidation" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery.validate.js" type="text/javascript"></script>
    <script type="text/javascript"  >
         $(document).ready(function () {
             $("#form1").validate();
         });
  </script>
 <style type="text/css">
    label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
</style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
            <fieldset style="width:500px;vertical-align:middle;font-family:Verdana;font-size:12px;border-bottom-width:medium;" >
                <legend>Validation Using Jquery in Asp.net page </legend>
                <table align="center" cellpadding="5px" >
                    <tr>
                        <td>
                            Name :
                        </td>
                        <td>
                            <asp:TextBox ID="txtname" CssClass="required" runat="server" ></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Amount :
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox1" CssClass="digits" runat="server" ></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Website url :
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox2" CssClass="url" runat="server" ></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Email :
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox3" CssClass="email" runat="server" ></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Date :
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox4" CssClass="date" runat="server" ></asp:TextBox>
                        </td>
                    </tr>
                     <tr>
                        <td>
                            
                        </td>
                        <td>
                            <asp:Button ID="btnSave"  runat="server" Text="Submit" />
                        </td>
                    </tr>
                </table>
            </fieldset>
    </div>
    </form>
</body>
</html>



Related Other posts

DOC file to RTF format in asp.net C#.

DOC file to RTF format in asp.net C#.

Introduction : This article describe how you can convert the DOC file to RTF format in asp.net using c# language .

Code For Doc to RTF: I have created one function to convert DOC file to RTF format in c# . You need to pass just doc file path to it and it save the .RTF format file .
First you need to add reference of Microsoft.Office.Interop.Word.dll dll in project .
Microsoft.Office.Interop.Word.dll

Function For Conversion Doc To RTF :
public void ConvertDocToRTF(string DocPath)
{        
        //Creare object of documnet .
        Document document = new Document();
        try
        {
          //Load doc file from given path
          document.LoadFromFile(DocPath);
         //Save doc file. It will convert to .Rtf format .
          document.SaveToFile("Tesfile.rtf", FileFormat.Rtf);
        }
        catch (Exception) { throw; }
}

Call Function :
ConvertDocToRTF("MyDocFilePath");


Related Other posts

Thursday, January 5, 2012

Send Mail Using gmail In asp.net c#

Send Mail Using gmail In asp.net c#.

Introduction : In this article i will show you how to send mail in asp.net using gmail account.It is very simple just you need to pass your gmail account email address and password in System.Net.NetworkCredential() . And also you need to set host= smtp.gmail.com ,port =587 .I have following code to send mail using gmail account in asp.net c# .

protected void btnSendMail_Click1(object sender, EventArgs e)
    {        
        string myEmailAddress = "your gmail account";
        string mypwd = "your gmail account password";
        string toEmailAddress = "to email address";
        string subject = "Test Subject";
        string mailbody = "Test body";
       
        var client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587)
        {
            Credentials = new System.Net.NetworkCredential(myEmailAddress, mypwd),
            EnableSsl = true
        };
        client.Send(myEmailAddress, toEmailAddress, subject, mailbody);      
    }


Related Other posts

Wednesday, January 4, 2012

Redirect One website to another website automatically

Redirect One website to another website

Introduction : In this article i will show how to redirect one website to another website . Many times we require that some one visit  www.xyz.com  then he should be redirect to another site for that you need add peace of java-script code and it automatically redirect to another site .

<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
       location.replace("http://www.google.com");         
    </script>
</head>


Related Other posts