下拉框dropdownlist开发学习,

下拉框与树形的结合,用于多张表的关联
StandardType.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StandardType.aspx.cs" Inherits="hbproject.standard.StandardType" %>

<%@ Register Assembly="Infragistics35.WebUI.UltraWebGrid.v9.1, Version=9.1.20091.1015, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace
="Infragistics.WebUI.UltraWebGrid" TagPrefix="igtbl" %>
<!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>ManagerType</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<link href="../UI/dialogStyle.css" type="text/css" rel="stylesheet">
<script type="text/javascript">
function Add() {
var row
= igtbl_addNew("dgList", 0);
return false;
}

function Del() {
var grid
= igtbl_getGridById("dgList");
var cell
= grid.getActiveCell();
if (cell != null) {
if (cell.Row.getCellFromKey("STANDARD_TYPE_ID").getValue() != null) {
if (document.all.txtDeldg.value == "") {
document.all.txtDeldg.value
= cell.Row.getCellFromKey("STANDARD_TYPE_ID").getValue();
}
else {
document.all.txtDeldg.value
+= "$" + cell.Row.getCellFromKey("STANDARD_TYPE_ID").getValue();
}
cell.Row.Element.style.display
= "none";
}
else {
cell.Row.deleteRow();
}
}
else {
alert(
'请选择要删除的行!');
}
return false;
}
function Save() {
var grid
= igtbl_getGridById("dgList");
return true;
// grid.getActiveCells();
//var hTbl = grid.GetRootTable().getElement();
//var rows = hTbl.rows;

// for(var i= 0;i<grid.rows.Length ; i++)
// {
// for(var j=i+1;j<grid.rows.Length;j++)
// {
//// if()
//// {
////
//// }
// }
// }
// alert('请选择要删除的行!');
// return false;
}
</script>
<style type="text/css">
.style2
{
width:
23%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="height: 15px">
<tr>
<td align="right" style="padding-right: 2px" class="style2">
<input class="MDButton" onclick="Add();" type="button" value="添加" />
<input class="MDButton" onclick="Del();" type="button" value="删除" />
<asp:Button ID="btnSave" runat="server" Text="保存" CssClass="MDButton" OnClick="btnSave_Click">
</asp:Button>
<asp:TextBox ID="txtDeldg" runat="server" Style="display: none">
</asp:TextBox>
</td>
</tr>
</table>

<igtbl:UltraWebGrid ID="dgList" runat="server" Height="310px" Width="100%" OnInitializeLayout="dgList0_InitializeLayout">
<DisplayLayout AllowAddNewDefault="Yes" AllowColSizingDefault="Free" AllowDeleteDefault="Yes"
AllowUpdateDefault
="Yes" AutoGenerateColumns="False" BorderCollapseDefault="Separate"
CellClickActionDefault
="Edit" ColWidthDefault="140px" HeaderClickActionDefault="SortSingle"
Name
="dgList" RowHeightDefault="22px" RowSizingDefault="Free" SelectTypeCellDefault="Extended"
SelectTypeRowDefault
="Extended" TableLayout="Fixed" Version="3.00" ViewType="Hierarchical">
<AddNewBox>
<style backcolor="LightGray" borderstyle="Solid" borderwidth="1px">

</style>
<BoxStyle BackColor="LightGray" BorderWidth="1px" BorderStyle="Solid">
<BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px">
</BorderDetails>
</BoxStyle>
</AddNewBox>
<Pager>
<style backcolor="#46677D" borderstyle="Solid" borderwidth="1px">

</style>
<PagerStyle BackColor="#46677D" BorderWidth="1px" BorderStyle="Solid">
<BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px">
</BorderDetails>
</PagerStyle>
</Pager>
<HeaderStyleDefault BackColor="#86A6BC" BorderColor="#46677D" BorderStyle="Solid"
ForeColor
="Black" Height="35px" HorizontalAlign="Center">
<BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" />
</HeaderStyleDefault>
<RowSelectorStyleDefault BackColor="#E2EAEF">
</RowSelectorStyleDefault>
<FrameStyle BorderColor="#46677D" BorderStyle="Solid" BorderWidth="1px" Cursor="Default"
Font
-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="310px" Width="100%">
</FrameStyle>
<FooterStyleDefault BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px">
<BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" />
</FooterStyleDefault>
<ActivationObject BorderStyle="Dotted">
</ActivationObject>
<GroupByBox>
<style backcolor="#B5CFF7">

</style>
<BandLabelStyle BackColor="#6372D4" ForeColor="White">
</BandLabelStyle>
<BoxStyle BackColor="#B5CFF7">
</BoxStyle>
</GroupByBox>
<SelectedHeaderStyleDefault BackColor="SteelBlue">
</SelectedHeaderStyleDefault>
<EditCellStyleDefault BorderStyle="None" BorderWidth="0px">
</EditCellStyleDefault>
<SelectedGroupByRowStyleDefault BackColor="#BCDAE8">
</SelectedGroupByRowStyleDefault>
<SelectedRowStyleDefault BackColor="SteelBlue" ForeColor="White">
</SelectedRowStyleDefault>
<RowAlternateStyleDefault BackColor="White" Height="22px">
</RowAlternateStyleDefault>
<RowStyleDefault BackColor="#E2EAEF" BorderColor="#46677D" BorderStyle="Solid" BorderWidth="1px"
ForeColor
="Black" HorizontalAlign="Center">
<Padding Left="3px" />
<BorderDetails ColorLeft="Gray" ColorTop="Gray" WidthLeft="0px" WidthTop="0px" />
</RowStyleDefault>
</DisplayLayout>
<Bands>
<igtbl:UltraGridBand>
<Columns>
<igtbl:UltraGridColumn BaseColumnName="STANDARD_TYPE_ID" Hidden="True" Key="STANDARD_TYPE_ID">
</igtbl:UltraGridColumn>
<igtbl:UltraGridColumn BaseColumnName="STANDARD_TYPE_NAME" HeaderText="类别名称" Key="STANDARD_TYPE_NAME"
Width
="100%">
<Header Caption="类别名称">
<RowLayoutColumnInfo OriginX="1"></RowLayoutColumnInfo>
</Header>
<Footer>
<RowLayoutColumnInfo OriginX="1"></RowLayoutColumnInfo>
</Footer>
</igtbl:UltraGridColumn>
</Columns>
<AddNewRow Visible="NotSet" View="NotSet">
</AddNewRow>
</igtbl:UltraGridBand>
</Bands>
</igtbl:UltraWebGrid>
</div>

</form>
</body>
</html>
StandardType.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Infragistics.WebUI.UltraWebNavigator;

namespace hbproject.standard
{
public partial class Standard : System.Web.UI.Page
{

Node selectNode;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.btnAdd.Attributes.Add("onclick","return Add();");
this.btnEdit.Attributes.Add("onclick","return Edit();");
this.btnDel.Attributes.Add("onclick", "return Del();");
this.addType.Attributes.Add("onclick","return ManageType();");

BindData();

//InitTree();


}

}



#region 初始化树
private void InitTree()
{
this.treeList.ClearAll();
//if (selectNum == null)
//{
// return;
//}
int selectNum = 0;
selectNum
= this.DropDownList_STANDARD_TYPE.SelectedIndex;
string select_type_name = this.DropDownList_STANDARD_TYPE.Items[selectNum].Text;
string select_type_id = this.DropDownList_STANDARD_TYPE.Items[selectNum].Value;
Node startNode
= new Node();
startNode.Tag
= "-1";

startNode.Text
= select_type_name;
//startNode.Text = "表名";

Node root
= treeList.Nodes.Add(startNode);
root.Expanded
= true;
DataTable dt
= dal.STANDARD_LIST().Tables[0];

//第一层节点遍历
DataView dv = dal.STANDARD_LIST().Tables[0].DefaultView;
dv.RowFilter
= "PARENT_STANDARD_ID is null AND STANDARD_TYPE = " + select_type_id + "";
for (int i = 0; i < dv.Count; i++)
{
Node nd
= new Node();
nd.Text
= dv[i]["TITLE"].ToString() + "" + dv[i]["CONTENT"].ToString();
nd.Tag
= dv[i]["STANDARD_ID"].ToString();
//大类标签
nd.TargetFrame = "dalei";

Node child
= startNode.Nodes.Add(nd);
child.Expanded
= true;

}
selectNode
= this.treeList.Nodes[0];
this.treeList.SelectedNode = selectNode;
GenerateTree(
this.treeList.Nodes, dt);
}
#endregion

#region GenerateTree

private void GenerateTree(Nodes nodes, DataTable dt)
{
if (nodes != null)
{
foreach (Node n in nodes)
{
DataView dv
= dt.DefaultView;
dv.RowFilter
= "PARENT_STANDARD_ID=" + n.Tag.ToString();
//dv.Sort = "ORDER_NUM ASC";

for (int i = 0; i < dv.Count; i++)
{
Node nd
= new Node();
nd.Text
= dv[i]["TITLE"].ToString() +""+ dv[i]["CONTENT"].ToString();
nd.Tag
= dv[i]["STANDARD_ID"].ToString();
//nd.HoverClass = dv[i]["LEVEL_FLAG"].ToString();
nd.TargetFrame = "child";
n.Nodes.Add(nd);
nd.Expanded
= true;
//if (SelNodeTagID == nd.Tag.ToString().Trim())
// {
// treeList.SelectedNode = nd;
// nd.Expand(true);
// }
}
if (n.Nodes.Count > 0)
{
GenerateTree(n.Nodes, dt);

}
else
{
//n.TargetFrame = "child";
}


}
}
}
#endregion

#region 初始化选择框
private void BindData()
{

this.DropDownList_STANDARD_TYPE.Items.Clear();
DataSet standard_type
= dal.STANDARD_TYPE_MANAGE_LIST();
this.DropDownList_STANDARD_TYPE.DataSource = standard_type.Tables[0].DefaultView;
this.DropDownList_STANDARD_TYPE.DataTextField = "STANDARD_TYPE_NAME";
this.DropDownList_STANDARD_TYPE.DataValueField = "STANDARD_TYPE_ID";
this.DropDownList_STANDARD_TYPE.DataBind();
//selectNum = this.DropDownList_STANDARD_TYPE.SelectedIndex;
if (standard_type.Tables[0].Rows.Count != 0)
{
InitTree();
}
else
{
this.treeList.ClearAll();
}

//this.DropDownList_STANDARD_TYPE.Items.Insert(0, new ListItem("请选择", ""));


//this.STANDARD_TYPE.SelectedItem.Value = standard_type.Tables[0].Rows[0]["STANDARD_TYPE_NAME"].ToString();



}
#endregion
//protected void btnAdd_Click(object sender, ImageClickEventArgs e)
//{
// InitTree();
//}

//protected void btnEdit_Click(object sender, ImageClickEventArgs e)
//{
// InitTree();
//}

//protected void btnDel_Click(object sender, ImageClickEventArgs e)
//{
// InitTree();
//}


protected void btnDel_Click1(object sender, ImageClickEventArgs e)
{


//BindData();
//selectNum = this.DropDownList_STANDARD_TYPE.SelectedIndex;
DataSet standard_type = dal.STANDARD_TYPE_MANAGE_LIST();
if (standard_type.Tables[0].Rows.Count != 0)
{
dal.STANDARD_DEL(
int.Parse(this.treeList.SelectedNode.Tag.ToString()));
InitTree();
}


}

protected void btnAdd_Click1(object sender, ImageClickEventArgs e)
{
//BindData();
// selectNum = this.DropDownList_STANDARD_TYPE.SelectedIndex;
DataSet standard_type = dal.STANDARD_TYPE_MANAGE_LIST();
if (standard_type.Tables[0].Rows.Count != 0)
{
InitTree();
}

}

protected void btnEdit_Click1(object sender, ImageClickEventArgs e)
{
//BindData();
//selectNum =
DataSet standard_type = dal.STANDARD_TYPE_MANAGE_LIST();
if (standard_type.Tables[0].Rows.Count != 0)
{
InitTree();
}

}

protected void addType_Click(object sender, ImageClickEventArgs e)
{
BindData();
//InitTree();
}



protected void DropDownList_STANDARD_TYPE_SelectedIndexChanged(object sender, EventArgs e)
{
// selectNum = this.DropDownList_STANDARD_TYPE.SelectedIndex;
InitTree();
}
}
}
posted @ 2011-04-22 10:38  .windy  阅读(155)  评论(0编辑  收藏  举报