<asp:datagrid id="DGPersonList" runat="server" Width="100%" BorderColor="#999999" BorderStyle="None"
BorderWidth="1px" BackColor="White" CellPadding="3" GridLines="Vertical">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle ForeColor="Black" BackColor="#EEEEEE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#000084"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#CCCCCC"></FooterStyle>
<Columns>
<asp:ButtonColumn Text="选择" HeaderText="选取" CommandName="Select"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="Black" BackColor="#999999" Mode="NumericPages"></PagerStyle>
</asp:datagrid></td>
其中:<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
是你要的东西!
dotnet带了一些风格的样子,你可以借鉴看看。我的这个就是用那个生成的!

解决方案 »

  1.   

    我下面有一個例子,希望對你有幫助...
    datagrid 的樣式表(DataGridTableStyle)應用... 
    首先 我們先定一個 datatable 和 一個datarow  Private idtb_temp As New DataTable
      Private idrw_row As DataRow  private sub GetDataTable()
             idtb_temp.Columns.Add("prdodr_subodr_code")              '''定義datatable 的列名        idtb_temp.TableName = "SearchTable"
            Dim ldcl_header As Windows.Forms.DataGridTextBoxColumn
            Dim ldgts_styles As New Windows.Forms.DataGridTableStyle
            ldgts_styles.SelectionForeColor = System.Drawing.Color.Yellow   
             '''選中行的前景色,即字體顏色
            ldgts_styles.SelectionBackColor = System.Drawing.Color.Brown     '''選中行的背景色        ldgts_styles.ForeColor = System.Drawing.Color.Coral           
            ''' datagrid 中將要顯示的字的顏色
            ldgts_styles.AlternatingBackColor = System.Drawing.Color.Cyan   
             '''datagrid中奇數行所顯示的顏色
            ldgts_styles.BackColor = System.Drawing.Color.Cyan            
           '''datagrid中偶數行所顯示的顏色        ldgts_styles.AllowSorting = False                              
             '''些樣式表定義datagrid不允許自動排序..        ldgts_styles.MappingName = "SearchTable"        ldcl_header = New Windows.Forms.DataGridTextBoxColumn          
             '''實例化一個datagridtextboxcolumn
            ldcl_header.MappingName = "prdodr_subodr_code"         
            '''引用前面定義的 “列名”
            ldcl_header.HeaderText = "第一列"                                                
           '''datagrid 中顯示的 表列頭 文字
            ldcl_header.ReadOnly = True            '''些列設定為只讀
            ldcl_header.TextBox.BorderStyle = BorderStyle.Fixed3D
            ldcl_header.TextBox.ForeColor = System.Drawing.Color.Red        ldgts_styles.GridColumnStyles.Add(ldcl_header)        For i As Integer = 0 To 7
                idrw_row = idtb_temp.NewRow
                idrw_row.Item("prdodr_subodr_code") = "第" & i & "行"
                idtb_temp.Rows.Add(idrw_row)        Next        idtb_temp.DefaultView.AllowNew = False
            Me.DataGrid1.TableStyles.Add(ldgts_styles)
            Me.DataGrid1.DataSource = idtb_temp
      end sub