Clearing all TextBoxes text from a Form using C#

When we develop any application form, then there will be a new button where we need to perform clear operation. We can clear all the TextBox texts from a Form or a Control like panel, tabe pages using following code foreach (Control c in this.Controls) { if (c is TextBox) { c.Text = string.Empty; } read more »

Run your ASP.net Application without IIS.

It is easy to run your asp.net web application without installing any web server. For running your application without IIS you have to use Cassini Desktop Adapter. Features of Cassini Desktop Adapter * Standalone Web Applications – now on the Desktop * 100% Embedded Web server * No Installation or GAC Required * No Administrator read more »

Select Distinct Record from DataTable

If it is necessary to select distinct record from Data Table, then we can use following method. public DataTable SelectDistinct(DataTable SourceTable, string FieldName) { DataTable dt = new DataTable(); dt = SourceTable.Clone(); object LastValue = null; foreach (DataRow dr in SourceTable.Select(“”, FieldName)) { if (LastValue == null || !(ColumnEqual(LastValue, dr[FieldName]))) { LastValue = dr[FieldName]; dt.ImportRow(dr); read more »

Sending Email using C# (with HTML body & Attachment )

Introduction This article is provide a basic idea how we can send Emails from a C# Windows Application. Here I have described how we can send mail with Attachment and HTML body. Description If we want to send mail then we need to know following things 1. SMTP Server address 2. Port No Here I read more »

Converting List to DataTable in C#

There is no built in method for converting list to data table in C#. So we can implement following method for converting List to DataTable in C#. public DataTable ToDataTable(IList data) { PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(t)); DataTable table = new DataTable(); for (int i = 0; i < props.Count; i++) { PropertyDescriptor prop = props[i]; read more »

Converting DataView to DataTable in C#

Consider following code for converting DataView to DataTable in C# DataTable dt = dv.ToTable();// dv = Data View Consider following example public DataTable GetFilterData(DataTable dt) { if (dt != null) { DataView dataView = dt.DefaultView; dataView.RowFilter = filterCondition; //some condition like”: ColumnName like ‘%this%’; dt = dataView.ToTable(); } return dt; }

Preventing / Blocking Page Review after Logout with Forms Authentication

After logging out we can prevent getting previous page or information by doing following things. Add Code to Page Load event: —————————– Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1)); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetNoStore(); Or We can use following code

Export to pdf ( Create pdf on fly ) using ASP.net and C#

Consider following code for creating pdf document on fly using ASP.net in C#. using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; namespace WebApplication1 { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) read more »

How to enable Paging in GridView in ASP.net or Grid View Paging doesn’t work

Do Following steps. –> Set EnablePaging and Sorting Callback = True from Propertise. Set your data source as general way. Now do another extra job for working paging Write down the following code under PageIndexGhanging Event protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { //Create your data set or table as u did GridView1.PageIndex = e.NewPageIndex; read more »

Filter data by date time in MS access, Select only date without selecting time from date time field in MS Access

Select * from TransactionInfo where CDate(Int([CreatedDate])) between #2010-05-04# and #2010-05-05# —————– it will return date like —————– 23-May-2010 Select * from TransactionInfo where [CreatedDate] between #2010-05-04# and #2010-05-05# —————– it will return —————–