ListBox - DropDownList Uygulamaları

 

Uygulama 1:Komut İle Eleman Ekleme

 

TextBox'a girilen değeri ekle butonuna basarak ListBox'a ekleyelim ve Temizle butonuna basıldığında ListBoxdaki elemanları tamamını silme işini yapalım.

Kod yardımıyla eleman ekleme ve silme işlemini yapalım.ListBox1.Items.Add(TextBox1.Text); komutu ile ekleme işlemini yapılır.

 

Silme işlemi için ListBox1.Items.Clear();komutu kullanılır.

 

 

 

 

 

 

 

 

 

 

protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Add(TextBox1.Text);
}
protected void Button2_Click(object sender, EventArgs e)
{
ListBox1.Items.Clear();
}

 

 

Standart Kontroller Sayfasına Geri Dön

 

Uygulama 2: ListBoxlar arasında eleman aktarımı.

 

Seçtiğimiz elemanı diğer listbox'a aktaralım.Aktarırken de aktarılan eleman ilkinden silinsin.

 

Seçtiğimiz elemanı diğer listbox'a aktardık.Bu işlem için ListBox2.Items.Add(ListBox1.SelectedItem.ToString()); komutunu kullandık.

 

Aktarımı yaparkende eski yerinden silmek için ListBox1.Items.Remove (ListBox1.SelectedItem.ToString()); komutunu kullandık.

 

 

 

 

 

 

 

protected void Button1_Click(object sender, EventArgs e)
{
ListBox2.Items.Add(ListBox1.SelectedItem.ToString());
ListBox1.Items.Remove(ListBox1.SelectedItem.ToString());
}
protected void Button2_Click(object sender, EventArgs e)
{
ListBox1.Items.Add(ListBox2.SelectedItem.ToString());
ListBox2.Items.Remove(ListBox2.SelectedItem.ToString());
}

 

Standart Kontroller Sayfasına Geri Dön

 

Uygulama 3: İl-İlçe Gösterimi

 

 

İl seçimi yapınca alt tarafta ilçe için başka bir dropdownlist ile listelenecektir.Bu işlem için visible özelliğinden faydalandık.İle göre ilçelerin gelmesi içinde if yapısında faydalandık

 

 

 

 

 

 

 

DropDownList2.Visible = true;

if (DropDownList1.SelectedIndex==1)
{
DropDownList2.Items.Clear(); //önceki seçimden eklenen ilçeleri temizler.
DropDownList2.Items.Add("Polatlı");
DropDownList2.Items.Add("Ostim");
DropDownList2.Items.Add("Çankaya");
}
else if (DropDownList1.SelectedIndex==2)
{
DropDownList2.Items.Clear();
DropDownList2.Items.Add("Kadıköy");
DropDownList2.Items.Add("Kartal");
DropDownList2.Items.Add("Pendik");
}
else if (DropDownList1.SelectedIndex == 3)
{
DropDownList2.Items.Clear();
DropDownList2.Items.Add("Meram");
DropDownList2.Items.Add("Karatay");
DropDownList2.Items.Add("Selçuklu");
}
else
{
DropDownList2.Visible = false;
}

 

 

Standart Kontroller Sayfasına Geri Dön

 

 

Uygulama 4: Seçilen ürünün fiyat bilgisi

 

 

Seçilen ürünün adı ve fiyat bilgisini items eklerken text ve value değerlerinden alıyoruz.

seçilem item valuesi için:DropDownList1.SelectedItem.Text; komutunu kullandık.

 

 

 

 

 

 

 

 

 

 

TextBox1.Text = DropDownList1.SelectedItem.Text;
TextBox2.Text = DropDownList1.SelectedValue+" TL";

 

 

Standart Kontroller Sayfasına Geri Dön

 

Uygulama 5: ListBox' a eleman ekleme-silme-arama

 

 

ListBox1.Items.FindByText(TextBox1.Text) komutu ile listbox ta arama yaptık.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Add(TextBox1.Text);
}
protected void Button2_Click(object sender, EventArgs e)
{
ListBox1.Items.Remove(ListBox1.SelectedItem);
}
protected void Button3_Click(object sender, EventArgs e)
{
ListBox1.Items.Clear();
}
protected void Button4_Click(object sender, EventArgs e)
{

ListBox1.ClearSelection();
ListBox1.Items.FindByText(TextBox1.Text).Selected = true;


}

 

Standart Kontroller Sayfasına Geri Dön

 

