is there a way for me to set a back color for a certain row like. row 1 backcolor is red, row 4 pink, row 9 blue.
Also, is there a away to align the column to the right on certain column?. like column1 right, 3 left, 7 right, etc...
Also, is there a away to align the column to the right on certain column?. like column1 right, 3 left, 7 right, etc...
8 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 29 Sep 2009, 11:10 AM
Hello Duy,
1) You can try out the following code to set the backcolor for rows based on the row index:
c#:
2) You can set the HorizontalAlign property of the columns as shown below:
c#:
-Princy.
1) You can try out the following code to set the backcolor for rows based on the row index:
c#:
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridDataItem && e.Item.OwnerTableView.Name=="Detail") |
| { |
| GridDataItem item = (GridDataItem)e.Item; |
| switch (item.ItemIndex) |
| { |
| case 0: |
| item.BackColor = System.Drawing.Color.Red; |
| break; |
| case 3: |
| item.BackColor = System.Drawing.Color.Pink; |
| break; |
| case 8: |
| item.BackColor = System.Drawing.Color.Blue; |
| break; |
| default: |
| break; |
| } |
| } |
| } |
2) You can set the HorizontalAlign property of the columns as shown below:
c#:
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| RadGrid1.MasterTableView.Columns[0].ItemStyle.HorizontalAlign = RadGrid1.MasterTableView.Columns[6].ItemStyle.HorizontalAlign = HorizontalAlign.Right; |
| } |
-Princy.
0
appdev
Top achievements
Rank 1
answered on 29 Sep 2009, 03:16 PM
i did this and it work
now what i want to do is instead of getting the index number of a row. is there a way for me to do this:
if cell (3,3) is empty then change the background of that row and also freeze that row for scrolling, and also do a cell(3,3) and cell(4,3) merge with each other into 1 cell. suppose (x,y)
i also tried to do
| If e.Item.OwnerTableView.Name = "Detail" Then |
| Select Case e.Item.ItemIndex |
| Case 0 |
| e.Item.BackColor = System.Drawing.Color.Red |
| Exit Select |
| Case 3 |
| e.Item.BackColor = System.Drawing.Color.Pink |
| Exit Select |
| Case 8 |
| e.Item.BackColor = System.Drawing.Color.Blue |
| Exit Select |
| Case Else |
| Exit Select |
| End Select |
| End If |
now what i want to do is instead of getting the index number of a row. is there a way for me to do this:
if cell (3,3) is empty then change the background of that row and also freeze that row for scrolling, and also do a cell(3,3) and cell(4,3) merge with each other into 1 cell. suppose (x,y)
i also tried to do
e.OwnerTableView.CommandItemStyle.Wrap =
False
but the text still get wrapped. thank you for your help.
0
appdev
Top achievements
Rank 1
answered on 30 Sep 2009, 10:41 AM
any idea guys? thanks.
0
Hi Duy,
Please use the following example as a reference:
Best wishes,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Please use the following example as a reference:
| <%@ Page Language="C#" %> |
| <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <script runat="server"> |
| protected void RadGrid1_PreRender(object sender, EventArgs e) |
| { |
| RadGrid grid = sender as RadGrid; |
| foreach (GridItem item in grid.Items) |
| { |
| if (item is GridDataItem) |
| { |
| foreach (GridColumn col in grid.MasterTableView.RenderColumns) |
| { |
| if (col is GridBoundColumn && grid.Items.Count > item.ItemIndex + 1 && |
| String.IsNullOrEmpty(((item as GridDataItem)[col.UniqueName] as TableCell).Text.Replace(" ", "").Trim())) |
| { |
| ((item as GridDataItem)[col.UniqueName] as TableCell).Attributes.Add("rowspan", "2"); |
| (grid.Items[item.ItemIndex + 1] as GridDataItem)[col.UniqueName].Visible = false; |
| } |
| } |
| } |
| } |
| } |
| </script> |
| <html xmlns="http://www.w3.org/1999/xhtml" > |
| <head runat="server"> |
| <meta http-equiv="content-type" content="text/html;charset=utf-8" /> |
| <title>RadControls for ASP.NET AJAX</title> |
| </head> |
| <body> |
| <form id="form1" runat="server"> |
| <asp:ScriptManager ID="ScriptManager1" runat="server" /> |
| <telerik:RadGrid |
| ID="RadGrid1" |
| runat="server" |
| Skin="Office2007" |
| DataSourceID="XmlDataSource1" |
| OnPreRender="RadGrid1_PreRender" /> |
| <asp:XmlDataSource ID="XmlDataSource1" runat="server"> |
| <Data> |
| <nodes> |
| <node Column1="Row 1 Value 1" Column2="Row 1 Value 2" Column3="Row 1 Value 3" Column4="Row 1 Value 4" /> |
| <node Column1="Row 2 Value 1" Column2="Row 2 Value 2" Column3="Row 2 Value 3" Column4="Row 2 Value 4" /> |
| <node Column1="Row 3 Value 1" Column2="Row 3 Value 2" Column3="" Column4="Row 3 Value 4" /> |
| <node Column1="Row 4 Value 1" Column2="Row 4 Value 2" Column3="Row 4 Value 3" Column4="Row 4 Value 4" /> |
| </nodes> |
| </Data> |
| </asp:XmlDataSource> |
| </form> |
| </body> |
| </html> |
Best wishes,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
appdev
Top achievements
Rank 1
answered on 30 Sep 2009, 01:47 PM
why does it keep automatically wrap my contain. like i have -20000000000 and the header is Price
Price
-20000000
it keeps doing this
-
20000000
and if my header is %Chg it will do
%
Chg
is there a way for me to prevent this? and let the width of each cell be 100%?
Price
-20000000
it keeps doing this
-
20000000
and if my header is %Chg it will do
%
Chg
is there a way for me to prevent this? and let the width of each cell be 100%?
0
Hello Duy,
Please provide your RadGrid declaration or a sample page, like the one I included in my previous mesage.
Best wishes,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Please provide your RadGrid declaration or a sample page, like the one I included in my previous mesage.
Best wishes,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
appdev
Top achievements
Rank 1
answered on 30 Sep 2009, 02:05 PM
| <telerik:RadGrid AutoGenerateColumns="true" ID="RadGrid1" Visible="false" MasterTableView-EnableNoRecordsTemplate="true" |
| Width="100%" AllowSorting="True" GridLines="vertical" Skin="Telerik" |
| PageSize="100" ShowStatusBar="true" AllowPaging="True" |
| runat="server" OnExcelMLExportStylesCreated="RadGrid1_ExcelMLExportStylesCreated" |
| OnExcelMLExportRowCreated="RadGrid1_ExcelMLExportRowCreated"> |
| <PagerStyle Mode="NextPrevAndNumeric" /> |
| <ClientSettings EnableRowHoverStyle="true"> |
| <Selecting AllowRowSelect="True" /> |
| </ClientSettings> |
| <MasterTableView Summary="testing" ></MasterTableView> |
| </telerik:RadGrid> |
0
Hi Duy,
The provided RadGrid declaration is not adequate for us to replicate your problem. Please send us a sample page, which will runnable without making additions or modifications to it - like the one I sent in my previous post.
At any rate, you will probably have to increase the column widths.
Sincerely yours,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
The provided RadGrid declaration is not adequate for us to replicate your problem. Please send us a sample page, which will runnable without making additions or modifications to it - like the one I sent in my previous post.
At any rate, you will probably have to increase the column widths.
Sincerely yours,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
