Form örneği (aspx.cs ve aspx) Kodları

Asp.NET ile ilgili tüm materyaller burada

Moderatör: yashin

warhorse
Üye
Mesajlar: 19
Kayıt: 07 May 2013 22:33
İletişim:

Form örneği (aspx.cs ve aspx) Kodları

Mesaj gönderen warhorse » 14 May 2013 02:04

ASPX.CS Kısmı
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gun();
ay();
yil();
sehir();
cinsiyet();
hobi();

}
}

public void gun()
{
ddlgun.Items.Add(new ListItem("Seçiniz"));
ddlgun.Items.Add(new ListItem("1"));
ddlgun.Items.Add(new ListItem("2"));
ddlgun.Items.Add(new ListItem("3"));
ddlgun.Items.Add(new ListItem("4"));
ddlgun.Items.Add(new ListItem("5"));
ddlgun.Items.Add(new ListItem("6"));
ddlgun.Items.Add(new ListItem("7"));
ddlgun.Items.Add(new ListItem("8"));
ddlgun.Items.Add(new ListItem("9"));
ddlgun.Items.Add(new ListItem("10"));
ddlgun.Items.Add(new ListItem("11"));
ddlgun.Items.Add(new ListItem("12"));
ddlgun.Items.Add(new ListItem("13"));
ddlgun.Items.Add(new ListItem("14"));
ddlgun.Items.Add(new ListItem("15"));
ddlgun.Items.Add(new ListItem("16"));
ddlgun.Items.Add(new ListItem("17"));
ddlgun.Items.Add(new ListItem("18"));
ddlgun.Items.Add(new ListItem("19"));
ddlgun.Items.Add(new ListItem("20"));
ddlgun.Items.Add(new ListItem("21"));
ddlgun.Items.Add(new ListItem("22"));
ddlgun.Items.Add(new ListItem("23"));
ddlgun.Items.Add(new ListItem("24"));
ddlgun.Items.Add(new ListItem("25"));
ddlgun.Items.Add(new ListItem("26"));
ddlgun.Items.Add(new ListItem("27"));
ddlgun.Items.Add(new ListItem("28"));
ddlgun.Items.Add(new ListItem("29"));
ddlgun.Items.Add(new ListItem("30"));
ddlgun.Items.Add(new ListItem("31"));
}
public void ay()
{
ddlay.Items.Add(new ListItem("Seçiniz"));
ddlay.Items.Add(new ListItem("Ocak"));
ddlay.Items.Add(new ListItem("Şubat"));
ddlay.Items.Add(new ListItem("Mart"));
ddlay.Items.Add(new ListItem("Nisan"));
ddlay.Items.Add(new ListItem("Mayıs"));
ddlay.Items.Add(new ListItem("Haziran"));
ddlay.Items.Add(new ListItem("Temmuz"));
ddlay.Items.Add(new ListItem("Ağustos"));
ddlay.Items.Add(new ListItem("Eylül"));
ddlay.Items.Add(new ListItem("Ekim"));
ddlay.Items.Add(new ListItem("Kasım"));
ddlay.Items.Add(new ListItem("Aralık"));
}
public void yil()
{
ddlyil.Items.Add(new ListItem("Seçiniz"));
ddlyil.Items.Add(new ListItem("2013"));
ddlyil.Items.Add(new ListItem("2012"));
ddlyil.Items.Add(new ListItem("2011"));
ddlyil.Items.Add(new ListItem("2010"));
ddlyil.Items.Add(new ListItem("2009"));
ddlyil.Items.Add(new ListItem("2008"));
ddlyil.Items.Add(new ListItem("2007"));
ddlyil.Items.Add(new ListItem("2006"));
ddlyil.Items.Add(new ListItem("2005"));
ddlyil.Items.Add(new ListItem("2004"));
ddlyil.Items.Add(new ListItem("2003"));
ddlyil.Items.Add(new ListItem("2002"));
ddlyil.Items.Add(new ListItem("2001"));
ddlyil.Items.Add(new ListItem("2000"));
ddlyil.Items.Add(new ListItem("1999"));
ddlyil.Items.Add(new ListItem("1998"));
ddlyil.Items.Add(new ListItem("1997"));
ddlyil.Items.Add(new ListItem("1996"));
ddlyil.Items.Add(new ListItem("1995"));
ddlyil.Items.Add(new ListItem("1994"));
ddlyil.Items.Add(new ListItem("1993"));
ddlyil.Items.Add(new ListItem("1992"));
ddlyil.Items.Add(new ListItem("1991"));
ddlyil.Items.Add(new ListItem("1990"));
ddlyil.Items.Add(new ListItem("1989"));
ddlyil.Items.Add(new ListItem("1988"));
ddlyil.Items.Add(new ListItem("1987"));
ddlyil.Items.Add(new ListItem("1986"));
ddlyil.Items.Add(new ListItem("1985"));
ddlyil.Items.Add(new ListItem("1984"));
ddlyil.Items.Add(new ListItem("1983"));
ddlyil.Items.Add(new ListItem("1982"));
ddlyil.Items.Add(new ListItem("1981"));
ddlyil.Items.Add(new ListItem("1980"));


}
public void sehir()
{
ddlsehir.Items.Add(new ListItem("Seçiniz"));
ddlsehir.Items.Add(new ListItem("Adana"));
ddlsehir.Items.Add(new ListItem("Adıyaman"));
ddlsehir.Items.Add(new ListItem("Afyonkarahisar"));
ddlsehir.Items.Add(new ListItem("Ağrı"));
ddlsehir.Items.Add(new ListItem("Amasya"));
ddlsehir.Items.Add(new ListItem("Ankara"));
ddlsehir.Items.Add(new ListItem("Antalya"));
ddlsehir.Items.Add(new ListItem("Artvin"));
ddlsehir.Items.Add(new ListItem("Aydın"));
ddlsehir.Items.Add(new ListItem("Balıkesir"));
ddlsehir.Items.Add(new ListItem("Bilecik"));
ddlsehir.Items.Add(new ListItem("Bingöl"));
ddlsehir.Items.Add(new ListItem("Bitlis"));
ddlsehir.Items.Add(new ListItem("Bolu"));
ddlsehir.Items.Add(new ListItem("Burdur"));
ddlsehir.Items.Add(new ListItem("Bursa"));
ddlsehir.Items.Add(new ListItem("Çanakkale"));
ddlsehir.Items.Add(new ListItem("Çankırı"));
ddlsehir.Items.Add(new ListItem("Çorum"));
ddlsehir.Items.Add(new ListItem("Denizli"));
ddlsehir.Items.Add(new ListItem("Diyarbakır"));
ddlsehir.Items.Add(new ListItem("Edirne"));
ddlsehir.Items.Add(new ListItem("Elazığ"));
ddlsehir.Items.Add(new ListItem("Erzincan"));
ddlsehir.Items.Add(new ListItem("Erzurum"));
ddlsehir.Items.Add(new ListItem("Eskişehir"));
ddlsehir.Items.Add(new ListItem("Gaziantep"));
ddlsehir.Items.Add(new ListItem("Giresun"));
ddlsehir.Items.Add(new ListItem("Gümüşhane"));
ddlsehir.Items.Add(new ListItem("Hakkâri"));
ddlsehir.Items.Add(new ListItem("Hatay"));
ddlsehir.Items.Add(new ListItem("Isparta"));
ddlsehir.Items.Add(new ListItem("Mersin"));
ddlsehir.Items.Add(new ListItem("İstanbul"));
ddlsehir.Items.Add(new ListItem("İzmir"));
ddlsehir.Items.Add(new ListItem("Kars"));
ddlsehir.Items.Add(new ListItem("Kastamonu"));
ddlsehir.Items.Add(new ListItem("Kayseri"));
ddlsehir.Items.Add(new ListItem("Kırklareli"));
ddlsehir.Items.Add(new ListItem("Kırşehir"));
ddlsehir.Items.Add(new ListItem("Kocaeli"));
ddlsehir.Items.Add(new ListItem("Konya"));
ddlsehir.Items.Add(new ListItem("Kütahya"));
ddlsehir.Items.Add(new ListItem("Malatya"));
ddlsehir.Items.Add(new ListItem("Manisa"));
ddlsehir.Items.Add(new ListItem("Kahramanmaraş"));
ddlsehir.Items.Add(new ListItem("Mardin"));
ddlsehir.Items.Add(new ListItem("Muğla"));
ddlsehir.Items.Add(new ListItem("Muş"));
ddlsehir.Items.Add(new ListItem("Nevşehir"));
ddlsehir.Items.Add(new ListItem("Niğde"));
ddlsehir.Items.Add(new ListItem("Ordu"));
ddlsehir.Items.Add(new ListItem("Rize"));
ddlsehir.Items.Add(new ListItem("Sakarya"));
ddlsehir.Items.Add(new ListItem("Samsun"));
ddlsehir.Items.Add(new ListItem("Siirt"));
ddlsehir.Items.Add(new ListItem("Sinop"));
ddlsehir.Items.Add(new ListItem("Sivas"));
ddlsehir.Items.Add(new ListItem("Tekirdağ"));
ddlsehir.Items.Add(new ListItem("Tokat"));
ddlsehir.Items.Add(new ListItem("Trabzon"));
ddlsehir.Items.Add(new ListItem("Tunceli"));
ddlsehir.Items.Add(new ListItem("Şanlıurfa"));
ddlsehir.Items.Add(new ListItem("Uşak"));
ddlsehir.Items.Add(new ListItem("Van"));
ddlsehir.Items.Add(new ListItem("Yozgat"));
ddlsehir.Items.Add(new ListItem("Zonguldak"));
ddlsehir.Items.Add(new ListItem("Aksaray"));
ddlsehir.Items.Add(new ListItem("Bayburt"));
ddlsehir.Items.Add(new ListItem("Karaman"));
ddlsehir.Items.Add(new ListItem("Kırıkkale"));
ddlsehir.Items.Add(new ListItem("Batman"));
ddlsehir.Items.Add(new ListItem("Şırnak"));
ddlsehir.Items.Add(new ListItem("Bartın"));
ddlsehir.Items.Add(new ListItem("Ardahan"));
ddlsehir.Items.Add(new ListItem("Iğdır"));
ddlsehir.Items.Add(new ListItem("Yalova"));
ddlsehir.Items.Add(new ListItem("Karabük"));
ddlsehir.Items.Add(new ListItem("Kilis"));
ddlsehir.Items.Add(new ListItem("Osmaniye"));
ddlsehir.Items.Add(new ListItem("Düzce"));


}

