Müdavim Girişi

E-Posta
Parola

Ücretsiz Kayıt Ol


Online Müdavimler (0 Kişi)
  • Online Kişi Bulunmadı

Yazar Hakkında
x
İsmail Kocacan
İsmail Kocacan is experienced on many development platforms and continues to learn technologies. Since the age of 16-17, dealing with software technologies. And continuous learning, teaching, research, continues to develop.
Hiyerarşik Tasarım(Kategorileme) Asp.net Uygulaması

 Daha önceki makalemde Hiyerarsik verileri tutmak için nasil bir tasarim yapabilecegimiz anlatmistim.Simdi ise onun Web Uygulamasi üzerinde gösterimini anlaticam.Asp.net ile Treeview nesnesinde göstericez.

Hiyerarsi.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="hiyerarsi.aspx.cs" Inherits="HiyerarsiTestwebx.hiyerarsi" %>
 
<!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>Hiyerarsik Kategorileme</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:TreeView ID="TreeView1" runat="server" ImageSet="XPFileExplorer"
            NodeIndent="15" onselectednodechanged="TreeView1_SelectedNodeChanged">
           <ParentNodeStyle Font-Bold="False" />
            <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
            <SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False"
                HorizontalPadding="0px" VerticalPadding="0px" />
            <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black"
                HorizontalPadding="2px" NodeSpacing="0px" VerticalPadding="2px" />
        </asp:TreeView>
   
    </div>
    </form>
</body>
</html>

 
Hiyerarsi.aspx.cs

namespace HiyerarsiTestwebx
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
 
    public partial class hiyerarsi : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.AnaKategorileriGetir();
            }
        }
 
 
        protected void AnaKategorileriGetir()
        {
            SqlConnection sconnx = new SqlConnection("server=.\\SQLExpress; database=KOBAY; integrated security=sspi");
            sconnx.Open();
 
            DataTable dtx = new DataTable();
            SqlCommand scommx = new SqlCommand("select * from Kategoriler Where UstKategoriNo=0", sconnx);
            dtx.Load(scommx.ExecuteReader());
 
            foreach (DataRow rowItemx in dtx.Rows)
            {
                string KategoriNo = rowItemx["KategoriNo"].ToString();
                string KategoriAd=rowItemx["KategoriAd"].ToString();
                TreeView1.Nodes.Add(new TreeNode(KategoriAd, KategoriNo));
            }
            dtx.Dispose();
            scommx.Dispose();
            sconnx.Dispose();
        }
 
 
        protected void AltKategorileriGetir(int UstKategoriNo)
        {
            SqlConnection sconnx = new SqlConnection("server=.\\SQLExpress; database=KOBAY; integrated security=sspi");
            sconnx.Open();
 
            DataTable dtx = new DataTable();
            SqlCommand scommx = new SqlCommand("select * from Kategoriler Where UstKategoriNo=" + UstKategoriNo, sconnx);
            dtx.Load(scommx.ExecuteReader());
 
            TreeView1.SelectedNode.ChildNodes.Clear();
            foreach (DataRow rowItemx in dtx.Rows)
            {
                string KategoriNo = rowItemx["KategoriNo"].ToString();
                string KategoriAd = rowItemx["KategoriAd"].ToString();
                TreeView1.SelectedNode.ChildNodes.Add(new TreeNode(KategoriAd, KategoriNo));
            }
            dtx.Dispose();
            scommx.Dispose();
            sconnx.Dispose();
        }
 
        protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
        {
            string KategoriNo = TreeView1.SelectedNode.Value.Trim();
            this.AltKategorileriGetir(int.Parse(KategoriNo));
        }
    }
}
 

Sonuc

Uygulamaya Ait Kaynak Kodlari Buradan indirebilirsiniz
Devami Gelecek...
ismailkocacan@gmail.com
Ismail Kocacan


Kategori : Asp.Net | 27.09.2010 15:20:00  | 5615 defa okundu  | 1 Yorum |

Yazara Ait Diğer Makaleler(51) Makaleye Yapılan Yorumlar Yorum Yazıcam
Emre AKPINAR | 27.09.2010 16:22:00
Abi eline saglık cok yararlı bir makale olmuş.Treewiew e bu sekilde vt den aktarma yapılacagını ogrendiğimiz iyi oldu.kategori ve alt kategorileri bu sekilde ayırıp bir duzene sokabiliriz.saolsın abi makale icin
Ara
 
Anket
Hangi VeriTabanı Yönetim Sistemini Kullanıyorsunuz ?