|
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));
}
}
}
|