1

我正在使用 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列加粗

4

2 回答 2

0

用这个:

Dim i As Integer = 0
      For i = 0 To GridView11.Rows.Count - 1
    GridView11.Rows(i).Cells(0).Font.Bold = True
      Next
于 2012-12-21T09:39:52.960 回答
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
于 2012-12-21T09:49:45.433 回答