Tuesday, January 31, 2012

gridview allowpaging W/O datasource in asp net C#

grid view on the page as follows

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowPaging="true" onpageindexchanging="GridView2_PageIndexChanging" >

protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
            GridView2.DataSource = ds;
            GridView2.PageIndex = e.NewPageIndex;
            GridView2.DataBind();
    }

Here ds is dataset.

change gridview row color based on condition c#

Change Row Color in asp.net Gridview base on conditions follow as stated


Suppose you placed agridview in the page as follows


<asp:GridView id="GridView1"  runat="Server" OnRowCreated="GridView1_OnRowCreated" autogenerateColumns="false"/>

Enable/Disable asp.net Gridview Checkbox base on conditions

To Enable/Disable asp.net Gridview Checkbox base on conditions just follow simple way


Suppose you placed agridview in the page as follows

<asp:GridView id="GridView1"  runat="Server" OnRowCreated="GridView1_OnRowCreated" autogenerateColumns="false"/>

Thursday, January 26, 2012

Digits after decimal point in c#.net

This example formats double to string with fixed number of decimal places. For two decimal places use pattern „0.00“. If a float number has less decimal places, the rest digits on the right will be zeroes. If it has more decimal places, the number will be rounded.

Ex :-
.ToString("N");         // 98.5864256544   ==>   98.58
or
String.Format("{0:0.00}", 123.4567);      // "123.46"
 

MySQL Date and Time Formatting

If you wanted to change the format of a MySQL date from YYYY-MM-DD to DD/MM/YYYY or MM/DD/YYYY format you can use the DATE_FORMAT() function as shown in the given example :-

syntax :-
SELECT DATE_FORMAT(ColumnName, '%d/%m/%Y') from TableName

Ex :-
SELECT DATE_FORMAT(startingdate, '%d/%m/%Y') from customerinfo
or
SELECT DATE_FORMAT(startingdate, '%m/%d/%Y') from customerinfo
or
SELECT DATE_FORMAT(date, '%m/%d/%Y %l %p') from customerinfo

Monday, January 23, 2012

String Format for DateTime (C#)

This post shows you how to format DateTime using DateTime.Now.ToString() method.

There are different datetime Formats as menctioned below...
DateTime dt = new DateTime.Now.ToString(); // jan-23-2012
gives an output as Monday, January 23, 2012 

More Examples :

dt.ToString("dd-MM-yyyy"); // Indian Date Format 23-01-2012
dt.ToString("dd-MM-yyyy HH:mm:ss"); // Indian Date and Time 23-01-2012 23:35:07
dt.ToString("dd-MM-yyyy HH:mm tt"); // Indian Date and Time 23-01-2012 23:35 PM

Tuesday, January 17, 2012

ModalPopUp from serverside in Asp.Net (C#)

 The ModalPopup control in the AJAX Control Toolkit offers a simple way to create a modal popup using client-side popup. However some scenarios require that the opening of the modal popup is triggered on the server-side.