Saturday, August 26, 2006

code for date picker combobox control in

ASP.NET provides calendar control to select date
but some time it not feasible due to the size of
it. It takes more spaces. So we are required
to create a new web control which is used less
space and also provides date selection mechanism
here are the code for that control in C#

<asp:dropdownlist id="cmbDay" AutoPostBack="True"


<asp:dropdownlist id="cmbMonth" AutoPostBack="True"


<asp:dropdownlist id="cmbYear" AutoPostBack="True"

Server Side Code in C#:
namespace Jalpesh.Control
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.VisualBasic;

public class DatePicker : System.Web.UI.UserControl
public System.Web.UI.WebControls.DropDownList cmbDay;
public System.Web.UI.WebControls.DropDownList cmbMonth;
public System.Web.UI.WebControls.DropDownList cmbYear;
private static string _SelectedDate;
public string _SetDate;
public static string SelectedDate
return _SelectedDate;

public string SetDate
return _SetDate;
Month.ToString() ).Selected=true;
ToString() ).Selected=true;
SelectedDate= cmbMonth.SelectedValue.ToString() + "/" +
cmbDay.SelectedValue.ToString() + "/" +


private void Page_Load(object sender, System.EventArgs e)
if (!Page.IsPostBack)
SelectedDate= cmbMonth.SelectedValue.ToString() + "/"
+cmbDay.SelectedValue.ToString() + "/" + cmbYear.SelectedValue.ToString();
public void FillDay(int Month,int Year)
int a;
int count;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
case 4:
case 6:
case 9:
case 11:
case 2:

