1,DropDownList属性AutoPostBack="True"
2,放在UpdatePanel内,用UpdatePanel后,只对UpdatePanel内的控件做数据绑定,不会对UpdatePanel外的control做操作(包括事件也不会触发)
3,一个UserControl占用页面的一行。
4,每个UserControl在页面上都是一个Div,可以用Div属性设置大小
5,Control之间的间距可以用<table>来接近:<table cellpadding="0"; cellspacing="0"; ><td style="padding-left:0px" >
6,联动可以用JavaScript完成,但是不能做成UserControl,因为JavaScript上要getElementsByID
问题不明,JavaScript不熟悉
<table cellpadding="0"; cellspacing="0"; style=" border:-1 none">
<tr style=" letter-spacing: 0px"> <td style="padding-left: 0px"> Dept. / Group / Section / Unit <asp:DropDownList ID="ddlDept" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlDept_SelectedIndexChanged" Width="105px"> <asp:ListItem Value="0">-select dept-</asp:ListItem> </asp:DropDownList> </td> <td style="padding-left:0px"> <asp:DropDownList ID="ddlGroup" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlGroup_SelectedIndexChanged" Width="105px"> <asp:ListItem Value="0">-select group-</asp:ListItem> </asp:DropDownList> </td> <td style=" padding-left:0px"> <asp:DropDownList ID="ddlSection" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlSection_SelectedIndexChanged" Width="105px"> <asp:ListItem Value="0">-select section-</asp:ListItem> </asp:DropDownList> </td> <td style=" padding-left:0px"> <asp:DropDownList ID="ddlUnit" runat="server" AutoPostBack="True" Width="105px"> <asp:ListItem Value="0">-select unit-</asp:ListItem> </asp:DropDownList> </td> </tr> </table>
#region 属性
private bool isEnable = true;public bool IsEnable
{ get { return isEnable; } set { isEnable = value; } } private bool isDeptVisible = true;public bool IsDeptVisible
{ get { return isDeptVisible; } set { isDeptVisible = value; } } private bool isGroupVisible = true;public bool IsGroupVisible
{ get { return isGroupVisible; } set { isGroupVisible = value; } } private bool isSectionVisible = true;public bool IsSectionVisible
{ get { return isSectionVisible; } set { isSectionVisible = value; } } private bool isUnitVisible = true;public bool IsUnitVisible
{ get { return isUnitVisible; } set { isUnitVisible = value; } }public string dept_id
{ get { return ddlDept.SelectedItem.Value.ToString(); } set { if (value is string) { ddlDept.SelectedItem.Value = value; ddlDept_SelectedIndexChanged(null, null); } } } public string group_id { get { return ddlGroup.SelectedItem.Value.ToString(); } set { if (value is string) { ddlGroup.SelectedItem.Value = value; ddlGroup_SelectedIndexChanged(null, null); } } } public string section_id { get { return ddlSection.SelectedItem.Value.ToString(); } set { if (value is string) { ddlSection.SelectedItem.Value = value; ddlSection_SelectedIndexChanged(null, null); } } } public string unit_id { get { return ddlUnit.SelectedItem.Value.ToString(); } set { if (value is string) { ddlUnit.SelectedItem.Value = value; } } } public DataTable dtResult(string dbTable) { DataTable dt = new DataTable(); return dt; } #endregion 属性protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack) { is_inventory_holding_unit.DDLBind(ddlDept, "dept", null); this.ddlDept.Items.Insert(0, new ListItem("-select dept-", "0")); } ddlDept.Enabled = IsEnable; ddlGroup.Enabled = IsEnable; ddlSection.Enabled = IsEnable; ddlUnit.Enabled = IsEnable;ddlDept.Visible = IsDeptVisible;
ddlGroup.Visible = IsGroupVisible; ddlSection.Visible = IsSectionVisible; ddlUnit.Visible = IsUnitVisible;}
protected void ddlDept_SelectedIndexChanged(object sender, EventArgs e) { this.ddlGroup.Items.Clear(); this.ddlSection.Items.Clear(); this.ddlUnit.Items.Clear(); is_inventory_holding_unit.DDLBind(ddlGroup, "group", ddlDept.SelectedItem.Value.ToString()); this.ddlGroup.Items.Insert(0, new ListItem("-select group-", "0")); this.ddlSection.Items.Insert(0, new ListItem("-select section-", "0")); this.ddlUnit.Items.Insert(0, new ListItem("-select unit-", "0")); }protected void ddlGroup_SelectedIndexChanged(object sender, EventArgs e)
{ this.ddlSection.Items.Clear(); this.ddlUnit.Items.Clear(); is_inventory_holding_unit.DDLBind(ddlSection, "section", ddlGroup.SelectedItem.Value.ToString()); this.ddlSection.Items.Insert(0, new ListItem("-select section-", "0")); this.ddlUnit.Items.Insert(0, new ListItem("-select unit-", "0")); }protected void ddlSection_SelectedIndexChanged(object sender, EventArgs e)
{ this.ddlUnit.Items.Clear(); is_inventory_holding_unit.DDLBind(ddlUnit, "unit", ddlSection.SelectedItem.Value.ToString()); this.ddlUnit.Items.Insert(0, new ListItem("-select unit-", "0")); }
#region Load时赋值
public void dept(string id) { is_inventory_holding_unit.DDLBind(ddlDept, "dept", null); ddlDept.SelectedValue = id; ddlDept_SelectedIndexChanged(null, null); } public void group(string id) { ddlGroup.SelectedValue = id; ddlGroup_SelectedIndexChanged(null, null); } public void section(string id) { ddlSection.SelectedValue = id; ddlSection_SelectedIndexChanged(null, null); } public void unit(string id) { if (id == null) return; if (id == "") return;ddlUnit.SelectedValue = id;
} #endregion