2013年4月25日 星期四

gridview + gridview


html
<asp:GridView ID="FileList" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"  DataSourceID="SqlDataSource1" EnableViewState="False">
     <Columns>
          <asp:TemplateField>
               <HeaderTemplate>
                    <asp:Label ID="Label1" runat="server" Text="展開"></asp:Label>
               </HeaderTemplate>
               <ItemTemplate>
                    <asp:ImageButton ID="colImageButton1" runat="server" CommandArgument='<%# Eval("ID") %>' ImageUrl="~/img/webmaster/col.gif" OnClick="colImageButton1_Click" Visible='<%# vis(Eval("ID")) %>' CausesValidation="False" />
               </ItemTemplate>
               <ItemStyle Width="7%" />
               <HeaderStyle Font-Size="10pt" CssClass="cell1" />
          </asp:TemplateField>
          ...
          ...
          ...
     </Columns>
</asp:GridView>


code

Protected Sub FileList_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles FileList.RowDataBound
        If Not (ViewState("cID") Is Nothing) Then
            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim drv As DataRowView = e.Row.DataItem
                Dim OrderID As String = CStr(ViewState("cID"))
                '判斷訂單編號相同的Row才要處理
                If CStr(drv.Item("ID")) = OrderID Then
                   
                    '產生新的GridViewRow
                    Dim gvRow As New GridViewRow(0, -1, DataControlRowType.DataRow, DataControlRowState.Normal)
                    '建立一個Cell
                    Dim lab1 As New Label
                    lab1.Text = "xxx"
                   
                    tCell.Controls.Add(lab1)
                    '設定合併Cell
                    tCell.Attributes.Add("colspan", "6")
                    'Cell放入GridViewRow
                    gvRow.Cells.Add(tCell)
                    'GridViewRow放到GridView中
                    e.Row.Parent.Controls.AddAt(e.Row.RowIndex + 2, gvRow)
                End If
            End If
        End If
    End Sub

沒有留言:

張貼留言