This is a migrated thread and some comments may be shown as answers.

Can not change backgound color of row of radgrid (Server side)

2 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kenghot
Top achievements
Rank 1
kenghot asked on 21 Apr 2008, 08:56 AM
Hi,
  I'm using radgrid (and skin = Vista )and i try to change row backgound color on event itemdatabound but it doesn't work. What should i do?

My code is

Protected Sub grdRoom_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles grdRoom.ItemDataBound

If e.Item.ItemType = Telerik.WebControls.GridItemType.Item Or e.Item.ItemType = Telerik.WebControls.GridItemType.AlternatingItem Then

Dim r As DataRow = CType(e.Item.DataItem, DataRowView).Row

Dim hpl As LinkButton = e.Item.FindControl("lnkRemark")

If r("remark") Is DBNull.Value OrElse r("remark").ToString.Trim = "" Then

hpl.Text =

"NoRemark<br>"

Else

hpl.Text =

"Remark<br>"

End If

If r("reply") Is DBNull.Value OrElse r("reply").ToString.Trim = "" Then

hpl.Text &=

"NoReply"

Else

hpl.Text &=

"Replied"

End If

hpl.OnClientClick = Master._Mdl._OpenRadWinString(

"./RoomReply.aspx?doc_no=" & r("doc_no").ToString.Trim _

, r(

"doc_no").ToString.Trim, 500, 500)

If r("cancel_request") Then

e.Item.BackColor = Drawing.Color.Red

else

e.Item.BackColor = Drawing.Color.Green

End

If

End If

End Sub


********* for aspx.vb ******

<

radG:RadGrid id="grdRoom" runat="server" Width="99%" GridLines="None" AutoGenerateColumns="False" SkinID="DefaultGrid" AllowSorting="True" AllowMultiRowSelection="True" EnableAJAX="True">

<

ExportSettings>

<

Pdf PageWidth="8.5in" PageRightMargin="" PageFooterMargin="" PageLeftMargin="" PageTopMargin="" PageHeight="11in" PageBottomMargin="" PageHeaderMargin=""></Pdf>

</

ExportSettings>

<

ClientSettings ApplyStylesOnClient="True" AllowColumnsReorder="True" ReorderColumnsOnClient="True">

<

Selecting AllowRowSelect="True"></Selecting>

</

ClientSettings>

<

MasterTableView><Columns>

<radG:GridClientSelectColumn UniqueName="ClientSelectColumn" />

<radG:GridTemplateColumn UniqueName="remarklink" HeaderText="Remark">

<ItemTemplate>

<asp:LinkButton ID="lnkRemark" runat="server">LinkButton</asp:LinkButton>

</ItemTemplate>

<HeaderStyle Width="100px" />

</radG:GridTemplateColumn>

<radG:GridBoundColumn DataField="room_code" HeaderText="Room" SortExpression="room_code"

UniqueName="room_code">

<HeaderStyle Width="30px" />

</radG:GridBoundColumn>

<radG:GridBoundColumn DataField="meeting_title" HeaderText="Title" SortExpression="meeting_title"

UniqueName="meeting_title">

<HeaderStyle Width="200px" />

</radG:GridBoundColumn>

<radG:GridBoundColumn DataField="request_by" HeaderText="Name" SortExpression="request_by"

UniqueName="user_name">

<HeaderStyle Width="200px" />

</radG:GridBoundColumn>

<radG:GridBoundColumn DataField="tel_no" HeaderText="Tel" UniqueName="tel_no">

<HeaderStyle Width="50px" />

</radG:GridBoundColumn>

<

radG:GridBoundColumn DataField="room_area_name" UniqueName="room_area_name" HeaderText="Area.">

<

HeaderStyle Width="150px"></HeaderStyle>

</

radG:GridBoundColumn>

<radG:GridBoundColumn DataField="use_date" DataFormatString="{0:dd/MM/yy}" HeaderText="Date"

