Posts tagged 'c'

C# GridView Sorting/Paging w/o a DataSourceControl DataSource

If you set AllowPaging="true" or AllowSorting="true" on a GridView control without using a DataSourceControl DataSource (i.e. SqlDataSource, ObjectDataSource), you will run into the following errors: When changing the page on the GridView control: The GridView 'GridViewID' fired event...

Continue reading "C# GridView Sorting/Paging w/o a DataSourceControl DataSource"

Strong Coders Generic Data Access Library

Until recently, I was using a modified version of the below code that was SQL Server-based for light weight data access. I've since introduced .NET generics to make it database independent. The below code is perfect for smaller projects where a component such as Enterprise Library or IBatis might be...

Continue reading "Strong Coders Generic Data Access Library"

Implicit and Explicit Operators in C#

For a side project I'm working on, explicit operators have come in handy in the data layer. With explicit operators, you can convert from one class to another using a user-defined conversion operator. For example: public class MyClass { private int _id; private string _description; public int ID...

Continue reading "Implicit and Explicit Operators in C#"

Accessing Config File Mail Settings Programmatically

Some people may not know that .NET 2.0 provides APIs for accessing everything in a configuration file. The most common question I see relates to accessing the mail settings in the system.net node programmatically. C# using System.Configuration; using System.Web.Configuration; using System.Net.Configuration;...

Continue reading "Accessing Config File Mail Settings Programmatically"

Sending an email using System.Net.Mail

Below is a C# and VB.NET class that demonstrates using System.Net.Mail to send an email. Download C# System.Net.Mail Helper Download VB.NET System.Net.Mail Helper Calling the function from code MailHelper .SendMailMessage( "fromAddress@yourdomain.com" , "toAddress@yourdomain.com"...

Continue reading "Sending an email using System.Net.Mail"

Replacing all instances of UTC time in a string

I'm in the progress of upgrading a web application from .NET 1.1 to 2.0 and came across this function that I created which replaces all instances of date/time in a string. In the application users add notes and when it gets saved to the database it appends Added By [User] on [Date/Time] to the end...

Continue reading "Replacing all instances of UTC time in a string"

Creating a List of a custom class

Let's say for instance, you want to create a List of your own class, say Employee, where Employee represents an employee. First, we'll start by creating an employee class. [ Serializable ] public class Employee { private bool m_IsSalaried; private int m_Age; private string m_Email; private string m_Name;...

Continue reading "Creating a List of a custom class"

Nullable Types

One of the weirder features in C# 2.0 is nullable types. My thinking is as follows: Why complicate things with Nullable<T>, or its shorter version of DataType? (i.e. int?), instead of allowing null values to be assigned to those data types that don't have any way of handling null? Maybe it was...

Continue reading "Nullable Types"

HttpContext Helper

Need to access an HttpContext object in a class, but can't because the class doesn't inherit System.Web.UI.Page? Here is a simple helper class that will allow you to access some of the most common HttpContext objects. C# using System; using System.Web; using System.Web.Caching; using System.Web.SessionState;...

Continue reading "HttpContext Helper"

Common DropDownList Issue

A common DropDownList issue I've seen on many forums and lists is about a DropDownList populating items 2x or not being able to get the selected value on postback when binding to a data source. This is due to the DropDownList having data bound to it again on postback before the form is processed. To...

Continue reading "Common DropDownList Issue"

Why is it a bad idea to use C# pointers?

I just answered a post on one of the lists I am a member of that asked how to use pointers in C#. Using pointers in C# is a very bad idea. Pointers reference a location in memory. If the garbage collector is called, the location of an object in memory could be moved and the end result is obvious. As...

Continue reading "Why is it a bad idea to use C# pointers?"

Using Statement Article

Here is my latest article in which I discuss the use of the using statement in C# and VB.NET.

Using Statement Article

R

Starwars Meet Yoda

Earlier I posted about C# Version 3.0 . I found this blog entry on C# 4.0 (codenamed Yoda) - http://blogs.msdn.com/mattwar/archive/2005/10/09/479008.aspx . R...

Continue reading "Starwars Meet Yoda"

What's wrong with Eval()?

The .NET Framwork 2.0 introduces Eval() . Eval() is a shortcut for Container.DataItem() . Since Eval() uses Reflection, it causes overhead. From a optimization standpoint, it is better to use Container.DataItem() . VB.NET Container.DataItem() C# DataReader: ((System.Data.Common.DbDataRecord)Container...

Continue reading "What's wrong with Eval()?"

C# Version 3.0 Specifications

Have you ever wondered what the next version of C# (3.0) has to offer? Microsoft has published the specifications and they can be downloaded at http://tinyurl.com/baoh8.

R