开发者

Is it possible to change the color of a particular cell in a gridview?

开发者 https://www.devze.com 2023-01-08 18:23 出处:网络
I\'m displaying the days of a month in a grid. If the first day of the month star开发者_高级运维ts with Wednesday then I need to gray out the cells of Monday and Tuesday for the first week. Is it poss

I'm displaying the days of a month in a grid. If the first day of the month star开发者_高级运维ts with Wednesday then I need to gray out the cells of Monday and Tuesday for the first week. Is it possible to change the color of particular cell in a gridview? I'm not using rowdatabound. Is there any alternative apart from rowdatabound? Please help.


Unless there's an explicit reason why you don't want to use the RowDataBound event, I would say go ahead and use that.

If you absolutely don't want to use it; jQuery could probably do what you're looking for.


See if below code helps you out: It is based on a template field with a label inside.

Protected Sub grdTest_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)

   If e.Row.RowType = DataControlRowType.DataRow Then
      Dim lbl As Label = CType(e.Row.FindControl("lblMonth"), Label)
        If DataBinder.Eval(e.Row.DataItem, "weekStart") == "Wednesday" Then
          lbl.ForeColor = Drawing.Color.Gray   
        End If
   End If
End Sub
0

精彩评论

暂无评论...
验证码 换一张
取 消