国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
ASP.NET2.0下含有DropDownList的GridView編輯、刪除的完整例子!...
 

<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="序號(hào)">
                                <ItemTemplate>
                                <%# this.GridView1.PageIndex * this.GridView1.PageSize + this.GridView1.Rows.Count + 1%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="學(xué)歷代碼" 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="學(xué)歷名稱" 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(‘確認(rèn)要編輯嗎?‘);"></asp:LinkButton>
                       
                            <asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" CommandName="Delete"
                                Text="刪除" OnClientClick="return confirm(‘確認(rèn)要?jiǎng)h除嗎?‘);"></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>
    /// 綁定數(shù)據(jù)到GridView
    /// </summary>
    private void GridViewBind()
    {
        檢索數(shù)據(jù)庫(kù)
        string strSql = "SELECT * FROM DB1";
        得到數(shù)據(jù)集
        this.GridView1.DataSource=conn.GetDs(strSql).Tables[0].DefaultView;
        this.GridView1.DataBind();
  
    }
    /// <summary>
    /// 編輯當(dāng)前行
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        //當(dāng)前編輯行背景色高亮
        this.GridView1.EditRowStyle.BackColor = Color.FromName("#F7CE90");
        GridViewBind();
    }
    /// <summary>
    /// 取消編輯狀態(tài)
    /// </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)
    {
        //得到單位編號(hào)
        string rowToDelete = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
        //轉(zhuǎn)換為整數(shù)
        //int ID=Convert.ToInt32(rowToDelete);
        //從數(shù)據(jù)庫(kù)中刪除
        string str = "DELETE FROM DB1 where DB1_1=" + "‘" + rowToDelete + "‘" + "";
      
        try
        {
        conn.RunSql(str);
        //重新綁定數(shù)據(jù)
        GridViewBind();
        }
        catch (Exception ex)
        {
        Response.Write("數(shù)據(jù)庫(kù)錯(cuò)誤,錯(cuò)誤原因:" + 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;
       
    //判斷表單項(xiàng)是否有空并給出提示信息
        if (DB1_1 == "" || DB1_2 == "")
        {
            conn.Alert("請(qǐng)輸入完整信息!", 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("錯(cuò)誤:已存在具有相同主鍵的記錄", Page);
            else
                conn.Alert("錯(cuò)誤:未能添加記錄", Page);
        }

        Response.Write("<script language=‘javascript‘>alert(‘?dāng)?shù)據(jù)已被保存!‘);</script>");
        //返回瀏覽狀態(tài)
        GridView1.EditIndex = -1;
        GridViewBind();
    }
    /// <summary>
    /// 分頁(yè)事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridViewBind();
    }
    /// <summary>
    /// 加入鼠標(biāo)效果及為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("學(xué)士", "3"));
        }

        //加入鼠標(biāo)滑過的高亮效果
        if (e.Row.RowType == DataControlRowType.DataRow)//判定當(dāng)前的行是否屬于datarow類型的行
        {
            //當(dāng)鼠標(biāo)放上去的時(shí)候 先保存當(dāng)前行的背景顏色 并給附一顏色
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor=‘yellow‘,this.style.fontWeight=‘‘;");
            //當(dāng)鼠標(biāo)離開的時(shí)候 將背景顏色還原的以前的顏色
            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‘;");
        }
    }

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
GridView和下拉菜單DropDownList結(jié)合
Asp.Net中GridView加入鼠標(biāo)滑過的高亮效果和單擊行顏色改變
asp.net2.0中使用存儲(chǔ)過程的方法
gridview 編輯,刪除,更新的用法
含有dropdownlist的gridview增刪改查
GridView鼠標(biāo)停留變色,行單擊事件處理
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服