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

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

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

    注銷

    注銷

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      112 隨筆 :: 7 文章 :: 18 評論 :: 0 Trackbacks
    在應用程序中,我需要在一個DataGrid中每顯示10條紀錄后便添加一個空行,我們可以簡單的修改DataTable,并且在DataGrid中的ItemDataBound 事件書寫一些代碼來實現,下面的文章將闡述如何做到這一點。

    In one application I had the requirement to add a blank row after every 10 rows in a DataGrid rather than use paging as shown in FIGURE 1. There is no in-built way to do this with the DataGrid, but it can be easily done by modifying the DataTable that the DataGrid is bound to and by writing some code in the DataGrids ItemDataBound event. The rest of this article will describe how it is done.


    添加空行到DataTable
    Adding Blank Rows to the DataTable



    每10條紀錄添加一個空行看起來使用一個簡單的循環就可以做到
    To add a blank row every 10 rows seems simple enough to do using a for loop with a counter. I knew that I could not use a for each loop due to me adding new items to the collection within the loop. As it turns out, you cannot use a for loop with a counter as the upper bound of the loop is not re-evaluated on every iteration! This means that the only way to loop through the item collection is to use a while loop with a counter.

    To keep track of when to add a blank row, another counter is used that is decremented. When this counter reaches 1, a new row is added to the DataTable and is then reset. At the same time, the upper bound is incremented to note the addition of the new row.

    The code below shows a function that can be used to add blank rows to the first DataTable in any DataSet. As you can see, the row is not actually blank. The first column in the row is given the negative of the counter. When the DataRow is inspected in the ItemDataBound event, the fact that it is a negative value can be used to note that this should be displayed as a blank row in the DataGrid. In this case, the first column in the DataSet that was used was a Primary Key and could not be blank, and I knew that the values from the database would all be positive. When implementing this yourself you can use whatever identifier is suitable for your scenario.

    Private Function addBlankLines(ByVal ds As DataSet) As DataSet

    Dim dr, drBlank As DataRow
    Dim count, repeatCount, upperBound As Integer

    repeatCount = 10 @#used to keep track of when to add a @#blank@# row
    upperBound = ds.Tables(0).Rows.Count

    While count <= upperBound

    If repeatCount = 1 Then

    drBlank = ds.Tables(0).NewRow
    drBlank(0) = -count
    ds.Tables(0).Rows.InsertAt(drBlank, count + 1)
    count += 1
    upperBound += 1
    repeatCount = 10

    Else

    repeatCount -= 1

    End If

    count += 1

    End While

    Return ds

    End Function



    把空行反映到DataGrid中
    Rendering the Blank Rows to the DataGrid

    After adding the blank rows to the DataTable, the next step is to render the blank rows in the DataGrid. To do this, a few lines in the DataGrid ItemDataBound event are required. The first thing to do is check to see if the item is an Item or Alternating item as this event fires for both the header and the footer of the DataGrid. The underlying DataRow that the ListItem is bound to can then be accessed to check the value in the first column to see if the value it contains denotes that it should be rendered as a blank row. The code below sets the text of the first cell to contain so as to make the blank row visible, and sets the BackColor to White (the rest of the rows are presented in a different color). This code can be easily adapted to allow you to render whatever format of blank row that you want.

    Private Sub dgResults_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgResults.ItemDataBound
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then

    If CType(CType(e.Item.DataItem, DataRowView).Row.Item(0), Integer) < 0 Then
    e.Item.Cells(0).Text = "&nbsp;"
    e.Item.BackColor = System.Drawing.Color.White
    End If

    End If

    End Sub


    Alternative Use

    One alternative use for the idea and code presented here is to create a running total row. As the DataTable is looped through, a running total can be kept and that value inserted into the correct column in the DataTable. Instead of rendering a blank row in the DataGrid, it can be rendered in another format.
    posted on 2006-11-08 14:49 注銷..... 閱讀(226) 評論(0)  編輯  收藏 所屬分類: .net摘要
    主站蜘蛛池模板: 日韩免费无砖专区2020狼| jjizz全部免费看片| 国内大片在线免费看| 日产亚洲一区二区三区| 四虎国产精品免费永久在线| 亚洲精品一级无码中文字幕| 色天使色婷婷在线影院亚洲| 国产在线不卡免费播放| 免费无码婬片aaa直播表情| 免费国产不卡午夜福在线| 羞羞网站在线免费观看| 亚洲国产综合无码一区二区二三区| 国产91成人精品亚洲精品| 亚洲精品无码av天堂| www在线观看播放免费视频日本| 亚洲精品无码专区2| 最近国语视频在线观看免费播放| 亚洲欧洲∨国产一区二区三区| 免费无码又爽又刺激一高潮| 亚洲一区二区影院| 国产精彩免费视频| 亚洲人成色777777老人头| 国产一区在线观看免费| 伊人久久大香线蕉免费视频| 国产亚洲精品岁国产微拍精品| 国产成人精品免费久久久久| 久久亚洲最大成人网4438| 精品久久洲久久久久护士免费| 一级女人18片毛片免费视频| 久久久久亚洲精品成人网小说| 国产精品成人观看视频免费| 日韩欧美亚洲中文乱码| 亚洲国产另类久久久精品黑人 | 91亚洲导航深夜福利| 成人影片麻豆国产影片免费观看| 国产精品亚洲一区二区三区久久 | 午夜亚洲国产精品福利| 国产自偷亚洲精品页65页| 日韩免费人妻AV无码专区蜜桃| 在线亚洲高清揄拍自拍一品区| 亚洲精品99久久久久中文字幕|