19 Kasım 2013 Salı

MultiView Kullanma


MultiView in içine viewler  eklenir.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class multiviewkullanma : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1 .SelectedItem .ToString ()=="elma" ){

            MultiView1.ActiveViewIndex = 0;

        }else if (DropDownList1 .SelectedItem .ToString ()=="armut" ){

            MultiView1.ActiveViewIndex = 1;
        }
        else if (DropDownList1.SelectedItem.ToString() == "cilek")
        {

            MultiView1.ActiveViewIndex = 2;
       
       
        }else {

            MultiView1.ActiveViewIndex = -1;
        }  
}}

Kodun Çalıştırılmış



Hidden Field Kullanımı Girilen Veriyi Saklama ve Gösterme

Aşağıdaki kodlar Gizle ve Göster butonlarının içine yazılır.Gizle ve Göster butonu hiddenfield i yönetir.

protected void Button1_Click(object sender, EventArgs e)
    {
        HiddenField1.Value = TextBox1.Text + "---" + TextBox2.Text;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Write(HiddenField1.Value);

    }



Kodun Çalıştırılmış Hali


Radiobutona Sayfa yüklendiğinde Ders Ekletme ve Seçilen Dersi Gösterme

                   
      Aşağıdaki kodlar yazılır.      
                                            
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) // sayfa ilk yüklendiğinde
        {
            RadioButtonList1.Items.Add("kimya");
            RadioButtonList1.Items.Add("biyoloji");
         

        }
    }
 
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Text = RadioButtonList1.SelectedValue.ToString();

    }


Kodun Çalıştırılmış Hali 


Checkboxlist Çoklu Seçimleri Gösterme ve Seçilen Menülerin Fiyatlarını Toplama

Checkboxlist e değer ekleme şekilde görüldüğü gibi yapılır.

















Aşağıdaki kodları hesapla butonuna yazınız.


  protected void Button1_Click(object sender, EventArgs e)
    {
        int i = 0;
        int toplam = 0;
        Label1.Text = "";
        Label2.Text = "";


        for (i = 0; i < CheckBoxList1.Items.Count; i++)
        {
            if (CheckBoxList1.Items[i].Selected)
            {
                Label1.Text += CheckBoxList1.Items[i] + " = " + CheckBoxList1.Items[i].Value + " ; " ;

                toplam += Convert.ToInt32(CheckBoxList1.Items[i].Value);
                Label2.Text = toplam.ToString("C"); // C burda tl simgesini göstermek için kullanılmıştır .

            }
        }

    }

Kodun Çalıştırılmış Hali 


DropDownList e Girilen Değeri Label e Yazdırma


Aşağıdaki kodlar DropDownList1_SelectedIndexChanged in içine yazılır.



Dropdownlist in Properties inden AutoPostPack seçeneği true olacak.

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label2.Text = DropDownList1.SelectedItem.Text};
}

Kodun Çalıştırılmış Hali 


2 Kasım 2013 Cumartesi

Ürün indirimi Checkbox Kontrolü

Aşağıdaki kodları hesapla butonuna yazınız.
    protected void Button1_Click(object sender, EventArgs e)
    {
        double fiyat, kdv, toplam ;
       fiyat = Convert.ToDouble(TextBox1.Text);
       kdv= Convert.ToDouble(TextBox2.Text);
       toplam = fiyat + ( fiyat * kdv / 100) ;

       if (CheckBox1.Checked == true)
       {
        toplam = toplam - toplam *0.05 ;
       }
       Label1.Text = "ürününün toplam fiyatı " + toplam;
 }

Kodun Çalıştırılmış Hali 


Klavyeden 0 Girilinceye Kadar Girilen Sayıların Toplamını ve Aritmetik Ortalamasını Bulma

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class klavyedengirilensayı : System.Web.UI.Page
{

    public static double  toplam, gort, i, sayi;
   
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)// ilk defa yüklendiyse bunu yap
        {

            Label1.Text = "";
            Label2.Text = "";
            toplam = 0;
            gort  = 0;
            i = 0;     

        }
    }


    protected void Button2_Click(object sender, EventArgs e)
    {
        sayi = Convert.ToDouble(TextBox1.Text);

        if (sayi == 0)
        {
            Button2.Enabled = false;

        }
        else {
       
        i++;

        ListBox1.Items.Add(sayi.ToString ());// sayıları listbox a ekle


        toplam = toplam + sayi;
        gort = toplam / i;
       
        }

        Label2.Text = gort.ToString();

        Label1.Text = toplam.ToString();

    }
}


Kodun Çalıştırılmış Hali