Compdigitec Labs

ASP.NET GridView All-In-One Quick Reference

By admin | July 17, 2010

Here is a quick collection of snippets where one can quickly lookup the necessities of setting up a GridView for the purposes of displaying information to the viewer through a database (for example, MySQL):

Adding Columns of Data

DataTable dt = new DataTable("Tablename");
dt.Columns.Add("Column1");
dt.Columns.Add("Column2");
dt.Columns.Add("Column3");
// for every row
DataRow dr = dt.NewRow();
dr["Column1"] = "Testing";
dr["Column2"] = "Blah";
dr["Column3"] = "Big Blah";
dt.Rows.Add(dr);

Binding the Data (and storage across sessions)

DataView dv = new DataView(dt);
Session["data"] = dv;
gridviewctrl.DataSource = dv;
gridviewctrl.DataBind();

Paging
Note: This needs AllowPaging to be set to “true”. The following code goes in the “PageIndexChanging” callback.

gridviewctrl.PageIndex = e.NewPageIndex;
gridviewctrl.DataSource = Session["data"];
gridviewctrl.DataBind();

Sorting
Note: This needs AllowSorting to be set to “true” and ensure all columns you want sorted have a “SortExpression” that matches the column name in the DataTable. The following code goes in the “Sorting” callback.

string dir;
if (e.SortDirection == SortDirection.Ascending) {
    dir = "ASC";
} else {
    dir = "DESC";
}
((DataView)Session["Data"]).Sort = e.SortExpression + " " + dir;
gridviewctrl.DataSource = Session["data"];
gridviewctrl.DataBind();

<asp:ButtonField>s
Create a <asp:ButtonField> declaration as follows: <asp:ButtonField ButtonType=”Button” Text=”Button Text Here” CommandName=”DoSomething” />

