ASP.NET GridView Sorting AllowSorting

aspnet Last update 2007-11-13 No Comments »

GridView sorting is actually all about binding grid with a source and setting its AllowSorting.

Lets first write our dataobject class.

If not created already, create your App_Code folder and add the class below.
Then drag drop a ObjectDataSource and GridView to your form.

using System;using System.Data;using System.IO;public class MyFiles

{

public MyFiles()

{

}

public DataTable ReadFiles(string thefolder)

{

DirectoryInfo dr = new DirectoryInfo(thefolder);

System.IO.FileInfo[] dosyalar;

dosyalar = dr.GetFiles("*.*");

DataTable dtdosyalar = new DataTable();

DataColumn dcAdi = new DataColumn("Dosya Ad?");

DataColumn dcBoyutu = new DataColumn("Dosya Boyutu");

DataColumn dcTarihi = new DataColumn("Olu?turulma Tarihi");

DataColumn dcSonErisim = new DataColumn("Son Eri?im Tarihi");

dtdosyalar.Columns.Add(dcAdi);

dtdosyalar.Columns.Add(dcBoyutu);

dtdosyalar.Columns.Add(dcTarihi);

dtdosyalar.Columns.Add(dcSonErisim);

for (int i = 0; i < dosyalar.Length; i++)

{

DataRow drr = dtdosyalar.NewRow();

drr["Dosya Ad?"] = dosyalar[i].Name;

drr["Dosya Boyutu"] = dosyalar[i].Length.ToString();

drr["Olu?turulma Tarihi"] = dosyalar[i].CreationTime.ToShortDateString();

drr["Son Eri?im Tarihi"] = dosyalar[i].LastAccessTimeUtc.ToShortDateString();

dtdosyalar.Rows.Add(drr);

}

return dtdosyalar;

}

}

Then in your aspx design set grid AllowSorting property true.

        <asp:gridview id="GridView1" runat="server" allowsorting="True"

datasourceid="ObjectDataSource1"></asp:gridview></pre>

As you see in the code, we set the TypeName property of ObjectDataSource as MyFiles and its SelectMethod as ReadFiles. That is in our App_Code class.

Also we set DataSourceID of GridView as our ObjectDataSource1. Then all you will do is binding the grid.

 if (!IsPostBack)        {GridView1.DataBind();

}

ASP.NET web.config MS Access Connection String

.NET Last update 2007-09-07 No Comments »

It is more secure that reading the connection string from web.config file in ASP.NET web site.

Simple web.config file can be as follows;

<?xml version="1.0"?>

<!-- Web.Config Configuration File -->

<configuration>

<system.web>

 	<customErrors mode="Off"/>

 	<compilation debug="true"/>

  </system.web>>

<appSettings>

    <add key="ConnStrng"

      value="Data Source=|DataDirectory|yourdbfile.mdb;provider=Microsoft.Jet.OLEDB.4.0" />

  </appSettings>

</configuration>

We add a key named Connection String and set its value to our connection string.

How to read the connection string from code;

public static string ReadConStr()
{
 string constr = "";
 constr = System.Configuration.ConfigurationManager.AppSettings["ConnStrng"];

 return constr ;
}

C# System Tray Minimize To Tray With NotifyIcon

.NET Last update 2007-08-31 8 Comments »

Minimize application form to system tray is done with the NotifyIcon control in Visual Studio.
NotifyIcon is in the System.Windows.Forms namespace.

Drag and drop a NotifyIcon control to your form.
To send your application form into the system tray, we simple handle the form re-size event.

private void frmMain_Resize(object sender, EventArgs e)
{
    if (FormWindowState.Minimized == this.WindowState)
            {
                mynotifyicon.Visible = true;
                mynotifyicon.ShowBalloonTip(500);
                this.Hide();
            }
            else if (FormWindowState.Normal == this.WindowState)
            {
                mynotifyicon.Visible = false;
            }

 }

We can also set BallonTipIcon, BallonTipText, BallonTipTitle and Icon , for our NotifyIcon control.

