Merhaba arkadaşlar,
Bu benim ilk yazım olacak, 1 aydır stajda olduğumdan dolayı blogumu açmama rağmen yazı paylaşamamıştım. Stajımı İçişleri Bakanlığı Bilgi İşlem Dairesi Başkanlığı’nda yaptım. 20 iş günü süren stajımda .NET + MSSQL ile E – Ticaret Projesi geliştirdim, tabi ki süre kısa olduğundan ve ilk defa kullandığım bir platform olduğundan tamamen bitmedi. Neyse artık konuya geçiyorum.
Kodu yazarken veritabanı bağlantısı yapmayacağım için değerleri elle gireceğim, siz veritabanı bağlantısı ile daha kullanışlı bir kod hazırlayabilirsiniz. Bu kodu İl / İlçe seçiminde ya da Otobüs Firması Kalkış / Varış seçiminde kullanabilirsiniz.
DropDownListlerimizin bulunacağı aspx dosyamızda bu kodu ekliyoruz.
1 2 3 4 5 6 7 8 9 10 11 12 |
<asp:DropDownList ID="BirinciDropDownList" runat="server" OnSelectedIndexChanged="BirinciDropDownList_SelectedIndexChanged" AutoPostBack="True"> <asp:ListItem Value="0">Kategori Seçiniz</asp:ListItem> <asp:ListItem Value="0">----------------</asp:ListItem> <asp:ListItem Value="1">İstanbul-Otogar</asp:ListItem> <asp:ListItem Value="2">Ankara-Otogar</asp:ListItem> <asp:ListItem Value="3">Karabük-Otogar</asp:ListItem> <asp:ListItem Value="4">Bolu-Otogar</asp:ListItem> <asp:ListItem Value="5">Mengen-Otogar</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="IkinciDropDownList" runat="server" OnSelectedIndexChanged="IkinciDropDownList_SelectedIndexChanged" AutoPostBack="true" > <asp:ListItem Value="0">---------------</asp:ListItem> </asp:DropDownList> |
Daha sonra aspx.cs dosyamıza geçerek aşağıdaki kodu ekliyoruz.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
protected void IkinciDropDownList_SelectedIndexChanged(object sender, EventArgs e) { Session.Add("Kalkis", BirinciDropDownList.SelectedItem.Value.ToString()); Session.Add("Varis", this.IkinciDropDownList.SelectedItem.Value.ToString()); Response.Redirect("SatinAl.aspx"); } protected void BirinciDropDownList_SelectedIndexChanged(object sender, EventArgs e) { IkinciDropDownList.Items.Clear(); IkinciDropDownList.Items.Add(new ListItem("---------", "0")); if(this.BirinciDropDownList.SelectedItem.Value.ToString() == "1") { IkinciDropDownList.Items.Add(new ListItem("Ankara-Otogar", "2")); IkinciDropDownList.Items.Add(new ListItem("Karabük-Otogar", "3")); IkinciDropDownList.Items.Add(new ListItem("Bolu-Otogar", "4")); } if(this.BirinciDropDownList.SelectedItem.Value.ToString() == "2") { IkinciDropDownList.Items.Add(new ListItem("İstanbul-Otogar", "1")); IkinciDropDownList.Items.Add(new ListItem("Karabük-Otogar", "3")); IkinciDropDownList.Items.Add(new ListItem("Bolu-Otogar", "4")); } if(this.BirinciDropDownList.SelectedItem.Value.ToString() == "3") { IkinciDropDownList.Items.Add(new ListItem("Ankara-Otogar", "2")); IkinciDropDownList.Items.Add(new ListItem("İstanbul-Otogar", "1")); IkinciDropDownList.Items.Add(new ListItem("Bolu-Otogar", "4")); } if(this.BirinciDropDownList.SelectedItem.Value.ToString() == "4") { IkinciDropDownList.Items.Add(new ListItem("Ankara-Otogar", "2")); IkinciDropDownList.Items.Add(new ListItem("İstanbul-Otogar", "1")); IkinciDropDownList.Items.Add(new ListItem("Mengen-Otogar", "5")); } if(this.BirinciDropDownList.SelectedItem.Value.ToString() == "5") { IkinciDropDownList.Items.Add(new ListItem("Bolu-Otogar", "4")); } } |
En son olarak yönlendirileceğimiz SatinAl.aspx.cs dosyamıza geçerek Page_Load fonksiyonumuza aşağıdaki kodu ekliyoruz.
1 2 3 4 5 6 7 8 9 |
if(Session["Kalkis"] != null) { Response.Write("Kalkış -> " + Session["Kalkis"].ToString() + " Varış ->" + Session["Varis"].ToString()); } else { Response.Write("Seçim Yapmadınız.."); } |
Windows Sunucum olmadığından dolayı size demo yüklemesi yapamıyorum ama localhost’ta deneyerek projenize dahil edebilirsiniz.
Sabırla okuduğunuz için teşekkür ederim. Yardım istediğiniz bir konu olduğunda mserdarkayar@gmail.com mail adresine ya da facebook.com/mserdarkayar hesabıma mesaj gönderebilirsiniz. Elimden geldiğince, bilgim olduğu sürece yardımcı olmaya çalışırım.
Herkese iyi günler.. 🙂
Bence Asp.Net ten uzaklaşırsanız iyi olur. Eski kafadan devam etmeyin gelecekte asp.net olmıcak. Şu an bile neredeyse bitmiş durumda.