gridview列项样式不起作用

时间:2012-12-21 09:33:33

标签: vb.net gridview

我使用vb.net从DB填充网格视图问题是在绑定gridview之后我更改了项目stlye但是它给出了这个错误

Index was out of range. Must be non-negative and less than the size of the collection

这是我的代码

Public Sub loadnews()
        Try
            con.Open()
            Dim da As New OdbcDataAdapter("SELECT A.LABEL ""Highest"",A.VALUE||' '||A.DATED ""SML I (Jhang)"",b.VALUE||' '||b.DATED ""SML II (Bhone)"" FROM (SELECT * FROM CMS20122013.DNEWS_HIGHEST_J@CMS) A, (SELECT * FROM CMS20122013.DNEWS_HIGHEST_B@CMS) B WHERE A.SRLNUM=B.SRLNUM", con)
            Dim ds As New DataSet
            da.Fill(ds)
            GridView11.DataSource = ds
            GridView11.DataBind()
            GridView11.Columns(1).ItemStyle.Font.Bold = True
            con.Close()

        Catch ex As Exception
            Response.Write(ex.ToString())
        Finally
            con.Close()
        End Try
    End Sub

请帮助我如何在0

中加粗

2 个答案:

答案 0 :(得分:0)

使用此:

Dim i As Integer = 0
      For i = 0 To GridView11.Rows.Count - 1
    GridView11.Rows(i).Cells(0).Font.Bold = True
      Next

答案 1 :(得分:0)

使用RowDataBound事件:

Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
      e.Row.Cells(0).Font.Bold = True
    End If
End Sub