for (int i=1;i<=count;i++) { ListItem lstItem=new ListItem(i.ToString(),i.ToString()); if (i==(int.Parse(System.DateTime.Today.Day.ToString() ))) { lstItem.Selected=true; } cmbDay.Items.Add(lstItem); } } public void FillYear() { int i; cmbYear.Items.Clear(); for (i=1900;i<=3000;i++) { ListItem lstItem=new ListItem(i.ToString(),i.ToString()); if (i==(int.Parse(System.DateTime.Today.Year.ToString() ))) { lstItem.Selected=true; } cmbYear.Items.Add(lstItem); lstItem=null; } } public void FillMonth() { int i; cmbMonth.Items.Clear(); for(i=1;i<=12;i++) { ListItem lstItem=new ListItem(GetMonthName(i,false),i.ToString()); if (i==(int.Parse(System.DateTime.Today.Month.ToString() ))) { lstItem.Selected=true; } cmbMonth.Items.Add(lstItem); lstItem=null; } } static string GetMonthName(int monthNum, bool abbreviate) { if(monthNum <> 12)
throw new ArgumentOutOfRangeException("monthNum");
DateTime date = new DateTime(1,monthNum,1);
return date.ToString("MMM");
return date.ToString("MMMM");

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
// CODEGEN: This call is required by the ASP.NET Web Form Designer.

private void InitializeComponent()
cmbDay.SelectedIndexChanged += new System.EventHandler(this.cmbDay_SelectedIndexChanged);
cmbMonth.SelectedIndexChanged += new System.EventHandler(this.cmbMonth_SelectedIndexChanged);
cmbYear.SelectedIndexChanged += new System.EventHandler(this.cmbYear_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);


private void cmbYear_SelectedIndexChanged(object sender, System.EventArgs e)
SelectedDate= cmbMonth.SelectedValue.ToString() + "/" +cmbDay.SelectedValue.ToString() + "/" + cmbYear.SelectedValue.ToString();

private void cmbMonth_SelectedIndexChanged(object sender, System.EventArgs e)
SelectedDate= cmbMonth.SelectedValue.ToString() + "/" +cmbDay.SelectedValue.ToString() + "/" + cmbYear.SelectedValue.ToString();

private void cmbDay_SelectedIndexChanged(object sender, System.EventArgs e)
SelectedDate= cmbMonth.SelectedValue.ToString() + "/" +cmbDay.SelectedValue.ToString() + "/" + cmbYear.SelectedValue.ToString();

Thursday, August 24, 2006

Thank You For Visiting My Blog

Thank You Very Much for visiting my blog,

There are 155 visitors in last month who visit my blog. It is such
a over whelming experience that you work is recognized in such big way.

I want your valuable comments on my post to make it better. So please put
your comments for the post directly.

You can also put your valuable comments in my guest book:

here are the links:

Post Your Comments

Sql Server Escape Sequence

Some times we are required to put '(Quotation Mark) in our sql stored procedure query.But '(Quotation Mark) will use for operation in sql server stored procedure. You can use escape sequence here.
for example you want to put 'jalpesh' in stored procedure then you should give
print '''jalpesh'''
here first two quota ion mark counted as escape sequence and then the third ' are counted as character.
Thursday, August 10, 2006

Starting Point of auto number fields in Microsoft Access

Auto Number Field handy things in Microsoft access.It will
automatically increase the filed value as records are
inserted. Developer don't have to care for it. By default
auto number field start with the zero but sometimes we
required to start auto number with rather than zero.

We can do it by creating the append query. Following
are the procedure for creating our own starting point
in the Microsoft access.

-First copy the auto number field table with another
table name.

-Now change the auto number field to the number field
in the newly created make sure that long integer is there.

-Now insert a record with starting point in newly created
table. For example you want to start with 300 then
insert with 300.

-Create a query from query designer of access
select all the field of newly created table.

-Go to the query menu select append query and into
destination table give original table name.

-Append it

- Delete newly created table.

That's it. You have created your own starting point.
now auto number starts with 300.

Happy Programming...

Paging in Datalist or Repeater Control In ASP.NET

HTML of Datalist
<asp:datalist id="dsList" runat="server" width=100%>


<%#DataBinder.Eval(Container.DataItem, "ID").ToString()%>

<%#DataBinder.Eval(Container.DataItem, "Name").ToString()%>



<table width="100%" border="0" align="Center">


<td><asp:LinkButton id="lnkPrevious" runat="server">



<td><asp:LinkButton id="lnkNext" runat="server">>




Server Side Coding : VB.NET

Dim Start As Integer
Dim dbCon As SqlConnection
Dim Adpt As SqlDataAdapter
Dim dtUser As DataSet

Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then
ViewState("Start") = 0
End If

End Sub

Sub BindData()

dbCon = New SqlConnection("server=localhost;uid=sa;
Adpt = New SqlDataAdapter("Select * from user ", dbCon)
dtUser = New DataSet
Start = ViewState("Start")
ViewState("Size") = 14
Adpt.Fill(dtUser, Start, ViewState("Size"), "user")
dsList.DataSource = dtUser

End Sub

Private Sub lnkPrevious_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles lnkPrevious.Click

Start = ViewState("Start")- ViewState("Size")
ViewState("Start") = Start
If Start <= 0 Then ViewState("Start") = 0 End If BindData() End Sub Private Sub lnkNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkNext.Click Dim count As Integer = dsList.Items.Count Start = ViewState("Start") + ViewState("Size") ViewState("Start") = Start If count <>
Server Side Coding: c#
int Start ;
SqlConnection dbCon ;
SqlDataAdapter Adpt ;
DataSet dtUser ;
private void Page_Load(object sender, System.EventArgs e)
if(!Page.IsPostBack )
ViewState["Start"] = 0;
void BindData()
dbCon = new SqlConnection("server=localhost;uid=sa;
Adpt = new SqlDataAdapter("Select * from user", dbCon);
dtUser = new DataSet();
Start = (int)ViewState["Start"];
ViewState["Size"] = 14;
Adpt.Fill(dtUser, Start,(int) ViewState["Size"], "user");
dsList.DataSource = dtUser;

private void lnkPrevious_Click(object sender, System.EventArgs e)
Start = (int) ViewState["Start"] -(int) ViewState["Size"];
ViewState["Start"] = Start;
if (Start <= 0 ) { ViewState["Start"] = 0; } BindData(); } private void lnkNext_Click(object sender, System.EventArgs e) { int count = dsList.Items.Count; Start = (int) ViewState["Start"]+(int) ViewState["Size"]; ViewState["Start"] = Start; if ( count < (int)ViewState["Size"] ) { ViewState["Start"] = (int)ViewState["Start"] - (int)ViewState["Size"]; } BindData(); }
Monday, August 7, 2006

Crystal Report : Add Comand:

Some times we need only a single field from a particular table while creating a report.Which sometimes has no relationship with others.To do this So many peoples are importing table and use a one field.

Crystal Reports 9.0 onwards give us a facility called command which return the fields as you have specified in the command query.

To do this go to the database expert and select add command this will open a query window there and put the simple query and it will return fields you have specified in the query analyser.

It's very simple.Happy Programming....
Thursday, August 3, 2006

Displaying Multiple record in a Row in ASP.NET:

Sometimes we need to display multiple records in a
row. For example we need to display image details and
image for a image viewer application.

For that we could not use datagrid. Because it cannot
display more than one record in a row.

The Asp.NET 1.1 and 2.0 provides other called datalist.
Which provides this functionality very easily.

It contains two properties called 'RepeatColumns'
and 'Repeat Direction'.

'Repeat Column'- Sets how much records we need to display
in a row.

'Repeat Direction' -Sets the repeat direction
i.e. Horizontal or Vertical.

With the help of this properties one can easily
display more than one record in one row.

For more details regarding the datalist please visit:

Happy Programming...
Tuesday, August 1, 2006

Use Component Class in Business Logic Class in C# or VB.NET:

You can get many advantage using a component class instead
of simple class.

Following are the some basic advantage that you can get using
component class.

- It implements System.Component namespace
- You can drag and drop any existing data access component.So
you have to right less code.
- You can drag and drop stored procedure and other sql server
object and .NET IDE will create sqlcommand and adapter and
command object directly.
- You can use typed dataset with the component class easily
without writing any code through wizards.

Insert NUll in value datatype like int,float in C#

Some times we need to make some data type to null. Like
in some cases like stored procedure in database.

We can do it in C# very easily. by just putting ?sign in'
the definition like below:

int? a;

that's it! you have created a value data type with null
database. If you don't supply a value to the int a then
it will remain null.

You can use this for any value data type like short,single,
double,long,decimal etc.

Happy Programming...
Search This Blog
About Me
My Photo

Full Stack Developer,Blogger,Microsoft Mvp, Mentor, Life long learner, 10+ Years of Experience for JavaScript, web and Microsoft technologies. ASP.NET MVC,Web Forms,C#,AngularJs,Golang
Mvp profile
Subscribe to my blog

Enter your email address:

Follow us on facebook
Blog Archive
Total Pageviews