hi i want to change the color of rows in a datasheet that is i want each rows to be of one color. Is it possible?

Dani AI

Generated

A few quick, practical options depending on what you actually want: a single uniform row color, alternating row colors, or data‑driven per‑row colors. asked for DataGrid behavior; and already pointed to control properties and a server-side approach. Below are clearer, maintainable patterns and pitfalls to watch for.

For a simple, global style (fast and easy): give the DataGrid a CssClass and style its table rows with regular CSS so the browser does the work (no server loop per row).

<asp:DataGrid ID="dg" runat="server" CssClass="myGrid" ... />
.myGrid tr td { background-color: #f7f7f7; }

For alternating rows (built into the control): set the control markup styles so ASP.NET emits the proper row attributes without extra code.

<asp:DataGrid ID="dg" runat="server">
  <ItemStyle BackColor="#ffffff" />
  <AlternatingItemStyle BackColor="#f2f2f2" />
</asp:DataGrid>

For data-driven coloring (what suggested): use the row/item data‑bound event but follow best practice — only act for data rows (skip header/footer), minimize work per row, and assign a CSS class instead of inline colors so theming and maintenance stay simple. If you have thousands of rows, consider computing the color as part of the query or data projection rather than doing heavy logic in the event handler.

Notes and gotchas: DataGrid is an older WebForms control — prefer GridView in new work (it has similar RowStyle/AlternatingRowStyle/RowDataBound hooks). Inline BackColor values take precedence over stylesheet rules, so prefer CssClass for predictable theming. If using client‑side libraries, you can handle odd/even styling quickly in the browser for purely visual effects.

Recommended Answers

All 3 Replies

What's a datasheet? do you mean a DataGrid or GridView control? just set the BackgroundColor property.

For Datagrid

if u want to change the datagrid color,,,,
Use datagrid_itemdatabound()
If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim value As String = Trim(e.Item.DataItem("Sex"))
If value = "male" Then
e.Item.BackColor = System.Drawing.Color.Chocolate ' i is the index of the particular column
End If
End If
--------------
change according to ur requirement...!!
regards,,,
preetham....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.