【jackyrong】asp.net 2.0常見問題技2

iDotNetSpace發表於2008-06-05
 一個detailview控制元件,用第一筆,上一筆,下一筆,最後一筆顯示記錄,還有可以有編輯,新增,刪除等功能,還可以根據下拉選單顯示頁數的一個程式.作為備用之用,而且是無重新整理的.
 
       

           
           

           
               
                   
               
           

                       
                           
                                                                    CellPadding="4" DataKeyNames="員工號碼" DataSourceID="LimingStudio" ForeColor="#333333"
                                    GridLines="None" Height="50px" Width="608px" nDataBound="DetailsView1_DataBound"
                                    nItemDeleted="DetailsView1_ItemDeleted" nItemInserted="DetailsView1_ItemInserted"
                                    nItemUpdated="DetailsView1_ItemUpdated" nPageIndexChanging="DetailsView1_PageIndexChanging">
                                   
                                   
                                   
                                   
                                   
                                   
                                                                                    SortExpression="員工號碼">
                                           
                                           
                                       

                                       
                                           
                                       

                                       
                                           
                                       

                                       
                                           
                                               
                                                   
                                                   
                                               

                                           

                                           
                                               
                                                   
                                                   
                                               

                                           

                                           
                                           
                                               
                                           

                                       

                                       
                                           
                                               
                                           

                                           
                                               
                                           

                                           
                                           
                                               
                                           

                                       

                                       
                                           
                                       

                                                                                    HeaderText="出生日期:" HtmlEncode="False" SortExpression="出生日期">
                                           
                                       

                                       
                                           
                                                 
                                                    已婚
                                                    未婚
                                               

                                           

                                           
                                               
                                                    已婚
                                                    未婚
                                               

                                           

                                           
                                           
                                               
                                           

                                       

                                                                                    HeaderText="到職日期:" HtmlEncode="False" SortExpression="到職日期">
                                           
                                       

                                       
                                           
                                       

                                       
                                           
                                       

                                                                                    HeaderText="加薪日期:" HtmlEncode="False" SortExpression="加薪日期">
                                           
                                       

                                       
                                           
                                                                                                    DataTextField="部門" DataValueField="部門" SelectedValue=''>
                                               

                                           

                                           
                                                                                                    DataTextField="部門" DataValueField="部門" SelectedValue=''>
                                               

                                           

                                           
                                           
                                               
                                           

                                       

                                       
                                           
                                                                                                    Text="更新" BackColor="White">
                                                                                                    Text="取消" BackColor="White">
                                           

                                           
                                                                                                    Text="插入" BackColor="White">
                                                                                                    Text="取消" BackColor="White">
                                           

                                           
                                           
                                                                                                    Text="編輯">
                                                                                                    Text="新增">
                                                                                                    nClientClick="return confirm('您確定要刪除此筆資料紀錄嗎?');" Text="刪除">
                                           

                                       

                                   

                                   
                                   
                                   
                                                                            Mode="NextPreviousFirstLast" NextPageImageUrl="~/Images/Next.gif" PreviousPageImageUrl="~/Images/Previous.gif" />
                                   
                                       
                                           
                                               
                                               
                                           
                                       

                                                    移至第
                                                   
                                                   
                                                    第一筆
                                                    上一筆
                                                    下一筆
                                                    最後一筆
                                               

                                                   
                                               

                                   

                               

                                                                    DeleteCommand="DELETE FROM [章立民工作室] WHERE [員工號碼] = @員工號碼" InsertCommand="INSERT INTO [章立民工作室] ([身份證號碼], [姓名], [性別], [地址], [郵政編碼], [出生日期], [婚姻狀況], [到職日期], [起薪], [目前薪資], [加薪日期], [部門]) VALUES (@身份證號碼, @姓名, @性別, @地址, @郵政編碼, @出生日期, @婚姻狀況, @到職日期, @起薪, @目前薪資, @加薪日期, @部門)"
                                    SelectCommand="SELECT * FROM [章立民工作室] " UpdateCommand="UPDATE [章立民工作室] SET [身份證號碼] = @身份證號碼, [姓名] = @姓名, [性別] = @性別, [地址] = @地址, [郵政編碼] = @郵政編碼, [出生日期] = @出生日期, [婚姻狀況] = @婚姻狀況, [到職日期] = @到職日期, [起薪] = @起薪, [目前薪資] = @目前薪資, [加薪日期] = @加薪日期, [部門] = @部門 WHERE [員工號碼] = @員工號碼">
                                   
                                       
                                   

                                   
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                   

                                   
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                   

                               

                                                                    SelectCommand="SELECT DISTINCT [部門] FROM [章立民工作室]">
                               
                           

                       

                   

       

   

 

protected void DetailsView1_DataBound(object sender, EventArgs e)
    {
        // 取得顯示頁數的那一列。
        DetailsViewRow pagerRow = this.DetailsView1.BottomPagerRow;

        // 取得"第一筆"、"上一筆"、"下一筆"與"最後一筆"的超級連結按鈕。
        LinkButton lnkBtnFirst = (LinkButton)(pagerRow.Cells[0].FindControl("lnkBtnFirst"));
        LinkButton lnkBtnPrev = (LinkButton)(pagerRow.Cells[0].FindControl("lnkBtnPrev"));
        LinkButton lnkBtnNext = (LinkButton)(pagerRow.Cells[0].FindControl("lnkBtnNext"));
        LinkButton lnkBtnLast = (LinkButton)(pagerRow.Cells[0].FindControl("lnkBtnLast"));

        // 設定何時應該啟用或停用"第一筆"、"上一筆"、"下一筆"與"最後一筆"的超級連結按鈕。
        if (this.DetailsView1.PageIndex == 0)
        {
            lnkBtnFirst.Enabled = false;
            lnkBtnPrev.Enabled = false;
        }
        else if (this.DetailsView1.PageIndex == this.DetailsView1.PageCount - 1)
        {
            lnkBtnLast.Enabled = false;
            lnkBtnNext.Enabled = false;
        }
        else if (this.DetailsView1.PageCount <= 0)
        {
            lnkBtnFirst.Enabled = false;
            lnkBtnPrev.Enabled = false;
            lnkBtnNext.Enabled = false;
            lnkBtnLast.Enabled = false;
        }

<

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-332345/,如需轉載,請註明出處,否則將追究法律責任。

相關文章