aspnet Last update 2007-11-13
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();
}
Share This
.NET Last update 2007-09-07
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 ;
}
Share This
.NET Last update 2007-08-31
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;
Share This
.NET Last update 2007-08-22
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.
Share This
.NET Last update 2007-08-10
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.
Share This
.NET Last update 2007-08-10
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.
- 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.

- Then click open in the form shown below.

- Click Tools->Security->Set Database Password.

- Type your password as you desired.

- Save and exit.
That’s all (:
Share This
.NET Last update 2007-08-09
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.
Share This
Google Tips and Tricks Last update 2007-08-08
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.
Share This
HTML Tags Last update 2007-08-08
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 |
| " |
“ |
Quotation mark |
" |
| & |
& |
Ampersand |
& |
| < |
< |
Less than |
< |
| > |
> |
Greater than |
> |
|   |
|
Non-breaking space |
|
| À |
À |
Capital A, grave accent |
À |
| à |
à |
Small a, grave accent |
à |
| Á |
Á |
Capital A, acute accent |
Á |
| á |
á |
Small a, acute accent |
á |
| Â |
 |
Capital A, circumflex accent |
 |
| â |
â |
Small a, circumflex accent |
â |
| Ã |
à |
Capital A, tilde |
à |
| ã |
ã |
Small a, tilde |
ã |
| Ä |
Ä |
Capital A, dieresis or umlaut mark |
Ä |
| ä |
ä |
Small a, dieresis or umlaut mark |
ä |
| Å |
Å |
Capital A, ring |
Å |
| å |
å |
Small a, ring |
å |
| Æ |
Æ |
Capital AE dipthong (ligature) |
Æ |
| æ |
æ |
Small ae dipthong (ligature) |
æ |
| Ç |
Ç |
Capital C, cedilla |
Ç |
| ç |
ç |
Small c, cedilla |
ç |
| Ð |
|
Capital Eth, Icelandic |
Ð |
| ð |
|
Small eth, Icelandic |
ð |
| È |
È |
Capital E, grave accent |
È |
| è |
è |
Small e, grave accent |
è |
| É |
É |
Capital E, acute accent |
É |
| é |
é |
Small e, acute accent |
é |
| Ê |
Ê |
Capital E, circumflex accent |
Ê |
| ê |
ê |
Small e, circumflex accent |
ê |
| Ë |
Ë |
Capital E, dieresis or umlaut mark |
Ë |
| ë |
ë |
Small e, dieresis or umlaut mark |
ë |
| Ì |
Ì |
Capital I, grave accent |
Ì |
| ì |
ì |
Small i, grave accent |
ì |
| Í |
Í |
Capital I, acute accent |
Í |
| í |
í |
Small i, acute accent |
í |
| Î |
Î |
Capital I, circumflex accent |
Î |
| î |
î |
Small i, circumflex accent |
î |
| Ï |
Ï |
Capital I, dieresis or umlaut mark |
Ï |
| ï |
ï |
Small i, dieresis or umlaut mark |
ï |
| µ |
µ |
Micro sign |
µ |
| Ñ |
Ñ |
Capital N, tilde |
Ñ |
| ñ |
ñ |
Small n, tilde |
ñ |
| Ò |
Ò |
Capital O, grave accent |
Ò |
| ò |
ò |
Small o, grave accent |
ò |
| Ó |
Ó |
Capital O, acute accent |
Ó |
| ó |
ó |
Small o, acute accent |
ó |
| Ô |
Ô |
Capital O, circumflex accent |
Ô |
| ô |
ô |
Small o, circumflex accent |
ô |
| Õ |
Õ |
Capital O, tilde |
Õ |
| õ |
õ |
Small o, tilde |
õ |
| Ö |
Ö |
Capital O, dieresis or umlaut mark |
Ö |
| ö |
ö |
Small o, dieresis or umlaut mark |
ö |
| Ø |
Ø |
Capital O, slash |
Ø |
| ø |
ø |
Small o, slash |
ø |
| ß |
ß |
Small sharp s, German (sz ligature) |
ß |
| Þ |
|
Capital THORN, Icelandic |
Þ |
| þ |
|
Small thorn, Icelandic |
þ |
| Ù |
Ù |
Capital U, grave accent |
Ù |
| ù |
ù |
Small u, grave accent |
ù |
| Ú |
Ú |
Capital U, acute accent |
Ú |
| ú |
ú |
Small u, acute accent |
ú |
| Û |
Û |
Capital U, circumflex accent |
Û |
| û |
û |
Small u, circumflex accent |
û |
| Ü |
Ü |
Capital U, dieresis or umlaut mark |
Ü |
| ü |
ü |
Small u, dieresis or umlaut mark |
ü |
| Ý |
|
Capital Y, acute accent |
Ý |
| ý |
|
Small y, acute accent |
ý |
| ÿ |
ÿ |
Small y, dieresis or umlaut mark |
ÿ |
| ¨ |
¨ |
Umlaut |
¨ |
| ¯ |
¯ |
Macron accent |
¯ |
| ´ |
´ |
Acute accent |
´ |
| ¸ |
¸ |
Cedilla |
¸ |
| ¡ |
¡ |
Inverted exclamation |
¡ |
| ¿ |
¿ |
Inverted question mark |
¿ |
| · |
· |
Middle dot |
· |
| ¦ |
|
Broken vertical bar |
¦ |
| « |
« |
Left angle quote |
« |
| » |
» |
Right angle quote |
» |
| ¶ |
¶ |
Paragraph sign |
¶ |
| § |
§ |
Section sign |
§ |
| © |
© |
Copyright |
© |
| ® |
® |
Registered trademark |
® |
| ¹ |
|
Superscript one |
¹ |
| ² |
|
Superscript two |
² |
| ³ |
|
Superscript three |
³ |
| ­ |
|
Soft hyphen |
­ |
| × |
|
Multiply sign |
× |
| ÷ |
÷ |
Division sign |
÷ |
| ¼ |
|
Fraction one-fourth |
¼ |
| ½ |
|
Fraction one-half |
½ |
| ¾ |
|
Fraction three-fourths |
¾ |
| ª |
ª |
Feminine ordinal |
ª |
| º |
º |
Masculine ordinal |
º |
| ¬ |
¬ |
Not sign |
¬ |
| ° |
° |
Degree sign |
° |
| ± |
± |
Plus or minus |
± |
| ¤ |
¤ |
General currency sign |
¤ |
| ¢ |
¢ |
Cent sign |
¢ |
| £ |
£ |
Pound sterling |
£ |
| ¥ |
¥ |
Yen sign |
¥ |
Html Special Characters
Share This
HTML Tags Last update 2007-08-08
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.
Share This
Recent Comments