Sunday, May 5, 2013

How to check checkbox is checked or unchecked on button click in asp.net,c# using java script.

This article to check checkbox is checked or uncheked on button click.I am using java script here to validate
checkbox on client side.

Lets take a checkbox

<asp:CheckBox ID="chkbox" runat="server"  />

and a button
Now create function in java script like that.


<script type="text/javascript">

        function ValidCheckbox() {

            var d = document.getElementById('chkbox');

            if (d.checked) {
                return true;

            }
            else {

             
                return false;
            }

        }
</script>



Now call the java script function on button click

<asp:Button ID="Button1" runat="server" OnClientClick="return ValidCheckbox()" Text="Button" />


Now run it and see the result...

Thursday, January 3, 2013

Find n'th Highest value From Column in Sql Server

N'th Highest Value from column in sql server using subquery;

Suppose we have one table name  Employee  and its two column :Id, Salary

Now if  we want to find 5'th highest salary  of emploee then query is:


SELECT     TOP (1) Id
FROM         (SELECT     TOP (5) Salary
                       FROM          Employee 
                       ORDER BY Salary DESC) AS Salary
ORDER BY Salary


Tuesday, December 25, 2012

Java Script

Java script is languages that gives functionality in html. 

Tuesday, November 20, 2012

Find from tag of xml

string strValue = "";
      
      
         strValue = "<search(key)>123<search(key)>";
        //for value
        string from=strValue.Remove( strValue.LastIndexOf('<'));
        string value = from.Substring(from.LastIndexOf('>')+1);

        //for parametr
        string parametefrom = strValue.Substring(strValue.LastIndexOf('(')+1);
        string parameter = parametefrom.Remove(parametefrom.LastIndexOf(')'));

Thursday, August 30, 2012

Simple Web Crawler in C# to get Html content

 WebRequest request = WebRequest.Create("http://google.com/");//Type url here
        using (WebResponse response = request.GetResponse())
        {
            using (StreamReader responseReader =
              new StreamReader(response.GetResponseStream()))
            {
                string responseData = responseReader.ReadToEnd();
              string path=  Server.MapPath(".");
                if(!File.Exists(path+"//Asptrick.html"))
                File.Create(path+"//Asptrick.html");
                using (StreamWriter writer =
                  new StreamWriter(path + "//Asptrick.html")) //Where You Want to save Content
                {
                    writer.Write(responseData);
                }
            }
        }

use namespace for this as following:
using System.IO;
using System.Net;

Saturday, April 21, 2012

Create Table Dynamically from Data table When Column of Data Table conver to Table Cell or row.

Supoose We Have Table Employee
                 
           DataTable dt1;
           DataTable dt2;
            Table tb = new Table();
            tb.CssClass = "mGrid";
            Int32 k = 1;
            string lastvalue = "";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                String empNo = dt1.Rows[i][0].ToString();
              
                TableRow tbrow = new TableRow();
                TableRow tbr = new TableRow();
                TableRow tbr1 = new TableRow();

                if (i == 0)
                {
                    TableHeaderCell tbHcell = new TableHeaderCell();//Header Row for Serial No
                    tbHcell.Width = 60;
                    tbHcell.BackColor = System.Drawing.Color.Black;
                    tbHcell.ForeColor = System.Drawing.Color.White;
                    tbHcell.BorderWidth = 1;
                    tbHcell.RowSpan = 2;
                    tbHcell.Text = "SNo";
                    tbr1.Cells.Add(tbHcell);
                    TableHeaderCell tbHcell1 = new TableHeaderCell();//Header Row for emp No
                    tbHcell1.Width = 100;
                    tbHcell1.BackColor = System.Drawing.Color.Black;
                    tbHcell1.ForeColor = System.Drawing.Color.White;
                    tbHcell1.BorderWidth = 1;
                    tbHcell1.RowSpan = 2;
                    tbHcell1.Text = "empno";
                    tbr1.Cells.Add(tbHcell1);




                }
                TableCell tbcell = new TableCell();// Row value for serial No
                tbcell.Width = 60;
                tbcell.BorderWidth = 1;
                tbcell.Text = (i + 1).ToString();
                tbrow.Cells.Add(tbcell);
                TableCell tbcell1 = new TableCell();//Row value for emp No
                tbcell1.Width = 100;
                tbcell1.BorderWidth = 1;
                tbcell1.Text = empno;
                tbrow.Cells.Add(tbcell1);

                TableHeaderCell tbHcell5 = new TableHeaderCell();//Tabel main Header from dt table rows
                for (int j = 0; j < dt2.Rows.Count; j++)
                {
                    if (i == 0)
                    {
                        TableHeaderCell tbHcell2 = new TableHeaderCell();//Tabel Header from dt table rows
                        tbHcell2.Width = 100;
                        tbHcell2.BackColor = System.Drawing.Color.Black;
                        tbHcell2.ForeColor = System.Drawing.Color.White;
                        tbHcell2.BorderWidth = 1;
                        tbHcell2.Text = dt2.Rows[j][1].ToString();
                        tbr.Cells.Add(tbHcell2);

                        if (lastvalue == dt.Rows[j][2].ToString())
                        {
                            k = k + 1;
                        }
                        else
                        {
                            tbHcell5 = new TableHeaderCell();//Tabel main Header with column Span from dt table rows
                            tbHcell5.Width = 100;
                            tbHcell5.BackColor = System.Drawing.Color.Black;
                            tbHcell5.ForeColor = System.Drawing.Color.White;
                            tbHcell5.BorderWidth = 1;
                            tbHcell5.Text = dt2.Rows[j][2].ToString();
                            tbr1.Cells.Add(tbHcell5);
                            lastvalue = dt2.Rows[j][2].ToString();
                            k = 1;

                        }
                        tbHcell5.ColumnSpan = k;
                    }

                    TableCell tbcell2 = new TableCell();//table row value from dt table row
                    tbcell2.Width = 100;
                    tbcell2.BorderWidth = 1;
                    tbcell2.Text = Convert.ToDouble(dt2.Rows[j][7]).ToString("N2");
                    tbrow.Cells.Add(tbcell2);

                }
                if (i == 0)
                {
                    tb.Rows.Add(tbr1);
                    tb.Rows.Add(tbr);
                }
                tb.Rows.Add(tbrow);
            }
            Panel1.Controls.Add(tb);
        }