Print Selected Columns Using Checkbox in a ASP.Net Gridview control


Print Selected Columns Using Checkbox in a ASP.Net Gridview control
//ASP :
<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

 <script language="JavaScript">

/*you can hide columns */

     function hideColumn() {

         col_num = document.getElementById("column_numbder").value;

         var col_nums = col_num.split(","); /*you can hide columns via ','*/

         rows = document.getElementById("GridView1").rows;

         for (m = 0; m < col_nums.length;m++)

         {

             col = col_nums[m];

           for (i = 0; i < rows.length; i++) {

              rows[i].cells[col].style.display = "none";

            }

         }

     }

 </script>



 <title>Untitled Page</title>

</head>

<body>

 <form id="form1" runat="server">

     <div>

         <asp:GridView ID="GridView1" runat="server">

         </asp:GridView>

     </div>

     <input id="column_numbder" type="text">

     <input type="button" value="Hide" onclick="hideColumn()">

 </form>

</body>

</html>




C#:

protected void Page_Load(object sender, EventArgs e)

        {

            if (!IsPostBack)

            {

                if (Session["strTemp"] != null)

                {

                    GridView1.DataSource = Session["strTemp"] as DataTable;

                    GridView1.DataBind();

                }

                else

                {

                    GridView1.DataSource = GetCustomMadeDataTable();

                    GridView1.DataBind();

                }

            }

        }

        public DataTable GetCustomMadeDataTable()

        {

            //Create a new DataTable object

            System.Data.DataTable objDataTable = new System.Data.DataTable();

            //Create three columns with string as their type

            objDataTable.Columns.Add("Id", typeof(string));

            objDataTable.Columns.Add("Column1", typeof(string));

            objDataTable.Columns.Add("Column2", typeof(string));

            objDataTable.Columns.Add("Column3", typeof(string));

            //Adding some data in the rows of this DataTable

            DataRow dr;

            for (int i = 0; i <= 20; i++)

            {

                dr = objDataTable.NewRow();

                dr[0] = i.ToString();

                dr[1] = "Column1Data" + i.ToString();

                dr[2] = "Column2Data" + i.ToString();

                dr[3] = "Column3Data" + i.ToString();

                objDataTable.Rows.Add(dr);

            } DataColumn[] dcPk = new DataColumn[1];

            dcPk[0] = objDataTable.Columns["Id"];

            objDataTable.PrimaryKey = dcPk;

            Session["strTemp"] = objDataTable;

            return objDataTable;

        }
By Drupal Study
Monday, April 14, 2014
Tag :

counting occurrence of letters in C# program

counting occurrence of letters in C# program
 
class solution_main
    {
        static void Main(string[] args)
        {
            string inPutString = "CodeProject Quick Answers";
            char letterToBeChecked = 'e';
            var result = GetLetterOccurence(inPutString, letterToBeChecked);
            Console.WriteLine(" The occurence of letter '{0}' from the string {1} is {2}", 
                letterToBeChecked, 
                inPutString, 
                result);
            Console.WriteLine("\nPress any key to exit");
            Console.ReadLine();
        }
 
        /// <summary>
        /// Get the number of occurence of letter
        /// </summary>
        /// <param name="inPutString">InputString value</param>
        /// <param name="letterToBeChecked">LetterToBeChecked value</param>
        /// <returns></returns>
        private static int GetLetterOccurence(string inPutString, char letterToBeChecked)
        {
            char[] chars = inPutString.ToArray();  // Get the Characters(letters) from string

            var result = (from c in chars
                          where c.Equals(letterToBeChecked)
                          select c).Count();
            return result;
        }
    }
By Drupal Study
Tag :

Removing bad Characters in Windows Filenames using C#

 hi everyone, how are you ?
Removing characters in Windows filenames using C#

i hope that all your works going fine..
so, i want to share a little c# fonctions with you in this post :)
in the fact there are no exist method do that (as i know :D )

bu we will do that very simple with a regex:
//c# code:
Regex illegalInFileName = new Regex(@"[\\/:*?""<>|]");
string myString = illegalInFileName.Replace(myString, "");

or:

 private Regex illegalInFileName = new Regex(string.Format("[{0}]", Regex.Escape(new string(Path.GetInvalidFileNameChars()))), RegexOptions.Compiled);
 ...
 string myString = @"A\\B/C:D?E*F""G<H>I|";
 myString = illegalInFileName.Replace(myString, "");

good look :)
By Drupal Study
Tag :

Follow By Email

About Me

My name is Abdennacer
I'm a Software Programmer and Web developer from morocco.
At morning, peoples sipping a cup of tea, but i like drinking a certain software codes with eating some new informations and then complete my...

Read More>>

Contact Me

Name

Email *

Message *

@All rights reserved Copy | © .:* Drupal Study *:.