根据的数据库的level关系绑定数据到控件上.
1/13
QA:根据的数据库的level关系绑定数据到控件上.
<a target=_blank
style="cursor:hand" onclick="window.open('Doc_DataSchemaSubjectList.aspx',
'',
'height=400, width=360,
scrollbars=1,resizable=1')
">选择</a>
图示: 数据库:
程序画面原型:
<asp:TreeView ID="tvThematic" runat="server" Height="290px"
ImageSet="News" ShowCheckBoxes="Leaf"
Width="322px">
</asp:TreeView>
程序Code:
/// <summary>
/// tree view binding
/// </summary>
private void PopulateNodes()
{
DataSet dst = GetTreeViewData();
if (dst != null && dst.Tables.Count > 0)
{
foreach (DataRow topRow in dst.Tables[0].Rows)
{
TreeNode topNod = new TreeNode((string)topRow["thematicName"]);
tvThematic.Nodes.Add(topNod);
foreach (DataRow masterRow in topRow.GetChildRows("Children1"))
{
TreeNode masterNode = new TreeNode((string)masterRow["thematicName"]);
topNod.ChildNodes.Add(masterNode);
foreach (DataRow subRow in masterRow.GetChildRows("Children2"))
{
TreeNode subNode = new TreeNode((string)subRow["thematicName"]);
masterNode.ChildNodes.Add(subNode);
}
masterNode.Collapse();
}
topNod.Collapse();
}
}
}
/// <summary>
/// return relation tables dataset
/// </summary>
/// <returns></returns>
private DataSet GetTreeViewData()
{
DataSet dtReceiver = Select("");
return dtReceiver;
}
/// <summary>
/// SELECT
/// </summary>
/// <param name="selectCondition">筛选条件,可以为空</param>
/// <returns>
/// 成功:信息列表(DataSet);
/// 失败:错误信息。
/// </returns>
public DataSet Select(string boName)
{
try
{
string strsql = "Doc_ThematicType_Select";
SqlParameter[] sqlparam =
{
//new SqlParameter ("@Condition", SqlDbType.VarChar)
};
//int i = 0;
//sqlparam[i++].Value = (selectCondition == null || selectCondition == "") ? "1 = 1" : selectCondition;
SqlDBAccess dbaccess = new SqlDBAccess(); //需要引用iFlytek.BaseClass.dll 在DLL文件夹中
DataSet ds = (DataSet)dbaccess.ExecuteDataset(boName, CommandType.StoredProcedure, strsql, sqlparam);
//DataTable dt = ds.Tables[0];
ds.Relations.Add("Children1",
ds.Tables[0].Columns["id"],
ds.Tables[1].Columns["superId"]);
ds.Relations.Add("Children2",
ds.Tables[1].Columns["id"],
ds.Tables[2].Columns["superId"]);
return ds;
}
catch (Exception e)
{
throw e;
}
}
QA:如何判断传入的对象控件是哪一个?(dropdownlist 还是 listbox)?
is 运算符用于检查对象的运行时类型是否与给定类型兼容
public void judgeObject(object objects)
{
if (objects is DropDownList) {
((DropDownList)objects).Items.Add(item);
//TO DO IT
}
Else if (objects is ListBox){
((ListBox)objects).Items.Add(item);
//TO DO IT
}
}
存储过程
CREATE PROCEDURE [dbo].[Doc_ThematicType_Select]
AS
SELECT * FROM Doc_ThematicType WHERE LEVAL = 1
SELECT * FROM Doc_ThematicType WHERE LEVAL = 2
SELECT * FROM Doc_ThematicType WHERE LEVAL = 3
GO
// 移除节点
TreeNode delNode = TreeView1.GetNodeFromIndex(TreeView1.SelectedNodeIndex);
delNode.Remove();
// 等效代码:
// TreeView1.GetNodeFromIndex(TreeView1.SelectedNodeIndex).Remove();
QA:如何点击“期刊浏览”之后,再点击“值班管理”时,让“期刊浏览”节点处于Collapse状态?
protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
foreach (TreeNode node in TreeView1.Nodes)
{
if (node.Text.Equals(e.Node.Text))
{
node.Expand();
}
else
{
node.Collapse();
}
}
}
QA:如何使用Hyperlinks Column