Thursday, July 29, 2010

Checking if a string is numeric in C#

 int sidNumber;
bool isInteger = Int32.TryParse(sid, out sidNumber);

Wednesday, July 28, 2010

Add a JavaScript alert box

http://www.beansoftware.com/ASP.NET-Tutorials/Message-Box.aspx

http://www.dotnetspider.com/forum/ViewForum.aspx?ForumId=32564

Credits to chakravarthy


string tmp = "";
tmp = "";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", tmp);
and if u want to alert message for Exceptions
string tmp = "";
tmp = "";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", tmp);

Adding Client-Side Confirmation When Deleting

http://www.asp.net/data-access/tutorials/adding-client-side-confirmation-when-deleting-cs

Here's some example code

<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="True" 
CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you wish to delete this record?');" />


 




Wednesday, May 19, 2010

Create Dynamic DataTable with DataTableManager

static DataTable dtNew;




string[] colNames = { "StudentID", "Name", "Course", "StudentClass", "MobileNo", "HomeEmail", "PT" };


string[] colTypes = { "System.String", "System.String", "System.String", "System.String", "System.String",
                                 "System.String", "System.String"};


int[] colWidth = { 10, 10, 10, 10, 10, 10, 10 };


protected void Page_Load(object sender, EventArgs e)
{
      if (!Page.IsPostBack)
          dtNew = DataTableManager.createNewTable(colNames, colTypes);
}

Friday, May 14, 2010

SQL: How to display row count / row number

select  ROW_NUMBER() OVER(ORDER BY ID,Name) AS 'Num', ID,Name

How to convert the output of a SQLDataSource.Select to a DataTable

/*Step 1 : First convert source of a SQLDataSource into a DataView */
DataView dv = (DataView)SqlDataSourceStudentsOnly.Select(DataSourceSelectArguments.Empty);
/*Step 2: Cast it to DataTable using ToTable() method of DataSet */

DataTable dt = (DataTable)dv.ToTable();