是从数据库提取数据呢
还是静态写?
这里有静态写的方法
自己去看
http://bbs.bc-cn.net/viewthread.php?tid=121738&star=at#
哦
我找到了
你看一下
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class zzjgwh : System.Web.UI.Page
{
Class1 mycon = new Class1();
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "";
if (!IsPostBack)
{
Session["mm"] = "zzjgwh";
databind();
Butt_add.Attributes.Add("onClick", "javascript: return confirm('你确定要添加该信息吗?')");
Butt_change.Attributes.Add("onClick", "javascript: return confirm('你确定要修改该信息吗?')");
Butt_agin.Attributes.Add("onClick", "javascript: return confirm('你确定要清除该信息吗?')");
#region TreeView
//DataSet ds = mycon.myDataSet("SELECT * FROM DEPART");
//TreeNode tn = null;
//this.treeNode(ds.Tables[0], "00", tn);
GridViewbind();
#endregion
string sqlstr1 = "select time1 from a";
DataSet ds = null;
ds = mycon.myDataSet(sqlstr1);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
#region TreeView绑定
private void GridViewbind()
{
string sql = "select * from DEPART where 上级部门编号=01";
DataSet ds = mycon.myDataSet(sql);
this.GridView1.DataSource = ds.Tables[0].DefaultView;
this.GridView1.DataBind();
}
private void treeNode(DataTable table, String parentid, TreeNode pn)
{
DataRow[] dr = table.Select("上级部门编号=" + parentid);
if (dr.Length > 0)
{
foreach (DataRow d in dr)
{
TreeNode tb = new TreeNode();
tb.Text = d["部门名称"].ToString();
if (pn == null)
{
this.TreeView1.Nodes.Add(tb);
}
else
{
pn.ChildNodes.Add(tb);
}
treeNode(table, d["部门编号"].ToString(), tb);
}
}
}
#endregion
#region 数据绑定
public void databind()
{
string sqlstr = "select * from DEPART";
DataSet ds = null;
ds = mycon.myDataSet(sqlstr);
GridView1.DataSource = ds;
GridView1.DataBind();
}
#endregion
#region 节点显示信息
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
string sql = "select * from DEPART where 上级部门编号=(select 部门编号 from DEPART where 部门名称= '" + this.TreeView1.SelectedValue.ToString() + "')";
DataSet ds = null;
ds = mycon.myDataSet(sql);
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
else
{
Label1.Text = "<script language='javascript'>alert('没有数据!');</script>";
return;
}
}
#endregion
#region 查看信息
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
#region 法一
//GridViewRow sel = GridView1.Rows[e.NewSelectedIndex];
//string id = sel.Cells[2].Text.ToString();
//string sqlstr = "select * from DEPART where 部门编号=" + id;
//DataSet ds = null;
//ds = mycon.myDataSet(sqlstr);
//GridView1.DataSource = ds;
//GridView1.DataBind();
//if (ds.Tables[0].Rows.Count > 0)
//{
// Txt_bh.Text = ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][0].ToString();
// Txt_sjbh.Text = ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][1].ToString();
// Txt_mc.Text = ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][2].ToString();
//}
//Panel1.Visible = true;
//GridView1.EditIndex = -1;
//databind();
#endregion
#region 法二
try
{
Txt_bh.Text = GridView1.SelectedRow.Cells[2].Text;
Txt_sjbh.Text = GridView1.SelectedRow.Cells[3].Text;
Txt_mc.Text = GridView1.SelectedRow.Cells[4].Text;
Txt_bz.Text = Server.HtmlDecode(GridView1.SelectedRow.Cells[5].Text);
}
catch (Exception exl)
{
Label1.Text = "<script language='javascript'>alert('" + exl.Message + "');</script>";
}
Panel1.Visible = true;
#endregion
}
#endregion
}