Categories
ASP.NET

How to access the EmptyDataTemplate controls from OnRowCommand in GridView

For example – inserting value in the empty gridview: protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == “Insert”) { TextBox txt = (((Control)e.CommandSource).NamingContainer).FindControl(“txtTest”) as TextBox; //do insert action } } Another way to do this is by getting EmptyDataTemplate table and its controls: if (e.CommandName == “Insert”) { Table table = (Table)GridView1.Controls[0]; TextBox […]

Categories
ASP.NET VB.NET

Error while trying to run project: Unable to start debugging on the web server

Open your Internet Information Services manager and from the [your machine]/Web Sites/ Default Web Site node select the virtual folder which stores your project. Right Click and select Properties to select the ASP.NET tab page. Make sure the correct version ASP.NET Version is selected. I have VS.NET 2003 and 2005 beta 1 running side-by-side on […]

Categories
ASP.NET

Change datagrid cell properties using ASP.NET C#

public void dgBoundItems(object sender, DataGridItemEventArgs e) { foreach(TableCell cell in e.Item.Cells) { ///e.Item.DataSetIndex = row ///e.Item.Cells.GetCellIndex(cell) = column if (e.Item.Cells.GetCellIndex(cell) == 2 && e.Item.DataSetIndex > 0) { ///If the salary is less than 5000 the color must be red. if (Convert.ToInt32(cell.Text.Trim()) < 5000) { cell.ForeColor = Color.Red; } } } }

Categories
ASP.NET C# JavaScript VB.NET

Inline IF’ Statement

C# string s; s = (true ? “True” : “False”); //s will be “True” VB.NET Dim s As String s = If(True, “True”, “False”) ‘s will be “True” ‘In the following you cannot rely on a particular function ‘not being called if the other argument is selected by Expression ‘(notice IIf vs. If) s = […]

Categories
ASP.NET

DateTime Format String

DateTime now = new DateTime(2006, 9, 07, 15, 06, 01, 08, DateTimeKind.Local); now.ToString(); //”09/27/2006 15:06:01″ Year now.ToString(“%y”); //”6″ now.ToString(“yy”); //”06″ now.ToString(“yyy”); //”2006″ now.ToString(“yyyy”); //”2006″ Month now.ToString(“%M”); //”9″ now.ToString(“MM”); //”09″ now.ToString(“MMM”); //”Sep” now.ToString(“MMMM”); //”September” Day now.ToString(“%d”); //”7″ now.ToString(“dd”); //”07″ now.ToString(“ddd”); //”Thu” now.ToString(“dddd”); //”Thursday” Hour now.ToString(“%h”); //”3″ now.ToString(“hh”); //”03″ now.ToString(“hhh”); //”03″ now.ToString(“hhhh”); //”03″ now.ToString(“%H”); //”15″ now.ToString(“HH”); //”15″ […]

Categories
ASP.NET

Problems with MagicAjax

I added what is below to my web.config file: <httpModules> <add name=”MagicAjax” type=”MagicAjax.MagicAjaxModule, MagicAjax”/> <add name=”ScriptModule” type=”Microsoft.Web.Services.ScriptModule”/> </httpModules> And I got: Could not load file or assembly ‘MagicAjax’ or one of its dependencies. The system cannot find the file specified. (C:\Inetpub\wwwroot\TheTracker\web.config line 48) The solution I found that worked was adding the MagicAjax assembly to […]

Categories
ASP.NET

Console Applications

Console Applications are command-line oriented applications that allow us to read characters from the console, write characters to the console and are executed in the DOS version. Console Applications are written in code and are supported by the System.Console namespace. (Source) Hello World – Console Application

Categories
ASP.NET

Try Catch in .NET

The Try word means “Try to execute this code”. The Catch word means “Catch any errors here”. The ex is a variable, and the type of variable it is an Exception object. Example Public Function Delete(ByVal fileName As String) As Boolean Try File.Delete(String.Format(“{0}\{1}”, ConfigurationManager.AppSettings(“ImageDirectory”), fileName)) Return True Catch ex As Exception Return False End Try […]