Uygulama 6: Pizza Sipariş Ekranı

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = DropDownList1.SelectedItem.Text;
TextBox2.Text = DropDownList1.SelectedItem.Value;
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox3.Text = DropDownList2.SelectedItem.Text;
TextBox4.Text = DropDownList2.SelectedItem.Value;
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox5.Text = DropDownList3.SelectedItem.Text;
TextBox6.Text = DropDownList3.SelectedItem.Value;
}
protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox7.Text = DropDownList4.SelectedItem.Text;
TextBox8.Text = DropDownList4.SelectedItem.Value;
}
protected void Button1_Click(object sender, EventArgs e)
{
int toplam, hamur, sebze, peynir, icecek;
hamur = Convert.ToInt32(TextBox2.Text);
peynir = Convert.ToInt32(TextBox4.Text);
sebze = Convert.ToInt32(TextBox6.Text);
icecek = Convert.ToInt32(TextBox8.Text);
toplam = hamur + peynir + sebze + icecek;
Label1.Text = "Ödenecek Tutar:"+toplam.ToString()+" TL dir";
ListBox1.Items.Clear();
ListBox1.Items.Add(TextBox1.Text+" + "+TextBox3.Text+" + "+TextBox5.Text+" + "+TextBox7.Text);
}

 

 

Standart Kontroller Sayfasına Geri Dön

 

Uygulama 7: Gün Ay Yıl Seçimi

 

For komutu ile dropdownlist elemanlarını doldurduk.Bu işlemi sayfanın yüklenme olayına yazdık.

 

 

 

 

 

 

protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.Items.Add("gün seç");
DropDownList2.Items.Add("ay seç");
DropDownList3.Items.Add("yıl seç");
for (int i = 1; i <= 30; i++)
{
DropDownList1.Items.Add(i.ToString());
}
for (int i = 1; i <= 12; i++)
{
DropDownList2.Items.Add(i.ToString());
}
for (int i = 1930; i <= 2015; i++)
{
DropDownList3.Items.Add(i.ToString());
}
}

 

 

Standart Kontroller Sayfasına Geri Dön

 

Uygulama 8: DropDownList nesnelerini tek ve çift sayılarla doldurma.

 

 

DropDownList Nesnelerini tek ve çift sayılarla doldurmak içinMod alma operatörü ve for döngüsünden faydalanıyoruz.For döngüsü ile eklenecek sayıları oluşturuyoruz.Mod alma operatörü sayının ile tek mi çift mi olduğuna karar veriyoruz ve ona göre ekleme işlemini yapıyoruz

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

for (int i = 1; i <= 100; i++)
{
if (i%2==0)
{
ListBox2.Items.Add(i.ToString());
}
else
{
ListBox1.Items.Add(i.ToString());
}
}

 

 

Standart Kontroller Sayfasına Geri Dön

 

Uygulama 9: Yemek Siparişi

 

 

Seçilen menüyü listboxa ekledik.RadioButonlarda uygulanacak indirimi seçtik ve o oranda indirim uyguladık.Özel istekler bölümünde de istenilen durumu seçince fiyata ekedik.

Hesapla butonuna basıncade ödenecek tutar hesapladı.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox1.Items.Add(new ListItem(DropDownList1.SelectedItem.Text,DropDownList1.SelectedItem.Value));
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = ListBox1.SelectedItem.Text;
TextBox2.Text = ListBox1.SelectedItem.Value;
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox1.Items.Add(new ListItem(DropDownList2.SelectedItem.Text, DropDownList2.SelectedItem.Value));
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox1.Items.Add(new ListItem(DropDownList3.SelectedItem.Text, DropDownList3.SelectedItem.Value));
}
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex);
}
protected void Button2_Click(object sender, EventArgs e)
{

}
protected void Button2_Click1(object sender, EventArgs e)
{
int toplam = 0;
for (int i = 0; i < ListBox1.Items.Count; i++)
{
toplam = Convert.ToInt32((ListBox1.Items[i].Value.ToString())) + toplam;
}
if (RadioButtonList1.SelectedIndex == 0)
{
toplam = toplam * 95 / 100;
}
else if (RadioButtonList1.SelectedIndex == 1)
{
toplam = toplam * 90 / 100;
}
else if (RadioButtonList1.SelectedIndex == 2)
{
toplam = toplam * 80 / 100;
}
if (CheckBox1.Checked == true)
{
toplam = toplam + 10;
}
if (CheckBox2.Checked == true)
{
toplam = toplam + 15;
}
Label1.Text = toplam.ToString()+" TL";
}

 

 

Standart Kontroller Sayfasına Geri Dön

 

 

 

 

Web hosting by Somee.com