DropDownList 二级联动 保存时 第二个DropDownList 被刷新
自己想做个DropDownList 二级联动用户控件,但是在保存数据时,第二个DropDownList被刷新,请各位帮忙指点下
代码如下:
编辑页面:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="UserOpt.aspx.cs" Inherits="IBP_UserOpt" Title="无标题页" EnableEventValidation="false" %>
<%@ Register TagPrefix="uc1" TagName="OrgDep" Src="~/UserControl/OrgDep.ascx" %>
<%@ Register TagPrefix="title" TagName="menuTab" Src="~/UserControl/MenuTab.ascx" %>
<asp:Content ID="cWorkTitle" ContentPlaceHolderID="WorkTitle" runat="Server">
<script src="../JS/Common.js" type="text/javascript"></script>
<script src="../JS/jquery-1.7.2.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="cWorkTop" ContentPlaceHolderID="WorkTop" runat="Server">
</asp:Content>
<asp:Content ID="cWorkMenu" ContentPlaceHolderID="WorkMenu" runat="Server">
<title:menuTab ID="menuTab" runat="server" DefaultSelect="0" MenuName="角色信息" />
</asp:Content>
<asp:Content ID="cWorkButton" ContentPlaceHolderID="WorkButton" runat="Server">
<asp:Button ID="btnSave" runat="server" CssClass="button2" Text="保 存" OnClick="btnSave_Click" />
<input id="btnClose" type="button" class="button2" value="关闭" onclick="cm.CloseWindow()" />
</asp:Content>
<asp:Content ID="cWorkForm" ContentPlaceHolderID="WorkForm" runat="Server">
<table cellspacing="0" cellpadding="2" border="0" width="100%">
<tr>
<td width="70px">
姓名:
</td>
<td>
<asp:TextBox ID="txtName" runat="server" CssClass="Line"></asp:TextBox>
</td>
</tr>
<tr>
<td width="70px">
帐号:
</td>
<td>
<asp:TextBox ID="txtLoginName" runat="server" CssClass="Line"></asp:TextBox>
</td>
</tr>
<tr>
<td width="70px">
性别:
</td>
<td>
<asp:RadioButtonList ID="rdbSex" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="男" Value="1" Selected="True"></asp:ListItem>
<asp:ListItem Text="女" Value="0"></asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td width="70px">
角色:
</td>
<td >
<asp:DropDownList ID="ddlRole" runat="server" Width="200px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td width="70px">
机构:
</td>
<td>
<uc1:OrgDep id="orgdep" runat="server"></uc1:OrgDep>
</td>
</tr>
</table>
</asp:Content>
<asp:Content ID="cWorkGrid" ContentPlaceHolderID="WorkGrid" runat="Server">
</asp:Content>
<asp:Content ID="cWorkEnd" ContentPlaceHolderID="WorkEnd" runat="Server">
</asp:Content>
<asp:Content ID="cWorkFooter" ContentPlaceHolderID="WorkFooter" runat="Server">
</asp:Content>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Core.IBP;
using Core.Common;
public partial class IBP_UserOpt : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) return;
ViewState["opt"] = Request["operation"] == null ? "view" : Request["operation"];
ViewState["ID"] = Request["ID"] != null ? Request["ID"] : "0";
InitData();
InitInfo();
InitPower();
}
private void InitData()
{
BaseSet.Initddl(ddlRole, IBP_T_Role.GetList(), false);
}
private void InitPower()
{
if (ViewState["opt"].ToString() == "view")
{
btnSave.Visible = false;
}
}
private void InitInfo()
{
DataTable dt = IBP_T_User.GetInfo(ViewState["ID"].ToString());
if (dt != null && dt.Rows.Count > 0)
{
txtName.Text = dt.Rows[0]["sName"].ToString();
txtLoginName.Text = dt.Rows[0]["sLoginName"].ToString();
rdbSex.SelectedValue = dt.Rows[0]["iSex"].ToString();
ddlRole.SelectedValue = dt.Rows[0]["iRoleID"].ToString();
orgdep.Orgid = dt.Rows[0]["iOrgid"].ToString();
orgdep.Depid = dt.Rows[0]["iDepid"].ToString();
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
string mes = checkValue();
if (mes.Length > 0)
{
this.ShowMessage(mes);
return;
}
if (ViewState["ID"].ToString() == "0")
{
bool b = IBP_T_User.CheckSameName(txtLoginName.Text);
if (b)
{
this.SaveClose("该帐号已存在");
return;
}
b = IBP_T_User.Insert(txtLoginName.Text, txtName.Text, int.Parse(rdbSex.SelectedValue), int.Parse(ddlRole.SelectedValue), int.Parse(orgdep.Orgid), int.Parse(orgdep.Depid));
if (b)
this.SaveClose("添加成功");
else
this.SaveClose("添加失败");
}
else
{
bool b = IBP_T_User.Save(ViewState["ID"].ToString(), txtLoginName.Text, txtName.Text, int.Parse(rdbSex.SelectedValue), int.Parse(ddlRole.SelectedValue),
int.Parse(orgdep.Orgid), int.Parse(orgdep.Depid));
if (b)
this.SaveClose("保存成功");
else
this.SaveClose("保存失败");
}
}
private string checkValue()
{
string mes = string.Empty;
if (txtName.Text.Length == 0)
{
mes += "名称不能为空\n";
}
if (txtLoginName.Text.Length == 0)
{
mes += "账号不能为空\n";
}
return mes;
}
}