public void cinsiyet()
{
rdcins.Items.Add(new ListItem("Bay"));
rdcins.Items.Add(new ListItem("Bayan"));
}
public void hobi()
{
chckhobi.Items.Add(new ListItem("Kitap Okumak"));
chckhobi.Items.Add(new ListItem("Sinemaya Gitmek"));
chckhobi.Items.Add(new ListItem("Fotoğraf Çekmek"));
chckhobi.Items.Add(new ListItem("Pul Biriktirmek"));
chckhobi.Items.Add(new ListItem("Resim Yapmak"));
chckhobi.Items.Add(new ListItem("Müzik Dinlemek"));
chckhobi.Items.Add(new ListItem("Spor Yapmak"));
chckhobi.Items.Add(new ListItem("Futbol/Basketbol/Voleybol Oynamak"));
}
protected void btnkay_Click(object sender, EventArgs e)
{
if (txtsifre.Text == string.Empty || txtsifre2.Text == string.Empty)
{
lbl.Text = "Lütfen diğer şifrenizi de giriniz...";
}


else if (txtsifre.Text == string.Empty && txtsifre2.Text==string.Empty)
{
lbl.Text = "Lütfen şifrelerinizi giriniz...";
}
else if (txtsifre.Text != txtsifre2.Text)
{
lbl.Text = " Şifreniz Eşleşmedi, Lüften Tekrar Giriniz! ";
}




else if (txtsifre.Text == txtsifre2.Text)
{


string cinsiyt = string.Empty;
if (rdcins.SelectedValue == "Bay")
{
cinsiyt = "bey";
}
else if (rdcins.SelectedValue == "Bayan")
{
cinsiyt = "hanım";
}
lbl.Text = "Sayın " + txtad.Text + " " + cinsiyt + "<br>" + " E-mailiniz: " + txtmail.Text + "<br>" + " Şifreniz: " + txtsifre.Text + "<br>" + " Doğum Tarihiniz: " + ddlgun.SelectedValue + "." + ddlay.SelectedValue + "." + ddlyil.SelectedValue + "<br>" + " Yaşadığınız Şehir " + ddlsehir.SelectedValue + "<br>" + "Hobileriniz :" + "<br>";

for (int i = 0; i < chckhobi.Items.Count; i++)
{
if (chckhobi.Items.Selected == true)
{
lbl.Text += chckhobi.Items + "<br>";
}
}

}

}
protected void btntem_Click(object sender, EventArgs e)
{
lbl.Text = string.Empty;
}
}
ASPX Kısmı
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
height: 23px;
width: 201px;
}
.style2
{
width: 328px;
}
.style3
{
width: 201px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="4px" bgcolor="#ffa" cellpadding="10" cellspacing="10">
<tr><td class="style1"><strong>Adınız:</strong></td><td class="style2">
<asp:TextBox ID="txtad" runat="server" AutoPostBack="True"></asp:TextBox>
</td></tr>
<tr><td class="style3"><strong>Soyadınız:</strong></td><td class="style2">
<asp:TextBox ID="txtsoyad" runat="server" AutoPostBack="True"></asp:TextBox>
</td></tr>
<tr><td class="style3"><strong>E-mail:</strong></td><td class="style2">
<asp:TextBox ID="txtmail" runat="server" AutoPostBack="True"></asp:TextBox>
</td></tr>
<tr><td class="style3"><strong>Şifreniz:</strong></td><td class="style2">
<asp:TextBox ID="txtsifre" runat="server" AutoPostBack="True"></asp:TextBox>
</td></tr>
<tr><td class="style3"><strong>Tekrar Şifre:</strong></td><td class="style2">
<asp:TextBox ID="txtsifre2" runat="server" AutoPostBack="True"></asp:TextBox>
</td></tr>
<tr><td class="style1"><strong>Dogum Tarihi:</strong></td><td class="style2">
<asp:DropDownList ID="ddlgun" runat="server" Height="19px" Width="78px"
AutoPostBack="True">
</asp:DropDownList>
&nbsp;
<asp:DropDownList ID="ddlay" runat="server" AutoPostBack="True">
</asp:DropDownList>
&nbsp;&nbsp;
<asp:DropDownList ID="ddlyil" runat="server" AutoPostBack="True">
</asp:DropDownList>
</td></tr>
<tr><td class="style3"><strong>Yaşadığınız Şehir:</strong></td><td class="style2">
<asp:DropDownList ID="ddlsehir" runat="server" AutoPostBack="True">
</asp:DropDownList>
</td></tr>
<tr><td class="style3"><strong>Cinsiyetiniz:</strong></td><td class="style2">
<asp:RadioButtonList ID="rdcins" runat="server" AutoPostBack="True">
</asp:RadioButtonList>
</td></tr>
<tr><td class="style3"><strong>Hobileriniz:</strong></td><td class="style2">
<asp:CheckBoxList ID="chckhobi" runat="server" AutoPostBack="True">
</asp:CheckBoxList>
</td></tr>

<tr><td class="style3">&nbsp;</td><td class="style2">
<asp:Button ID="btnkay" runat="server"
style="color: #FFFFFF; font-weight: 700; background-color: #996600"
Text="Kaydet" onclick="btnkay_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btntem" runat="server"
style="font-weight: 700; color: #FFFFFF; background-color: #996600"
Text="Temizle" onclick="btntem_Click" />
<br />
<asp:Label ID="lbl" runat="server"></asp:Label>
</td></tr>
</table>
</div>
</form>
</body>
</html>

“ASP.Net” sayfasına dön