<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    302班

    java突擊隊
    posts - 151, comments - 74, trackbacks - 0, articles - 14
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理
     

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" PageSize="10"
                            Width="542px" AllowPaging="True" AllowSorting="True"
                             DataKeyNames="DB31_1,DB31_2" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_RowDataBound" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnSorting="GridView1_Sorting" >
                            <Columns>
                                <asp:TemplateField HeaderText="序號">
                                    <ItemTemplate>
                                    <%# this.GridView1.PageIndex * this.GridView1.PageSize + this.GridView1.Rows.Count + 1%>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="學歷代碼" SortExpression="DB1_1">
                                    <EditItemTemplate>
                                        <%--<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DB1_1") %>'></asp:TextBox>--%>
                                   <asp:DropDownList ID ="ddlXL" runat="server"  DataValueField='<%# Bind("DB1_1") %>'></asp:DropDownList>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("xueliText") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="學歷名稱" SortExpression="DB1_2">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("DB1_2") %>'></asp:TextBox>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("DB1_2") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                             
                            <asp:TemplateField HeaderText="操作" ShowHeader="False">
                            <EditItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                                     Text="更新"></asp:LinkButton>
                                <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                    Text="取消"></asp:LinkButton>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                                    Text="編輯" OnClientClick="return confirm('確認要編輯嗎?');"></asp:LinkButton>
                           
                                <asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" CommandName="Delete"
                                    Text="刪除" OnClientClick="return confirm('確認要刪除嗎?');"></asp:LinkButton>
                                <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Select"
                                    Text="選擇"></asp:LinkButton>
                            </ItemTemplate>
                            </asp:TemplateField>
                           </Columns>
                           <AlternatingRowStyle BackColor="Aquamarine" />
                        </asp:GridView>
        /// <summary>
        /// 綁定數據到GridView
        /// </summary>
        private void GridViewBind()
        {
            檢索數據庫
            string strSql = "SELECT * FROM DB1";
            得到數據集
            this.GridView1.DataSource=conn.GetDs(strSql).Tables[0].DefaultView;
            this.GridView1.DataBind();
      
        }
        /// <summary>
        /// 編輯當前行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            //當前編輯行背景色高亮
            this.GridView1.EditRowStyle.BackColor = Color.FromName("#F7CE90");
            GridViewBind();
        }
        /// <summary>
        /// 取消編輯狀態
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView1.EditIndex = -1;
            GridViewBind();
        }
        /// <summary>
        /// 刪除記錄過程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //得到單位編號
            string rowToDelete = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
            //轉換為整數
            //int ID=Convert.ToInt32(rowToDelete);
            //從數據庫中刪除
            string str = "DELETE FROM DB1 where DB1_1=" + "'" + rowToDelete + "'" + "";
          
            try
            {
            conn.RunSql(str);
            //重新綁定數據
            GridViewBind();
            }
            catch (Exception ex)
            {
            Response.Write("數據庫錯誤,錯誤原因:" + ex.Message);
            Response.End();
            }

        }
        /// <summary>
        /// 更新記錄過程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            string ID = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
            string DB1_1 = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1")).Text;
            //string DB1_2 = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2")).Text;
            string DB1_2 = (((DropDownList))GridView1.Rows[e.RowIndex].FindControl("ddlXL")).SelectedItem.Text;
           
        //判斷表單項是否有空并給出提示信息
            if (DB1_1 == "" || DB1_2 == "")
            {
                conn.Alert("請輸入完整信息!", Page);
                return;
            }            
           try
           {
            conn.BuilderEdit("select * from DB1 where DB1_1 ='" + ID + "'");
            conn.dr["DB1_1"] = DB1_1;
            conn.dr["DB1_2"] = DB1_2;
            conn.BuilderEditClose();
           }
           catch (OracleException err)
           {
                if (err.Code.ToString() == "1")
                    conn.Alert("錯誤:已存在具有相同主鍵的記錄", Page);
                else
                    conn.Alert("錯誤:未能添加記錄", Page);
            }

            Response.Write("<script language='javascript'>alert('數據已被保存!');</script>");
            //返回瀏覽狀態
            GridView1.EditIndex = -1;
            GridViewBind();
        }
        /// <summary>
        /// 分頁事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            GridViewBind();
        }
        /// <summary>
        /// 加入鼠標效果及為DropDownList綁定值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //為DropDownList綁定值
            if (((DropDownList)e.Row.FindControl("ddlXL")) != null)
            {
                DropDownList ddlXL = (DropDownList)e.Row.FindControl("ddlXL");
                ddlXL.Items.Clear();
                ddlXL.Items.Add(new ListItem("博士", "1"));
                ddlXL.Items.Add(new ListItem("碩士", "2"));
                ddlXL.Items.Add(new ListItem("學士", "3"));
            }

            //加入鼠標滑過的高亮效果
            if (e.Row.RowType == DataControlRowType.DataRow)//判定當前的行是否屬于datarow類型的行
            {
                //當鼠標放上去的時候 先保存當前行的背景顏色 并給附一顏色
                e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='yellow',this.style.fontWeight='';");
                //當鼠標離開的時候 將背景顏色還原的以前的顏色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
            }
            //單擊行改變行背景顏色
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onclick", "this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';");
            }
        }

    主站蜘蛛池模板: 亚洲乱亚洲乱妇无码麻豆| 成年女人免费碰碰视频| 亚洲色WWW成人永久网址| 国产精品亚洲天堂| xvideos亚洲永久网址| 国产精品观看在线亚洲人成网| 日韩一级免费视频| 黄网站色视频免费观看45分钟| 免费一级毛片清高播放| 一级人做人a爰免费视频| 亚洲熟女一区二区三区| 久久久高清日本道免费观看| 亚洲人成在线电影| 97热久久免费频精品99| 亚洲爆乳少妇无码激情| 亚洲国产精品一区二区第一页免 | 亚洲成人福利网站| 黄页免费的网站勿入免费直接进入| ass亚洲**毛茸茸pics| 国内自产少妇自拍区免费| 精品久久亚洲一级α| 国产L精品国产亚洲区久久| 光棍天堂免费手机观看在线观看 | 国产一区二区三区无码免费| www在线观看播放免费视频日本| 国产AV无码专区亚洲AV男同 | 久久久久亚洲av无码专区蜜芽| 7m凹凸精品分类大全免费| 亚洲狠狠成人综合网| 免费va在线观看| 久久免费观看国产精品88av| 久久亚洲精品国产亚洲老地址| 亚洲AV无码乱码在线观看牲色| 国产成人无码区免费内射一片色欲| 亚洲AV无码久久久久网站蜜桃| 国产免费卡一卡三卡乱码| 免费国产成人午夜在线观看| 中文字幕亚洲综合小综合在线 | 野花香高清在线观看视频播放免费 | 免费观看黄色的网站| 四虎影视在线看免费观看|