Check Uncheck All Checkboxes in Html Table Using JQuery

In this blog post, we will see a small example to check or uncheck all checkboxes in a html table using jquery. You can implement the same code in Asp.net gridview.

To make this work, first you need to use jquery in your web page.

There are many articles on web providing code samples to check or uncheck all checkboxes.
But here we will also see how a header checkbox acts indeterminate when few of the checkboxes are checked/unchecked.

The working example code is given below.



DataTable to Dictionary Conversion in C#.Net

In this post, here is the c# code to convert DataTable to Dictionary.

I have written 2 overrides for a method DataTabelToDictionary(). The Method code is given below:



  /// <summary>
 /// Converts DataTable to Dictionary
 /// </summary>
 /// <param name="dt">DataTable</param>
 /// <param name="keyIndex">Column Index for Dictionary Key</param>
 /// <param name="ValueIndex">Column Index for DIctionary Value</param>
 /// <returns></returns>
  public Dictionary<object, object> DataTabelToDictionary(DataTable dt, int keyIndex, int ValueIndex)
 {
    return dt.AsEnumerable()
            .ToDictionary<DataRow, object, object>(row => row.Field<object>(keyIndex),
                                        row => row.Field<object>(ValueIndex));
 }

    /// <summary>
  /// Converts DataTable to Dictionary
  /// </summary>
  /// <param name="dt">DataTable</param>
  /// <param name="keyIndex">Column Name for Dictionary Key </param>
  /// <param name="ValueIndex">Column Name for Dictionary Value</param>
  /// <returns></returns>
  public Dictionary<object, object> DataTabelToDictionary(DataTable dt, string keyColName, string ValColName)
  {
    return dt.AsEnumerable()
         .ToDictionary<DataRow, object, object>(row => row.Field<object>(keyColName),
                                        row => row.Field<object>(ValColName));
  }




The Program below is an example of converting DataTable to Dictionary.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;

namespace Dtable2Dict
{
    class Program
    {
        static void Main(string[] args)
        {
            Program objProg = new Program();
            DataTable dtDept = objProg.getDepartments();


            Dictionary<object, object> dicTest;
           
            //converting DataTable to Dictionary
            dicTest = objProg.DataTabelToDictionary(dtDept, "DeptId", "DeptName");

            //Converting Dictionary to our required Dictionary Type
            Dictionary<int, string> dicThruColNames = dicTest.ToDictionary(k => Convert.ToInt32(k.Key),
                                                k => k.Value == null ? "" : k.Value.ToString());

            dicTest = objProg.DataTabelToDictionary(dtDept, 0, 1);
            Dictionary<int, string> dicThruColIndex = dicTest.ToDictionary(k => Convert.ToInt32(k.Key),
                                                    k => k.Value == null ? "" : k.Value.ToString());

            //Printing Dictionary
            Console.WriteLine("\n*** www.programmingposts.com ***\n");
            Console.WriteLine("\n>>> Program for DataTable to Dictionary Conversion <<<\n");
            
            Console.WriteLine("Printing Converted Dictionary :");
            Console.WriteLine("Key || Value");
            foreach (KeyValuePair<int, string> pair in dicThruColNames)
            {
                Console.WriteLine(pair.Key + "  " + pair.Value);
            }
            Console.ReadLine();
        }

        /// <summary>
        /// returns sample DataTable
        /// </summary>
        /// <returns></returns>
        private DataTable getDepartments()
        {
            DataTable dtDept = new DataTable();
            dtDept.Columns.Add("DeptId", typeof(Int32));
            dtDept.Columns.Add("DeptName", typeof(String));
            dtDept.Columns.Add("DeptEmpCount", typeof(Int32));
            DataRow dr;

            for (int i = 1; i <= 5; i++)
            {
                dr = dtDept.NewRow();
                dr["DeptId"] = i;
                dr["DeptName"] = "Dept" + i.ToString();
                dr["DeptEmpCount"] = (i * 10);
                dtDept.Rows.Add(dr);
            }
            return dtDept;
        }

        /// <summary>
        /// Converts DataTable to Dictionary
        /// </summary>
        /// <param name="dt">DataTable</param>
        /// <param name="keyIndex">Column Index for Dictionary Key</param>
        /// <param name="ValueIndex">Column Index for DIctionary Value</param>
        /// <returns></returns>
        public Dictionary<object, object> DataTabelToDictionary(DataTable dt, int keyIndex, int ValueIndex)
        {
            return dt.AsEnumerable()
              .ToDictionary<DataRow, object, object>(row => row.Field<object>(keyIndex),
                                        row => row.Field<object>(ValueIndex));
        }

        /// <summary>
        /// Converts DataTable to Dictionary
        /// </summary>
        /// <param name="dt">DataTable</param>
        /// <param name="keyIndex">Column Name for Dictionary Key </param>
        /// <param name="ValueIndex">Column Name for Dictionary Value</param>
        /// <returns></returns>
        public Dictionary<object, object> DataTabelToDictionary(DataTable dt, string keyColName, 
                                           string ValColName)
        {
            return dt.AsEnumerable()
              .ToDictionary<DataRow, object, object>(row => row.Field<object>(keyColName),
                                        row => row.Field<object>(ValColName));
        }
    }

}

output:

VB.Net Program to print Numbers 1..N in Right Triangle Format



Module Module1

    Sub Main()
        Dim sum As Integer = 0, i As Integer, k As Integer, n As Integer
        Console.WriteLine("*** www.programmingposts.com ***")
        Console.WriteLine(vbLf & ">>> VB.Net Program to print Numbers 1..n as Right Triangle <<<")
        Console.Write(vbLf & " Enter the nth number of series: ")
        n = Convert.ToInt32(Console.ReadLine()) 'taking input, converting to Int
        For i = 1 To n

            For k = 1 To i
                Console.Write("{0} ", k)
            Next

            Console.Write(vbLf)
        Next

        Console.ReadLine()
    End Sub


End Module

Sample output Screen :



Bulk Email Sending Software - Free Download

I have developed a simple Bulk Email sending software a long ago. I just wanted to share this software so that anyone may find it useful.
It supports both Text mails and Html mails. So you can also send attractive html emails using this software.

You can use this tool to send emails to all your contacts within few clicks. It may be a invitation to your friends and relatives  or a welcome mail or greetings to your clients etc,. It uses smtp to send mails.

Please do not misuse this software to send spam content. You cannot send unlimited mails using this software.

Below are the screenshots of the software.

ScreenShot 1:


ScreenShot 2:



How it works :

-> select your Email Service provider, if not found in dropdown, then select other
-> Enter your email credentials.
-> Click on Test Connection, if test connection successful, it means all the credentials are correct and you
    can proceed to send emails.
-> Select MS Excel file in which your contacts emails addresses are saved. The emails should be saved in A     column  of excel sheet as shown in figure below.
 

-> Enter Email Subject.
-> If you want to send text email, you can enter/paste your text in the available textbox (screenshot1).
-> Or else you can paste your HTML code in the textbox and check Html-Mail checkbox to send Html 
     mails (screenshot1).
-> If you have HTML saved in some .hmtl / .htm file , you can browse for the file as shown in screenshot2.
-> If you want to have some media in your html email  to make it more attractive, in image tags you should 
     put the links of images available on internet.
-> Click on Send Emails





Download BulkEmail Sending Software