2012-12-21 77 views
1

我用vb.net問題是綁定在GridView後,我改變了項目stlye填充從數據庫網格視圖,但它給這個錯誤gridview的列項的風格不工作

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 [email protected]) A, (SELECT * FROM [email protected]) 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

回答

0

使用此:

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

是否加工正確 – user1915635

+0

使用這個答案wihtout ItemStyle –

+0

此進行了大膽的只有拳頭item.cani大膽整列? – user1915635

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 
+0

嗯好主意好友 – user1915635