Saturday, September 30, 2006

Page Counter in ASP 3.0

Lots of guys had done programming for page counter for a site.

I found a interesting example on IIS 5.1 documentation. It is

very easy and very cool. You can developer your page counter

with 2 or 3 line of code in asp 3.0.

Following are the code:


<%

Set MyPageCounter = Server.CreateObject("MSWC.PageCounter")

HitMe = MyPageCounter.Hits

Response.Write("Total Count:" & HitMe)

%>


Thats it your counter is ready.


Happy Programming...

Share:
Saturday, August 26, 2006

code for date picker combobox control in asp.net:

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#

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

runat="server"></asp:dropdownlist>



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

runat="server"></asp:dropdownlist>



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

runat="server"></asp:dropdownlist>
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
{
get
{
return _SelectedDate;
}
set
{
_SelectedDate=value;

}
}
public string SetDate
{
get
{
return _SetDate;
}
set
{
cmbYear.Items.FindByValue(cmbYear.SelectedValue).Selected=false;
cmbYear.Items.FindByValue(System.Convert.ToDateTime(value).
Year.ToString()).Selected=true;
cmbMonth.Items.FindByValue(cmbMonth.SelectedValue).Selected=false;
cmbMonth.Items.FindByValue(System.Convert.ToDateTime(value).
Month.ToString() ).Selected=true;
cmbDay.Items.FindByValue(cmbDay.SelectedValue).Selected=false;
cmbDay.Items.FindByValue(System.Convert.ToDateTime(value).Day.
ToString() ).Selected=true;
SelectedDate= cmbMonth.SelectedValue.ToString() + "/" +
cmbDay.SelectedValue.ToString() + "/" +
cmbYear.SelectedValue.ToString();

}
}

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
FillYear();
FillMonth();
FillDay(int.Parse(cmbMonth.SelectedValue),
int.Parse(cmbYear.SelectedValue));
SelectedDate= cmbMonth.SelectedValue.ToString() + "/"
+cmbDay.SelectedValue.ToString() + "/" + cmbYear.SelectedValue.ToString();
}
}
public void FillDay(int Month,int Year)
{
cmbDay.Items.Clear();
int a;
a=Year%4;
int count;
count=0;
switch(Month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
count=31;
break;
case 4:
case 6:
case 9:
case 11:
count=30;
break;
case 2:
if(a==0)
{
count=29;
}
else
{
count=28;
}
break;
}

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);
if(abbreviate)
return date.ToString("MMM");
else
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.
//
InitializeComponent();
base.OnInit(e);
}


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);

}
#endregion

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

private void cmbMonth_SelectedIndexChanged(object sender, System.EventArgs e)
{
FillDay(int.Parse(cmbMonth.SelectedValue),int.Parse(cmbYear.SelectedValue));
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();
}

}
}
Share:
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
Share:

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.
Share:
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...
Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews