Skip to main content

Posts

IsNumeric C# equivalent

IsNumeric in C#, WHY NOT? This is something that has bothered me for a long while now. Why doesn't C# have a IsNumeric(string num) function like VB.NET? I have used every kind of IsNumeric code you van think of... This is what I started with.publicbool IsNumeric(string s) { try { Int32.Parse(s); } catch { returnfalse; } returntrue; }But we all no the unspoken rule, NEVER use try, catch for functionality... So I tried this.internalstaticbool IsNumeric(string numberString) { char [] ca = numberString.ToCharArray(); for (int i = 0; i <> if (ca[i] > 57 || ca[i] <> returnfalse; } returntrue; } Then I found char.IsNumber: (Why do they have a char.IsNumber, but no string.IsNumeric???)internalstaticbool IsNumeric(string numberString) { char [] ca = numberString.ToCharArray(); for (int i = 0; i <> if (!char.IsNumber(ca[i])) ret…

How To Add IsNumneric Function in C#

That's right, you can call VB's IsNumeric() function directly from C#. First add a reference to the Visual Basic compatibility assembly, Microsoft.VisualBasic.dll, which contains the function's implementation: import namespace using Microsoft.VisualBasic; <%@ Page Language="C#" AutoEventWireup="true" CodeFile="IsNumneric.aspx.cs" Inherits="IsNumneric" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title></head><body><formid="form1"runat="server"><div><asp:TextBoxID="TextBox1"runat="server"></asp:TextBox><asp:LabelID="Label1"runat="server"Text="Label"></asp:Label><asp:ButtonID="B…

Working With ObjectDataSource And GridView

1. Create Middle Tier classl Create static, stateless methodsl Mark class and methods with DataObjectMethod attribute (requires using System.ComponentModel)2. Configure Data Source·Choose a business object·Define data methods3. Configure GridView·Check “Enable Editing”, etc.step1.Add a new project in VS.netstep2.Add a class CustomersDataObject in App_Code Folder and add following codeusing System; using Syst

How to find a cell value

If you find yourself wanting to parse through a dataset for a particular cellvalue and you need to do this programatically, this might help a little.. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewCellValue.aspx.cs" Inherits="GridViewCellValue" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title><styletype="text/css"> .Hide{visibility:hidden}; </style></head><body><formid="form1"runat="server"><div><asp:GridViewID="GridView1"runat="Server"OnRowDataBound="GridView1_RowDataBound"></asp:GridView></div></form></body></html>using System; using System.Data; using S…

sp.Net Ajax HoverMenu Control On GridView with Database Manipulations

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewHover.aspx.cs" Inherits="GridViewHover" %><%@ Register TagPrefix="cc1" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title><styletype="text/css"> .popupMenu { position:absolute; visibility:hidden; background-color:#F5F7F8; opacity:.9; filter: alpha(opacity=90); } .popupHover { background-image:url(img/header-opened.png); background-repeat:repeat-x; background-position:left top; background-color:#F5F7F8; } …

Tips -Master Page

ASP.NET master pages are pretty handy and here is a simple tip to make them even easier to use. Using the MasterType reference in your content page allows you to refer to your master page properties without having to cast it to your master page type everytime. For example... <%@ MasterType TypeName="myMasterType" %>allows me to write... this.Master.myProperty = "value";rather than... ((myMasterType)this.Master).myProperty = "value";Which saves you a little typing and provides intellisense

Select GridView Row on Double Click

Start with an existing GridView that is populated from a data source In the ItemDataBound event handler of GridView, you assign a JavaScript ondblclick method to the GridViewRow <%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewDblClick.aspx.cs" Inherits="GridViewDblClick" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title></head><body><formid="form1"runat="server"><div><asp:GridViewID="GridView1"runat="Server"OnRowDataBound="GridView1_RowDataBound"></asp:GridView></div></form></body></html>using System; using System.Data; using System.Configuration; using System.Collections; using System…