none
updatepanel中的dropdownlist不停的刷新 RRS feed

  • 问题

  • 我在updatepanel中写了个dropdownlist,但是显示出来的让我快哭了,数据没了不说,而且点开还自动缩回去了,不知道咋整了
    • 已移动 ThankfulHeart 2012年5月7日 8:52 ASP.NET的问题 (发件人:.NET Framework 一般性问题讨论区)
    2012年5月4日 11:39

全部回复

  • 我在updatepanel中写了个dropdownlist,但是显示出来的让我快哭了,数据没了不说,而且点开还自动缩回去了,不知道咋整了

    请尝试:

    1)把Dropdownlist绑定到一个数据源,或者在Page_Load中设置其DataSource+调用DataBind方法绑定到下拉列表。

    2)然后把这个下拉列表扔到UpdatePanel中。

    3)把下拉列表AutoPostBack=True即可。

    实在不行,请给出你的代码(包含cs和aspx部分)。谢谢了……


       QQ我:讨论(Talk)
    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

    2012年5月5日 2:17
  • 同意楼上观点

    郭哲

    2012年5月7日 9:56
  • 建议给出代码..帮你检查下哪里有问题!
    2012年5月8日 3:00
    版主
  • <%@ Control Language="C#" AutoEventWireup="true" CodeFile="user.ascx.cs" Inherits="Admin_user"  EnableViewState="false"%>
    <fieldset style="overflow: hidden; zoom: 1; margin-top: 10px; background-color: #f5f7f8; padding: 10px">
        <legend style="background: url(images/icon42.jpg) no-repeat 6px 50%; font-weight: bold; line-height: 45px; padding-left: 60px">成员管理</legend>
        <div style="text-align:center;">
            <div style="text-align: left;">
                <a href="#" style="text-decoration:none; color:#000000;" class="od" onclick="show('fd');return false;">添加新用户</a>
                <%--<a href="javascript://" onclick="jBox.open('div-jBoxID','div','fd','修改密码','width=280,height=400,center=true,minimizable=true,resize=true,draggable=true,model=true');"
                    style="text-decoration: none; color: #000000;" class="od">
                    添加新用户</a>--%>
                
            </div>
            <div id="fd" style="display: none;filter: alpha(opacity=100); opacity: 1;" >
                <div id="module_list" style="text-align: right; height: 15px; filter: alpha(opacity=100); opacity: 1;">
                    <a href="#" style="text-decoration:none; color:Black;" onclick="closeed('fd');return false;">关闭</a>
                </div>
               <%-- <div id="AddNewUsers" style="display: none; filter: alpha(opacity=100); opacity: 1;">--%>
                
                <div></div>
                <fieldset style="overflow: hidden; zoom: 1; margin-top: 10px; background-color: #EDF1F8; padding: 10px">
                    <legend style="background: url(images/icon42.jpg) no-repeat 6px 50%; font-weight: bold; line-height: 45px; padding-left: 60px">添加新用户</legend>
                        <table border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td>
                                    用&nbsp;&nbsp;户&nbsp;&nbsp;名:</td>
                                <td><asp:TextBox ID="AddUserName" Width="180px" runat="server" EnableViewState="false"></asp:TextBox></td>
                                <td><font color="red">*</font></td>
                            </tr>
                            <tr>
                                <td>
                                    密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:</td>
                                <td><asp:TextBox ID="AddUserPwd" runat="server" Width="180px" TextMode="Password" ></asp:TextBox></td>
                                <td><font color="red">*</font></td>
                            </tr>
                            <tr>
                                <td>
                                    真实姓名:
                                </td>
                                <td>
                                   
                                    <asp:TextBox ID="AddTrueName" runat="server" Width="180px"></asp:TextBox>
                                </td>
                                <td>
                                    <font color="red">*</font>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别:</td>
                                <td align="left">
                                    <asp:DropDownList ID="AddUserSex" runat="server">
                                        <asp:ListItem>男</asp:ListItem>
                                        <asp:ListItem>女</asp:ListItem>
                                    </asp:DropDownList>
                                </td>
                                <td><font color="red">*</font></td>
                            </tr>
                            
                            <tr>
                                <td>
                                    年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;龄:</td>
                                <td align="left">
                                    <asp:TextBox ID="AddUserAge" Width="35px" runat="server" EnableViewState="false"></asp:TextBox>
                                </td>
                                <td><font color="red">*</font></td>
                            </tr>
                            <tr>
                                <td>出生日期:</td>
                                <td align="left">
                                    <asp:TextBox ID="AddUserbirthday" runat="server" Width="180px" EnableViewState="false"></asp:TextBox>
                                </td>
                                <td><font color="red">*</font></td>
                            </tr>
                            <tr>
                                <td>手机号码:</td>
                                <td align="left">
                                    <asp:TextBox ID="AddUserPhone" runat="server" Width="180px"></asp:TextBox>
                                </td>
                                <td><font color="red">*</font></td>
                            </tr>
                            <tr>
                                <td>电子邮箱:</td>
                                <td align="left">
                                    <asp:TextBox ID="AddUserEmail" runat="server" Width="180px" 
                                    validationExpression="^[/w-]+(/.[/w-]+*@[/w-]+(/.[/w=]+)+$"></asp:TextBox>
                                </td>
                                <td><font color="red">*</font></td>
                            </tr>
                            <tr>
                                <td>所在部门:</td>
                                <td align="left">
                                    <%--<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server"></asp:ScriptManagerProxy>--%>
                                    <asp:UpdatePanel ID="DepName" runat="server">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="AddUserDepName" runat="server" AutoPostBack="true" DataTextField="DepName"
                                                DataValueField="DepartmentID" onselectedindexchanged="AddUserDepName_SelectedIndexChanged"></asp:DropDownList>
                                            <asp:Label ID="lable1" Visible="false" runat="server"></asp:Label>
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                    <%--<asp:SqlDataSource ID="AddUsers" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                                        SelectCommand="SELECT [DepName] FROM [Accounts_Department]"></asp:SqlDataSource>--%>
                                </td>
                                <td><font color="red">*</font></td>
                            </tr>
                            <tr>
                                <td>用户类别:
                                </td>
                                <td align="left">
                                    <asp:UpdatePanel ID="UserTyoe" runat="server">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="AddUserType" runat="server" AutoPostBack="true" ></asp:DropDownList>
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                </td>
                                <td><font color="red">*</font></td>
                            </tr>
                            <tr>
                                <td colspan="3">
                                   <asp:Button ID="SaveInfomation" Text="保存" runat="server" 
                                        onclick="SaveInfomation_Click" />&nbsp;&nbsp;&nbsp;&nbsp;
                                   <asp:Button ID="Cancle" Text="取消" runat="server" OnClientClick="closeed('fd');return false; " />
                                </td>
                                
                            </tr>
                        </table>
                </fieldset>
                </div>
            </div>
            <script type="text/javascript">
                var prox;
                var proy;
                var proxc;
                var proyc;
                function show(id) {/*--打开--*/
                    clearInterval(prox);
                    clearInterval(proy);
                    clearInterval(proxc);
                    clearInterval(proyc);
                    var o = document.getElementById(id);
                    o.style.display = "block";
                    o.style.width = "1px";
                    o.style.height = "1px";
                    prox = setInterval(function () { openx(o, 350) }, 10);
                }
                function openx(o, x) {/*--打开x--*/
                    var cx = parseInt(o.style.width);
                    if (cx < x) {
                        o.style.width = (cx + Math.ceil((x - cx) / 5)) + "px";
                    }
                    else {
                        clearInterval(prox);
                        proy = setInterval(function () { openy(o, 345) }, 10);
                    }
                }
                function openy(o, y) {/*--打开y--*/
                    var cy = parseInt(o.style.height);
                    if (cy < y) {
                        o.style.height = (cy + Math.ceil((y - cy) / 5)) + "px";
                    }
                    else {
                        clearInterval(proy);
                    }
                }
                function closeed(id) {/*--关闭--*/
                    clearInterval(prox);
                    clearInterval(proy);
                    clearInterval(proxc);
                    clearInterval(proyc);
                    var o = document.getElementById(id);
                    if (o.style.display == "block") {
                        proyc = setInterval(function () { closey(o) }, 10);
                    }
                }
                function closey(o) {/*--打开y--*/
                    var cy = parseInt(o.style.height);
                    if (cy > 0) {
                        o.style.height = (cy - Math.ceil(cy / 5)) + "px";
                    }
                    else {
                        clearInterval(proyc);
                        proxc = setInterval(function () { closex(o) }, 10);
                    }
                }
                function closex(o) {/*--打开x--*/
                    var cx = parseInt(o.style.width);
                    if (cx > 0) {
                        o.style.width = (cx - Math.ceil(cx / 5)) + "px";
                    }
                    else {
                        clearInterval(proxc);
                        o.style.display = "none";
                    }
                }
                ////////////////////////////////////////////////////
              
                /*$(function (e) {
                    $("m_title").bind('mouseover', function () {
                        $(this).css("cursor", "move")
                    });
                    var $show = $("#loader");
                    var $orderlist = $("#orderkist");
                    var $list = $("module_list");
                    $list.sortable({
                        opacity:0.6,//设置拖动时候的透明度
                        revert:true,//缓冲效果
                        cursor:'move',//拖动的时候鼠标样式
                        handle:'m_title',//可以拖动的部位,标题部分
                    });
                });
                */
               
                /*-------------------------鼠标拖动---------------------*/
               /* var od = document.getElementById("fd");
                var dx, dy, mx, my, mouseD;
                var odrag;
                var isIE = document.all ? true : false;
                document.onmousedown = function (e) {
                    var e = e ? e : event;
                    if (e.button == (document.all ? 1 : 0)) {
                        mouseD = true;
                    }
                }
                document.onmouseup = function () {
                    mouseD = false;
                    odrag = "";
                    if (isIE) {
                        od.releaseCapture();
                        od.filters.alpha.opacity = 100;
                    }
                    else {
                        window.releaseEvents(od.MOUSEMOVE);
                        od.style.opacity = 1;
                    }
                   
                }
                //function readyMove(e){ 
                od.onmousedown = function (e) {
                    odrag = this;
                    var e = e ? e : event;
                    if (e.button == (document.all ? 1 : 0)) {
                        mx = e.clientX;
                        my = e.clientY;
                        od.style.left = od.offsetLeft + "px";
                        od.style.top = od.offsetTop + "px";
                        if (isIE) {
                            od.setCapture();
                            od.filters.alpha.opacity = 50;
                        }
                        else {
                            window.captureEvents(Event.MOUSEMOVE);
                            od.style.opacity = 0.5;
                        }
                        //alert(mx);
                        //alert(my);
                    }
                }
                document.onmousemove = function (e) {
                    var e = e ? e : event;
                    //alert(mrx);
                    //alert(e.button);  
                    if (mouseD == true && odrag) {
                        var mrx = e.clientX - mx;
                        var mry = e.clientY - my;
                        od.style.left = parseInt(od.style.left) + mrx + "px";
                        od.style.top = parseInt(od.style.top) + mry + "px";
                        mx = e.clientX;
                        my = e.clientY;
                    }
                }
                */
     
            </script>
            <asp:Label ID="value" runat="server"></asp:Label>
            <br />
            <asp:ScriptManagerProxy ID="SMP1" runat="server"></asp:ScriptManagerProxy>
            
            <asp:GridView ID="UserMeng" runat="server"  AutoGenerateColumns="False"  
            BackColor="White" BorderColor="#CCCCCC"  EmptyDataText="暂无数据"  onrowdeleting="UserMeng_RowDeleting"  
            onrowcancelingedit="UserMeng_RowCancelingEdit"  
            onrowediting="UserMeng_RowEditing" onrowupdating="UserMeng_RowUpdating" 
            PageSize="30" onrowdatabound="UserMeng_RowDataBound">
             
                <Columns>
                
                
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:CheckBox ID="select" runat="server" />
                    </ItemTemplate>
                    <HeaderStyle Width="15px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                    <ItemStyle Width="15px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                </asp:TemplateField>
                <%--<asp:BoundField DataField="UserName" HeaderText="用户名">
                    <HeaderStyle Width="150px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                    <ItemStyle Width="150px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                </asp:BoundField>--%>
                <asp:TemplateField HeaderText="用户名">
                    <ItemTemplate>
                        <%#Eval("UserName") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="NameText" runat="server" Text='<%#Eval("UserName") %>' Width="150px"></asp:TextBox>
                    </EditItemTemplate>
                    <HeaderStyle Width="150px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                    <ItemStyle Width="150px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                </asp:TemplateField>
                    
                <asp:TemplateField HeaderText="真实姓名">
                    <ItemTemplate>
                        <%# Eval("TrueName") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="TrueNameText" runat="server" Text='<%#Eval("TrueName") %>' Width="150px"></asp:TextBox>
                    </EditItemTemplate>
                    <HeaderStyle Width="150px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                    <ItemStyle Width="150px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa"/>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="性别">
                    <ItemTemplate>
                        <%--<asp:DropDownList ID="SexDDL" DataValueField="性别" DataTextField="性别" Visible="false"  runat="server"></asp:DropDownList>--%>
                        <%# Eval("Sex") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="SexDD" runat="server">
                            <asp:ListItem>男</asp:ListItem>
                            <asp:ListItem>女</asp:ListItem>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <HeaderStyle Width="80px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                    <ItemStyle Width="80px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="年龄">
                    <ItemTemplate>
                        <%# Eval("Age") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="AgeText" runat="server" Text='<%#Eval("Age") %>' Width="70px"></asp:TextBox>
                    </EditItemTemplate>
                    <HeaderStyle Width="70px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                    <ItemStyle Width="70px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                </asp:TemplateField>
                <asp:BoundField DataField="BirthDay" HeaderText="出生日期" DataFormatString="{0:yyyy-MM-dd}" HtmlEncode="false">
                    <HeaderStyle Width="130px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                    <ItemStyle Width="130px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                </asp:BoundField>
                <%--<asp:TemplateField HeaderText="出生日期">
                    <ItemTemplate>
                        <%# Eval("BirthDay") %>
                    </ItemTemplate>
                    <HeaderStyle Width="130px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                    <ItemStyle Width="130px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                </asp:TemplateField>--%>
                
                <asp:TemplateField HeaderText="手机号码 ">
                    <ItemTemplate>
                        <%#Eval("Phone") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="PhoneText" runat="server" Text='<%#Eval("Phone") %>' Width="150px"></asp:TextBox>
                    </EditItemTemplate>
                    <HeaderStyle Width="150px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                    <ItemStyle Width="150px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                </asp:TemplateField>
               
                <asp:TemplateField HeaderText="E-Mail">
                    <ItemTemplate>
                        <%# Eval("Email") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="EmailText" runat="server" Text='<%#Eval("Email") %>' Width="150px"></asp:TextBox>
                    </EditItemTemplate>
                    <HeaderStyle Width="150px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                    <ItemStyle Width="150px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText=" 所在部门">
                    <ItemTemplate>
                      
                     <%#Eval("DepartmentID") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:HiddenField ID="DepNameHDF" runat="server" Value='<%#Eval("DepartmentID") %>' />
                        <asp:DropDownList ID="DepNameDDL" runat="server" Width="180px"></asp:DropDownList>
                    </EditItemTemplate>
                    <HeaderStyle Width="180px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                    <ItemStyle Width="180px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="用户类别">
                    <ItemTemplate>
                        <%# Eval("UserType") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:HiddenField ID="UserTypeHDF" runat="server" Value='<%#Eval("UserType") %>' />
                        <asp:DropDownList ID="UserTypeDDL" runat="server" Width="120px"></asp:DropDownList>
                    </EditItemTemplate>
                    <HeaderStyle Width="120px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                    <ItemStyle Width="120px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                </asp:TemplateField>
                <asp:CommandField HeaderText="操作" ShowEditButton="true" ShowDeleteButton="true">
                    <HeaderStyle Width="180px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                    <ItemStyle Width="180px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#9BD1Fa" />
                </asp:CommandField>
        
              </Columns>
                <SelectedRowStyle BackColor="#669999" Font-Bold="true" ForeColor="White" />
                <RowStyle ForeColor="#000066" />
                <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Center" />
                <HeaderStyle BackColor="#006699" Font-Bold="true" ForeColor="White" CssClass="Freezing" Font-Size="15px" />
                <FooterStyle BackColor="White" ForeColor="000066" />
            </asp:GridView>
           
            <div style="text-align:left; padding-top:5px; height:25px; line-height:25px;">
                <asp:CheckBox ID="SelectALL" runat="server" AutoPostBack="true" Text="全选"  OnCheckedChanged="SelectALL_CheckChaned" align="left"/>
                &nbsp;
                <asp:Button ID="canel" runat="server" Text="取消" />&nbsp;
                <asp:Button ID="Delete" runat="server" Text="删除" />
            </div>
            
            <div style="text-align: left; padding-top: 10px; color: #000066;">
                <asp:LinkButton ID="FirstPage" Text="首页" Style="text-decoration: none; color: #000066;"
                    runat="server"></asp:LinkButton>&nbsp;
                <asp:LinkButton ID="PrePage" Text="上一页" Style="text-decoration: none; color: #000066;"
                    runat="server"></asp:LinkButton>&nbsp;
                <asp:LinkButton ID="NextPage" Text="下一页" Style="text-decoration: none; color: #000066;"
                    runat="server"></asp:LinkButton>&nbsp;
                <asp:LinkButton ID="LastPge" Text="末页" Style="text-decoration: none; color: #000066;"
                    runat="server"></asp:LinkButton>&nbsp; 第<asp:Label ID="ThisPage" runat="server"></asp:Label>页&nbsp;
                共<asp:Label ID="SubPage" runat="server"></asp:Label>页&nbsp; 共<asp:Label ID="RecordCount"
                    runat="server"></asp:Label>条数据
            </div>
            </asp:UpdatePanel>
        </div>
    </fieldset>

    using System;
    using System.Data;
    using System.Data.Sql;
    using System.Data.SqlClient;
    using System.Data.SqlTypes;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.SessionState;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Text;
    using System.Security.Cryptography;
    using Common;
    using DBUtility;
    using BLL;
    using DAL;
    public partial class Admin_user : System.Web.UI.UserControl
    {
         
        protected void Page_Load(object sender, EventArgs e)
        {
           // GdBind();
            //AddUserDepNameBind();
            //AddUserTypeBind();
            //Response.Write(SQLHelper.connectionString);
            if (!IsPostBack)
            {
                
                AddUserDepNameBind();
                AddUserTypeBind();
                GdBind();
                //Response.Write(this.AddUserDepName.SelectedValue);
                //this.AddUserDepName.AutoPostBack = true;
                value.Text = this.AddUserDepName.Items[9].ToString() + "&nbsp;&nbsp;" + this.AddUserDepName.Items[9].Value;
            }
        }
        private void AddUserTypeBind()//UserType数据绑定
        {
            try
            {
                BLL.Accounts_Roles bll = new BLL.Accounts_Roles();
                DataSet ds = bll.GetAllList();
                this.AddUserType.DataSource = ds.Tables[0];
                this.AddUserType.DataTextField = "Description";
                this.AddUserType.DataValueField = "RoleID";
                this.AddUserType.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write("数据库错误,错误原因:" + ex.Message);
                Response.End();
            }
        }
        private void AddUserDepNameBind()//UserDepName数据绑定
        {
            try
            {
                BLL.Accounts_Department bll = new BLL.Accounts_Department();
                DataSet ds = bll.GetAllList();
                this.AddUserDepName.DataSource = ds.Tables[0];
                this.AddUserDepName.DataTextField = "DepName";
                this.AddUserDepName.DataValueField = "DepartmentID";
                this.AddUserDepName.DataBind();
                
            }
            catch (Exception ex)
            {
                Response.Write("数据库错误,错误原因:" + ex.Message);
                Response.End();
            }
        }
        
        public void GdBind()//GridView数据绑定
        {
            try
            {
                 BLL.Accounts_Users bll = new BLL.Accounts_Users();
                DataSet ds = bll.GetAllList();
                UserMeng.DataSource = ds;
                UserMeng.DataKeyNames = new string[] { "UserID" };
                UserMeng.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write("数据库错误,错误原因:" + ex.Message);
                Response.End();
            }
           
        }
        //科室显示,不显示数字,显示在对应数据库中的文本数据
        /*public string Dep_Name(int DepartmentID)
        {
            BLL.Accounts_Department bll = new BLL.Accounts_Department();
            bll.GetName(DepartmentID);
            return Dep_Name(DepartmentID);
        }*/
        protected void SelectALL_CheckChaned(object sender, EventArgs e)
        {
            for (int i = 0; i <=UserMeng.Rows.Count-1; i++)
            {
                CheckBox cbox = (CheckBox)UserMeng.Rows[i].FindControl("select");
                if (SelectALL.Checked == true)
                {
                    cbox.Checked = true;
                }
                else
                {
                    cbox.Checked = false;
                }
            }
        }
        public static byte[] EncryptPassword(string password) 
        { 
            byte[] bytes = new UnicodeEncoding().GetBytes(password);
            SHA1 sha = new SHA1CryptoServiceProvider(); 
            return sha.ComputeHash(bytes);
        }
        protected void SaveInfomation_Click(object sender, EventArgs e)
        {
            
            string strError = "";
            if (this.AddUserName.Text.Trim().Length==0)
            {
                strError += "用户名不能为空!\\n";
            }
            if (this.AddUserPwd.Text.Trim().Length==0)
            {
                strError += "密码不能为空\\n";
            }
            if (this.AddTrueName.Text.Trim().Length==0)
            {
                strError += "真实姓名不能为空\\n";
            }
            if (!PageValidate.IsNumber(AddUserAge.Text))
            {
                strError += "年龄格式错误\\n";
            }
            if (!PageValidate.IsDateTime(AddUserbirthday.Text))
            {
                strError += "出生日期格式错误\\n";
            }
            if (this.AddUserPhone.Text.Trim().Length==0)
            {
                strError += "电话号码不能为空\\n";
            }
            
            if (this.AddUserEmail.Text.Trim().Length==0)
            {
                strError += "E-Mail不能为空\\n";
            }
            /*string EmailRegex=@"^[/w-]+(/.[/w-]+*@[/w-]+(/.[/w=]+)+$";
            if (Regex.IsMatch(AddUserEmail.Text,EmailRegex))
            {
                Response.Write("<script>alt"+"邮箱格式错误"+"</script>");
            }*/
            if (strError!="")
            {
                MessageBox.Show(this.Page,strError);
               
                return;
              
            }
           // BLL.Accounts_Department Depbll = new BLL.Accounts_Department();
            //定义以及初始化
            string UserName = this.AddUserName.Text;
            //byte[] UserPassword = new UnicodeEncoding().GetBytes(this.AddUserPwd.Text);
            byte[] UserPassword = EncryptPassword(this.AddUserPwd.Text);
            string TrueName = this.AddTrueName.Text;
            string Sex = this.AddUserSex.SelectedValue.ToString();
            int Age = int.Parse(this.AddUserAge.Text);
            DateTime BirthDay = DateTime.Parse(this.AddUserbirthday.Text);
            string Phone = this.AddUserPhone.Text;
            string Email = this.AddUserEmail.Text;
           
            int DepName =Convert.ToInt32( this.AddUserDepName.SelectedItem.Value);
            //int DepName = Convert.ToInt32(lable1.Text);
           
            string UserType = this.AddUserType.SelectedValue.ToString();
            //赋值
           
            Model.Accounts_Users model = new Model.Accounts_Users();
            model.UserName = UserName;
            model.UserPassWord = UserPassword;
            model.TrueName = TrueName;
            model.Sex = Sex;
            model.Age = Age;
            model.BirthDay = BirthDay;
            model.Phone = Phone;
            model.Email = Email;
            model.DepartmentID = DepName;
            model.UserType = UserType;
            //业务逻辑层处理
            BLL.Accounts_Users bll = new BLL.Accounts_Users();
            bll.Add(model);
            Common.MessageBox.ShowAndRedirect(this.Page, "保存成功!", "User.aspx");
        }
        protected void AddUserDepName_SelectedIndexChanged(object sender, EventArgs e)
        {
            //int DepName = Convert.ToInt32(this.AddUserDepName.SelectedValue.ToString());
           // this.AddUserDepName.ClearSelection();
            lable1.Text = AddUserDepName.SelectedItem.Value;
            //AddUserDepNameBind();
        }
        protected void UserMeng_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            BLL.Accounts_Users bll = new BLL.Accounts_Users();
            bll.Delete(Convert.ToInt32(this.UserMeng.DataKeys[e.RowIndex].Value.ToString()));
            GdBind();
        }
        protected void UserMeng_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Model.Accounts_Users mode = new Model.Accounts_Users();
            BLL.Accounts_Users bll = new BLL.Accounts_Users();
            bll.Update(mode);
            GdBind();
        }
        protected void UserMeng_RowEditing(object sender, GridViewEditEventArgs e)
        {
            UserMeng.EditIndex = e.NewEditIndex;
            GdBind();
        }
        protected void UserMeng_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            UserMeng.EditIndex = -1;
            GdBind();
        }
        //public string KS(int i)
        //{
        //    BLL.Accounts_Department bll = new BLL.Accounts_Department();
        //    bll.GetModel(i).ToString();
        //    return null;
        //}
        protected void UserMeng_RowDataBound(object sender, GridViewRowEventArgs e)
        {
           /* if (e.Row.RowType==DataControlRowType.DataRow)
            {
                if (e.Row.RowState==DataControlRowState.Normal||e.Row.RowState==DataControlRowState.Alternate)
                {
                    ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('您确认要删除:/'"  +e.Row.Cells[1].Text+"' / 吗?')");
                }
            }*/
            BLL.Accounts_Department bll=new BLL.Accounts_Department();
            if (((DropDownList)e.Row.FindControl("DepNameDDL"))!=null)
            {
               //生成dropdownlist的值
                DropDownList depnameddl = (DropDownList)e.Row.FindControl("DepNameDDL");
                depnameddl.Items.Clear();
                DataSet ds = bll.GetAllList();
                depnameddl.DataSource = ds.Tables[0];
                depnameddl.DataTextField = "DepName";
                depnameddl.DataValueField = "DepartmentID";
                depnameddl.DataBind();
                //选中dropdownlist
                depnameddl.SelectedValue = ((HiddenField)e.Row.FindControl("DepNameHDF")).Value;
            }
             DropDownList depnameddl1 = (DropDownList)e.Row.FindControl("DepNameDDL");
            
           
            BLL.Accounts_Roles Rolesbll = new BLL.Accounts_Roles();
            if (((DropDownList)e.Row.FindControl("UserTypeDDL"))!=null)
            {
                //生成dropdownlist的值
                DropDownList usertypeddl = (DropDownList)e.Row.FindControl("UserTypeDDL");
                usertypeddl.Items.Clear();
                DataSet ds = Rolesbll.GetAllList();
                usertypeddl.DataSource = ds.Tables[0];
                usertypeddl.DataTextField = "Description";
                usertypeddl.DataValueField = "RoleID";
                usertypeddl.DataBind();
                //选中dropdownlist的值
                usertypeddl.SelectedValue = ((HiddenField)e.Row.FindControl("UserTypeHDF")).Value;
            }
        }
    }


    2012年5月8日 10:53
  • 首先你把updatepanel容器去掉试试 如果还是空白的 就是代码有问题,还有我感觉你的page_load 你是绑定上去的 你确定会有10个items?

    this.AddUserDepName.Items[9].ToString() + "&nbsp;&nbsp;" + this.AddUserDepName.Items[9].Value

        protected void Page_Load(object sender, EventArgs e)
        {
           // GdBind();
            //AddUserDepNameBind();
            //AddUserTypeBind();
            //Response.Write(SQLHelper.connectionString);
            if (!IsPostBack)
            {
                
                AddUserDepNameBind();
                AddUserTypeBind();
                GdBind();
                //Response.Write(this.AddUserDepName.SelectedValue);
                //this.AddUserDepName.AutoPostBack = true;
                value.Text = this.AddUserDepName.Items[9].ToString() + "&nbsp;&nbsp;" + this.AddUserDepName.Items[9].Value;
            }
        }

    2012年5月8日 11:05
    版主
  • 去掉updatepanel容器,dropdownlist加上AutoPostBack=true的话点击就会刷新,一刷新就没了数据就空白了,但是刷新之前就有
    2012年5月9日 1:34
  • 首先你把updatepanel容器去掉试试 如果还是空白的 就是代码有问题,还有我感觉你的page_load 你是绑定上去的 你确定会有10个items?

    this.AddUserDepName.Items[9].ToString() + "&nbsp;&nbsp;" + this.AddUserDepName.Items[9].Value

        protected void Page_Load(object sender, EventArgs e)
        {
           // GdBind();
            //AddUserDepNameBind();
            //AddUserTypeBind();
            //Response.Write(SQLHelper.connectionString);
            if (!IsPostBack)
            {
                
                AddUserDepNameBind();
                AddUserTypeBind();
                GdBind();
                //Response.Write(this.AddUserDepName.SelectedValue);
                //this.AddUserDepName.AutoPostBack = true;
                value.Text = this.AddUserDepName.Items[9].ToString() + "&nbsp;&nbsp;" + this.AddUserDepName.Items[9].Value;
            }
        }


    上面的那个是我做测试用的看看有没有既数据,连接是不是正确的
    2012年5月9日 1:35
  • 怎么没人帮我啊  ,急死了
    2012年5月10日 1:36
  • 上面的那个是我做测试用的看看有没有既数据,连接是不是正确的?

    这句话我没理解..

    2012年5月10日 1:39
    版主
  • 也就是说那个没用,注释掉也是一样的,我是拿他看看数据对不对,有没有数据绑定到dropdownlist中,连接没有问题
    2012年5月10日 4:40
  • 怎么没人帮我啊  ,急死了
    msdnmg@microsoft.com 
    2012年5月10日 5:58
  • 半天没人出来回答我当然急了

    2012年5月10日 7:47
  • 半天没人出来回答我当然急了

    msdnmg@microsoft.com 发过去问问
    2012年5月11日 6:09