mynotifyicon.BallonTipText = "My application still working...";
mynotifyicon.BallonTipTitle = "My Sample Application";
mynotifyicon.BallonTipIcon = ToolTipIcon.Info;

C# and ASP.NET Create Table Dynamically

.NET Last update 2007-08-22 5 Comments »

In the run-time sometimes we have to create table dynamically.
From the namespace System.Data DataTable DataColumn classes we can easily create table dynamically in C# and also in ASP.NET.

using System.Data;// Create a DataTable instance

DataTable dTbl = new DataTable("myDynamicTable");

// Create a DataColumn instances

DataColumn dValue = new DataColumn();
DataColumn dMember = new DataColumn();

dValue.ColumnName = "Id";
dValue.DataType = Type.GetType("System.Int32");

dMember.ColumnName = "Name";
dMember.DataType = Type.GetType("System.String");

// Add these DataColumns into the DataTable

dTbl.Columns.Add(dValue);
dTbl.Columns.Add(dMember);

After you create table dynamically, you can add rows into it.
It is a good way to create DataRow from the table we create, with the function NewRow().

// Create a DataRow Instance from the table we create above, with NewRow();

DataRow myrow = dTbl.NewRow();

myrow["Id"] = 1;
myrow["Name"] = "Tux";

// Add the row into the table

dTbl.Rows.Add(myrow);

That’s all for creating table dynamically in C# and also ASP.NET.

C# WMI ManagementClass ManagementObject Win32_LogicalDisk Disk Serial Number and Volume Name

.NET Last update 2007-08-10 No Comments »

Using C# WMI ManagementClass and ManagementObject with the Win32_LogicalDisk query
Disk informations can be read, Serial Number Volume Name, Name, Free Space, File System.
Check out the C# code below.

using System.Management;

using System.Management.Instrumentation;ManagementClass mangnmt = new ManagementClass("Win32_LogicalDisk");

ManagementObjectCollection mcol = mangnmt.GetInstances();

string result = "";

foreach (ManagementObject strt in mcol)

{

result += "Name                 : " + Convert.ToString(strt["Name"]) + Environment.NewLine;

result += "VolumeName           : " + Convert.ToString(strt["VolumeName"]) + Environment.NewLine;

result += "FileSystem           : " + Convert.ToString(strt["FileSystem"]) + Environment.NewLine;

result += "Size                 : " + Convert.ToString(strt["Size"]) + Environment.NewLine;

result += "FreeSpace            : " + Convert.ToString(strt["FreeSpace"]) + Environment.NewLine;

result += "Description          : " + Convert.ToString(strt["Description"]) + Environment.NewLine;

result += "VolumeSerialNumber   : " + Convert.ToString(strt["VolumeSerialNumber"]) + Environment.NewLine;

result += Environment.NewLine;

}

textBox1.Text = result;

And this will result in my computer as follows;

Name                 : A:
VolumeName           :

FileSystem           :

Size                 :

FreeSpace            :

Description          : 3 1/2 Inch Floppy Drive

VolumeSerialNumber   :

Name                 : C:

VolumeName           :

FileSystem           : NTFS

Size                 : 52534829056

FreeSpace            : 44959264768

Description          : Local Fixed Disk

VolumeSerialNumber   : D06A9EE0

Name                 : D:

VolumeName           : depo

FileSystem           : NTFS

Size                 : 180355678208

FreeSpace            : 32619413504

Description          : Local Fixed Disk

VolumeSerialNumber   : 581E6CBE

Name                 : E:

VolumeName           : temp

FileSystem           : NTFS

Size                 : 17157898240

FreeSpace            : 17089097728

Description          : Local Fixed Disk

VolumeSerialNumber   : 7424915D

Name                 : F:

VolumeName           : 

FileSystem           : CDFS

Size                 : 1449984

FreeSpace            : 0

Description          : CD-ROM Disc

VolumeSerialNumber   : 8E4F294A

c# managementclass
c# managementobject
managementobjectsearcher
c# managementscope
c# win32_logicaldisk

are used in the c# wmi sample code.

MS Access How To Set Database Password Tutorial

.NET Last update 2007-08-10 No Comments »