if (e.CommandName == "DoSomething") {
    // get Index
    int index = Convert.ToInt32(e.CommandArgument);
    string test = ((DataView)Session["Data"]).Table.Rows[index]["Column1"];
    Response.Redirect("http://www.google.com/search?q=" + test.ToString()");
}

Topics: HTTP (Internet), Windows | No Comments »

Solving Could not find stored procedure dbo.aspnet_CheckSchemaVersion in ASP.NET Membership

By admin | July 13, 2010

Normally, as usual, one would not see the error Could not find stored procedure ‘dbo.aspnet_CheckSchemaVersion’ if one has a good database already setup with everything good to go. However, sometime the annoying error Could not find stored procedure ‘dbo.aspnet_CheckSchemaVersion’ crops up one can check the steps below to determine the root cause of the error:

  1. Try to recreate the Memberships database (ASPNETDB) - it may be corrupt or inaccessible:
    C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regsql -S . -E -A mrpc
  2. If that does not resolve the problem for you, the you should check in your web.config file to see if added “Initial Catalog=aspnetdb” somewhere in your web.config file like this:
    Data source=.;Integrated Security=True;Initial Catalog=aspnetdb
  3. Restart IIS.

Topics: Windows | 3 Comments »

Solving Handler “PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in ASP.NET 4.0

By admin | July 12, 2010

If you have just installed Visual Studio 2010 or the .NET 4.0 Framework and trying to host ASP.Net 4.0 applications doesn’t work for you and results in the following error message:

Handler “PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler”

It means that you haven not yet run the aspnet_iisreg.exe executable needed to register the ASP.NET 4 framework with the IIS 7 webserver. In order to do so, open a command prompt and type in the following:

C:\windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i

Substitute v4.0.30319 for what other past or future ASP.NET versions. To uninstall the ASP.NET 4 (e.g. for when you are done playing around with it and would like to do some work):

c:\windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -u

Topics: Windows | 8 Comments »

Solving “The name … does not exist in the current context” in ASP.NET

By admin | July 7, 2010

A little-known fact is that in ASP.NET is that you cannot have two copies of the same ASP.NET web page in the same folder, or it will attempt to load elements (such as controls) from the (usually) wrong page, and end up confusing itself, resulting in the error “The name … does not exist in the current context”. This can be very confusing as you try to figure out why it is not working even though it looks like you are doing it correctly.

To resolve this, make sure there are no copies of the page in the same folder (such as things like backup files, accidental copies, etc) in the same folder. Either move them to a different folder or rename their extensions: .aspx to .aspxold and .cs to .csold.

Topics: HTTP (Internet), Windows | No Comments »

How to add entries by UUID to /etc/fstab

By admin | June 30, 2010

Normally in Linux, one would be able to add entries to the /etc/fstab file by using the standard /dev/xdx notation. However, what happens when we add or remove some partitions and hard disks? In this case, it would completely throw off the entries resulting in you not being able to access your partition. As a result, it is also possible to mount using UUID (Universally Unique Identifier)s. This way you will still be able to access your partitions even if they are shuffled around.

To get the UUID of a partition:

blkid /dev/<em>xxxx</em> -s UUID

and it will output something like this:

/dev/<em>xxxx</em>: UUID="1fa6e8df-f05a-4c7c-b30a-cd3c1b2bcebd"

and then you can use the UUID to add a line in /etc/fstab:

UUID=1fa6e8df-f05a-4c7c-b30a-cd3c1b2bcebd	/media/mountpoint	ext4	defaults	0	1

Topics: Linux | No Comments »

Fixing “Write Error - the file could not be written” error in OpenOffice.org on Ubuntu

By admin | May 6, 2010

Write Error

Write Error


In OpenOffice.org on Ubuntu by default, the package openoffice.org-java-common is not installed. As a result, when you try to save using some filters in OpenOffice.org that require the Java Runtime, you may experience the error as a result. To fix, this install the package openoffice.org-java-common:

sudo apt-get install openoffice.org-java-common

This should fix the error, however you must restart OpenOffice.org for this to take effect.

Topics: Linux | 1 Comment »

XHTML-compliant way to embed Macromedia Flash

By admin | April 30, 2010

For many years, people have been using complicated, ugly ways to forcibly embed their Macromedia Flash content into their webpages. There have been several ways, usually using the non-standard <embed> element or other fancy IE-only <object> hacks. But now, we have a safe, bug-free, validator-safe way to embed Flash that passes the HTML 5 and XHTML 1.0 standards.

Presenting…

<object type="application/x-shockwave-flash" data="replace_this.swf" width="720" height="540">
    <param name="movie" value="replace_this.swf" />
</object>

Topics: (X)HTML | 1 Comment »

How to enable symlink following in Samba

By admin | March 30, 2010

After a recent samba update, it appears that the Samba team has decided to set their default for the “unix extensions” to yes after an update. Unfortunately, even though this means that Unix clients will now be able to create symlinks on smbfs-mounted file system, it still means that some Unix clients who wish to access where the symlink leads instead of the symlink itself. This also includes Windows clients, who have no idea of what a symlink is, and as a result error out with a “Access is denied” message. In order to access where the symlink resides one must disable “unix extensions” in smb.conf.

Open up a text editor:

sudo nano -w /etc/samba/smb.conf

and add the line:

unix extensions = no

right after the [general] section. Save by pressing Ctrl-O and then restart samba:

sudo /etc/init.d/samba restart

Symlink following should now work properly.

Topics: Linux | 2 Comments »

How to force a CD/DVD drive to eject in Linux

By admin | March 20, 2010

Usually, the CD drive in Linux is pretty permissive just like in Windows, where one can eject and insert discs at any time. However, sometimes some random bugs in various application show up when you eject a disk while reading, and the operating system no longer honours any requests to eject (e.g. pressing the eject button the physical drive) because the application is still waiting for the request to complete.

Normally, pressing the eject icon next to the drive in Nautilus would work and usually this command too:

eject

However, even that sometimes doesn’t work properly. Therefore, we need to use cdrecord to forcibly eject:

cdrecord -eject

This usually will cause the CD tray to eject. However it is recommended that you eject normally by using the eject command as forced ejects could create problems with programs.

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more interesting articles!

Topics: Linux | No Comments »

Paint.NET on Ubuntu Linux 9.10

By admin | March 18, 2010

Paint.NET on Ubuntu

Paint.NET on Ubuntu

Paint.NET is a very powerful yet simple to use raster graphics editor that used to be under the free MIT-license. Even though the author has now closed its sources we can always run an older version of it (3.0) since there are no effective major changes. There is already a porting in progress by Miguel de Icaza but there unfortunately was no compiled package that has been compiled yet. Here is a compiled binary if you wish to use it on Ubuntu for now without having to compile yourself. You still need Mono installed, of course.

Download

To run
Press Alt-F2 and type in:

paintdotnet

For convenience you may wish to to add a link in your applications menu for easy access.

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more interesting articles!

Topics: Linux | No Comments »

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles! « Older Entries Newer Entries »