Tuesday, March 31, 2009

Dyanamic item addition in drop down list by using C#

Below is the syntax for dyanamic item addition in drop down list by using C#

DropDownList1.Items.Add("Item1");
DropDownList1.Items.Add("Item2");
DropDownList1.Items.Add("Item3");

Find current day, month and year by using c#

Here is the syntax to find current day, month and year by using c#.net

String TodayDate = DateTime.Now.Date.Day.ToString();
String Todaymonth = DateTime.Now.Date.Month.ToString();
String Todayyear = DateTime.Now.Date.Year.ToString();

--------showing day, month and year in text boxes---------------
Date.Text = TodayDate;
month.Text = Todaymonth;
year.Text = Todayyear;

Here is the out put sample.
day=1
Month=4
year=2009

SQL Server Database Connection using C#.net and ASP.net

Step 1:
First of all add appSettings tag in web.config file under configuration tag

--------appSettings------------

add key="cn" value="workstation id=SQL8;packet size=4096;user id=user1;password=password1;data source=671.15.417.21;initial catalog=DBNews; Connection Timeout=120;"

--------appSettings------------


Step 2:
Add namespace given below.
using System.Data
using System.Data.SqlClient;


Step 3:
Add below code under partial class

SqlConnection con;
SqlCommand cmd;
SqlDataAdapter adp;
DataSet ds;

Step 4:
Call below code at Page Load event

con = new SqlConnection(ConfigurationManager.AppSettings["cn"]);
String sql = "select * from tbl_adminuser";
cmd = new SqlCommand(sql, con);
adp = new SqlDataAdapter(cmd);
ds = new DataSet();
adp.Fill(ds, "tbl_adminuser");

Step 5:
Show User password on the page.

TextBox1.Text=ds.Tables[0].Rows[0]["Password"].ToString();

Friday, March 20, 2009

ASP.net Basics

What is ASP.NET?
ASP.NET is a server side scripting technology that enables scripts (embedded in web pages) to be executed by an Internet server.

ASP.NET is a Microsoft Technology
ASP stands for Active Server Pages
ASP.NET is a program that runs inside IIS
IIS (Internet Information Services) is Microsoft's Internet server
IIS comes as a free component with Windows servers
IIS is also a part of Windows 2000 and XP Professional

What is an ASP.NET File?
An ASP.NET file is just the same as an HTML file
An ASP.NET file can contain HTML, XML, and scripts
Scripts in an ASP.NET file are executed on the server
An ASP.NET file has the file extension ".aspx"

How Does ASP.NET Work?
When a browser requests an HTML file, the server returns the file
When a browser requests an ASP.NET file, IIS passes the request to the ASP.NET engine on the server
The ASP.NET engine reads the file, line by line, and executes the scripts in the file
Finally, the ASP.NET file is returned to the browser as plain HTML

What is ASP+?
ASP+ is the same as ASP.NET.

ASP+ is just an early name used by Microsoft when they developed ASP.NET.

ASP.NET is Not ASP
ASP.NET is the next generation ASP, but it's not an upgraded version of ASP.

ASP.NET is an entirely new technology for server-side scripting. It was written from the ground up and is not backward compatible with classic ASP.


ASP.NET is the major part of the Microsoft's .NET Framework.