MS Access database files has to be published with the application,
so to set up database password is required to protect your data.
Also you may encrypt the data in the Access database but one still open
you access mdb file and change its values etc.It is very easy to set up a database password in MS Access.

  • Open MS Access without double-clicking on your mbd file, just open it from the start menu.
  • Click File->Open
  • There is down arrow next to the open button, click on it and select open exclusive.

To set up a password, you have to open the mdb file with open exclusive. See the image below.

MS Access Open Exclusive

  • Then click open in the form shown below.
  • MS Access Open Database
  • Click Tools->Security->Set Database Password.

MS Access Set Database Password

  • Type your password as you desired.
  • MS Access Set Database Password
  • Save and exit.

That’s all (:

C# Access Connection String OLE DB OleDbConnection

.NET Last update 2007-08-09 2 Comments »

The Connection String for MS Access can be set as ;

private constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=yourdbfile.mdb;Jet OLEDB:Database Password=yourpassword;";

And the C# code to connect to MS Access database ;

public bool OpenConnection()
{
OleDbConnection con;
con = new OleDbConnection(constr);

if (con.State != ConnectionState.Open)
{
  try
     {
         con.Open();
         return true;
      }
  catch (Exception)
     {
       return false;
     }
}

else
    return false;
      }

C# Access Connection String OLE DB OleDbConnection password field is the password you set up in access database.

Meaning of De parvis grandis acervus erit

Google Tips and Tricks Last update 2007-08-08 No Comments »

When you open the Google toolbar about box, you may see this text there.

De parvis grandis acervus erit.

After I googling, I found several possible meanings;

  • Out of small things a great heap will be formed.
  • Little by little there’s so much done.
  • Tall oaks from little acorns grow.
  • Small things will make a large pile. 

I really love this quote, I think it summarize the Google great services clearly, their passion and simplicity beyond the great work and service.

Please let me know if this translations are incorrect or any other suggestions.

Html Special Characters

HTML Tags Last update 2007-08-08 No Comments »

ISO-8859-1 Html special characters commonly used.

If you want to add one of the char below, in your html codes, add the Entity equivalent of the desired symbol from the table below.

Decimal Symbol Description Entity
&#34; Quotation mark &quot;
&#38; & Ampersand &amp;
&#60; < Less than &lt;
&#62; > Greater than &gt;
&#160; Non-breaking space &nbsp;
&#192; À Capital A, grave accent &Agrave;
&#224; à Small a, grave accent &agrave;
&#193; Á Capital A, acute accent &Aacute;
&#225; á Small a, acute accent &aacute;
&#194; Â Capital A, circumflex accent &Acirc;
&#226; â Small a, circumflex accent &acirc;
&#195; Ã Capital A, tilde &Atilde;
&#227; ã Small a, tilde &atilde;
&#196; Ä Capital A, dieresis or umlaut mark &Auml;
&#228; ä Small a, dieresis or umlaut mark &auml;
&#197; Å Capital A, ring &Aring;
&#229; å Small a, ring &aring;
&#198; Æ Capital AE dipthong (ligature) &AElig;
&#230; æ Small ae dipthong (ligature) &aelig;
&#199; Ç Capital C, cedilla &Ccedil;
&#231; ç Small c, cedilla &ccedil;
&#208; Capital Eth, Icelandic &ETH;
&#240; Small eth, Icelandic &eth;
&#200; È Capital E, grave accent &Egrave;
&#232; è Small e, grave accent &egrave;
&#201; É Capital E, acute accent &Eacute;
&#233; é Small e, acute accent &eacute;
&#202; Ê Capital E, circumflex accent &Ecirc;
&#234; ê Small e, circumflex accent &ecirc;
&#203; Ë Capital E, dieresis or umlaut mark &Euml;
&#235; ë Small e, dieresis or umlaut mark &euml;
&#204; Ì Capital I, grave accent &Igrave;
&#236; ì Small i, grave accent &igrave;
&#205; Í Capital I, acute accent &Iacute;
&#237; í Small i, acute accent &iacute
&#206; Î Capital I, circumflex accent &Icirc;
&#238; î Small i, circumflex accent &icirc;
&#207; Ï Capital I, dieresis or umlaut mark &Iuml;
&#239; ï Small i, dieresis or umlaut mark &iuml;
&#181; µ Micro sign &micro;
&#209; Ñ Capital N, tilde &Ntilde;
&#241; ñ Small n, tilde &ntilde;
&#210; Ò Capital O, grave accent &Ograve;
&#242; ò Small o, grave accent &ograve;
&#211; Ó Capital O, acute accent &Oacute;
&#243; ó Small o, acute accent &oacute;
&#212; Ô Capital O, circumflex accent &Ocirc;
&#244; ô Small o, circumflex accent &ocirc;
&#213; Õ Capital O, tilde &Otilde;
&#245; õ Small o, tilde &otilde;
&#214; Ö Capital O, dieresis or umlaut mark &Ouml;
&#246; ö Small o, dieresis or umlaut mark &ouml;
&#216; Ø Capital O, slash &Oslash;
&#248; ø Small o, slash &oslash;
&#223; ß Small sharp s, German (sz ligature) &szlig;
&#222; Capital THORN, Icelandic &THORN;
&#254; Small thorn, Icelandic &thorn;
&#217; Ù Capital U, grave accent &Ugrave;
&#249; ù Small u, grave accent &ugrave;
&#218; Ú Capital U, acute accent &Uacute;
&#250; ú Small u, acute accent &uacute;
&#219; Û Capital U, circumflex accent &Ucirc;
&#251; û Small u, circumflex accent &ucirc;
&#220; Ü Capital U, dieresis or umlaut mark &Uuml;
&#252; ü Small u, dieresis or umlaut mark &uuml;
&#221; Capital Y, acute accent &Yacute;
&#253; Small y, acute accent &yacute;
&#255; ÿ Small y, dieresis or umlaut mark &yuml;
&#168; ¨ Umlaut &uml;
&#175; ¯ Macron accent &macr;
&#180; ´ Acute accent &acute;
&#184; ¸ Cedilla &cedil;
&#161; ¡ Inverted exclamation &iexcl;
&#191; ¿ Inverted question mark &iquest;
&#183; · Middle dot &middot;
&#166; Broken vertical bar &brvbar;
&#171; « Left angle quote &laquo;
&#187; » Right angle quote &raquo;
&#182; Paragraph sign &para;
&#167; § Section sign &sect;
&#169; © Copyright &copy;
&#174; ® Registered trademark &reg;
&#185; Superscript one &sup1;
&#178; Superscript two &sup2;
&#179; Superscript three &sup3;
&#173; ­ Soft hyphen &shy;
&#215; Multiply sign &times;
&#247; ÷ Division sign &divide;
&#188; Fraction one-fourth &frac14;
&#189; Fraction one-half &frac12;
&#190; Fraction three-fourths &frac34;
&#170; ª Feminine ordinal &ordf;
&#186; º Masculine ordinal &ordm;
&#172; ¬ Not sign &not;
&#176; ° Degree sign &deg;
&#177; ± Plus or minus &plusmn;
&#164; ¤ General currency sign &curren;
&#162; ¢ Cent sign &cent;
&#163; £ Pound sterling &pound;
&#165; ¥ Yen sign &yen;

Html Special Characters

How To Add Favicon and Create Favicon Online

HTML Tags Last update 2007-08-08 No Comments »

favicon Favicons are the little images, icons that appears in left of the browser address bar and bookmarks menu.

Favicon size is 16×16 pixel.

Favicons are very important feature, visitors may remember a website from its favicon.

Favicon is kind a symbol of a website.

How to add a favicon in your website html.

  • Create a favicon online easily visit the link below and create your favicon online.

FavIcon Generator Online

  • Upload your favicon into your hosting site.
  • Add the html tag below into your website, between head tags.
<link href="images/favicon.ico" rel="shortcut icon" />

Done.

Powered by Wordpress WP Theme and Icons by N.Design Studio
Entries RSS Comments RSS Login
Close
E-mail It