SortExpression="use_date" UniqueName="use_date">

<HeaderStyle Width="60px" />

</radG:GridBoundColumn>

<

radG:GridBoundColumn DataField="start_datetime" DataType="System.DateTime" UniqueName="start_datetime" SortExpression="start_datetime" HeaderText="Start" DataFormatString="{0:HH:mm}">

<HeaderStyle Width="50px" />

</

radG:GridBoundColumn>

<

radG:GridBoundColumn DataField="end_datetime_disp" DataType="System.DateTime" UniqueName="end_datetime_disp" SortExpression="end_datetime_disp" HeaderText="End" DataFormatString="{0:HH:mm}">

<HeaderStyle Width="50px" />

</

radG:GridBoundColumn>

<radG:GridBoundColumn DataField="user_code" UniqueName="user_code" Visible="False">

</radG:GridBoundColumn>

<radG:GridBoundColumn DataField="doc_no" UniqueName="doc_no" Visible="False">

</radG:GridBoundColumn>

<radG:GridBoundColumn DataField="total_audience" HeaderText="Seats" SortExpression="total_audience"

UniqueName="total_audience">

<HeaderStyle Width="20px" />

</radG:GridBoundColumn>

<radG:GridBoundColumn DataField="end_datetime" UniqueName="end_datetime" Visible="False">

</radG:GridBoundColumn>

<radG:GridBoundColumn DataField="floor" UniqueName="floor" Visible="False">

</radG:GridBoundColumn>

<radG:GridBoundColumn DataField="alignment_format" UniqueName="alignment_format" Visible="False">

</radG:GridBoundColumn>

<radG:GridBoundColumn DataField="total_mic" UniqueName="total_mic" Visible="False">

</radG:GridBoundColumn>

<radG:GridBoundColumn DataField="projector" UniqueName="projector" Visible="False">

</radG:GridBoundColumn>

<radG:GridBoundColumn DataField="requested_by" UniqueName="request_by" Visible="False">

</radG:GridBoundColumn>

<radG:GridBoundColumn DataField="remark" UniqueName="remark" Visible="False">

</radG:GridBoundColumn>

<radG:GridBoundColumn DataField="dept_name" UniqueName="dept_name" Visible="False">

</radG:GridBoundColumn>

<radG:GridBoundColumn DataField="div_name" UniqueName="div_name" Visible="False">

</radG:GridBoundColumn>

<radG:GridBoundColumn DataField="comp_name" UniqueName="comp_name" Visible="False">

</radG:GridBoundColumn>

<

radG:GridBoundColumn DataField="room_name" UniqueName="room_name" HeaderText="Room Name." Visible="False">

<

HeaderStyle Width="200px"></HeaderStyle>

</

radG:GridBoundColumn>

</

Columns>

<

ExpandCollapseColumn Visible="False" Resizable="False">

<

HeaderStyle Width="20px"></HeaderStyle>

</

ExpandCollapseColumn>

<

RowIndicatorColumn Visible="False">

<

HeaderStyle Width="20px"></HeaderStyle>

</

RowIndicatorColumn>

</

MasterTableView>

</

radG:RadGrid>



BR,
Kenghot

2 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 22 Apr 2008, 07:52 AM
Hi,

I tested the functionality that you mentioned, and the control behaved as expected.
Attached to this message, is the sample, which I used for testing.
I hope it helps.

Sincerely yours,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Dimo
Telerik team
answered on 22 Apr 2008, 08:19 AM
Hello,

Just a small hint in addition: as you know, RadGrid items are in fact table rows (<tr> elements). If you set a background to a table row, you must not set a background to the table cells, otherwise the <tr> background will remain below the <td> background.

This could be the reason why the item background is not seen. Please check your CSS code for background styles set to <td>'s.

Kind regards,
Dimo
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
kenghot
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Dimo
Telerik team
Share this question
or