Telerik Grid Row color - asp.net

Is the only way to change the background color of a row based on data on the Telerik grid by doing it in the ItemDataBound event? I have a grid that a huge amount of data and it is taking a really long time. I have a property in the data row that tells me what color the row needs to be. I would like to be able to dynamically set the css class at runtime.
Thanks,
Rhonda

You should be able to change the row color using ItemStyle and AlternatingItemStyle:
<MasterTableView AutoGenerateColumns="false" ShowFooter="true">
<ItemStyle BackColor="PeachPuff" />

If you are looking to specifically change the style of the row during the OnItemDataBound event I recommend that you look at this documentation article from the Telerik online documentation. It covers how you can set inline styles from the code-behind, or use predefined CSS styles and apply them to the rows.

Related

Div produced from an ASP.Net GridView is too large

I have an ASP.Net GridView with properties like so:
<asp:GridView ID="grdOrderEntry" runat="server" AutoGenerateColumns="false" ShowFooter="True"
DataKeyNames="oid" Height="100%">
When I view the control in the browser, there is a lot of white space after the control. When viewing the HTML, the div that is produced by the GridView is much larger than the control, causing the whitespace. Is there a property I can set on the GridView to make the div as small as possible?
If you set the CssClass property you will be able to create some css to address the problem. I would recommend using a live css editor so you can mess around with it until you get the desired effect.
I suspect this is being caused by your Height="100%" attribute, remove that, and it should just stretch around the table it contains (unless there is some css other style added to it as well).

How can I create alternating background colors for listview rows while only using ItemTemplate?

How can I create alternating background colors for listview rows while only using ItemTemplate? I don't want to use AlternateTemplate because I would have to edit both of them everytime i want to change something when all I'm using it for is to create the alternating background colors. So what's a way I could do it using only the ItemTemplate? Thanks!
If you could consider the alternating colours a progressive enhancement and not absolutely required in all (old) browsers then you could use a CSS n-th child selector to apply the colour without changing the HTML.
If you have jQuery (or similar) in your project already and want a solution for older browser, you could use that to select every other row with the :odd or :even selector.
Update (Example)
Assuming we are using table rows
tr:nth-child(odd) td{
background-color: red;
}
You can also use even, 2n or 2n+1. This would work equally well with <li> tags.
More examples: http://reference.sitepoint.com/css/pseudoclass-nthchild
This might work too:
Alternating Table Row Colors with ASP.Net ListView Control
It uses the <%# style syntax in your ASPX page to toggle the class based on the DisplayIndex Mod 2.
C# and VB code samples on that link too...
Use the ItemDataBound event of the ListView (if it has one like the Repeater does). Add a runat="server" element to your ItemTemplate that you can use to set the color using a class. Get a reference to this control in the event and set the css class.
Have you tried using a Repeater control, instead of the ListView.
You'll have more control over the template, and it's easier to change alternating colors, w/out having duplicate templates.

aspx radiobutton control list in one line

http://www.codetoad.com/asp.net/aspnetcontrols11.asp
Is it possible to have radiobutton control list in one row. Now it is in 3 rows.
You need to use the RepeatDirection and RepeatLayout properties of the RedioButtonList control.
There are several ways of getting the layout you want - I suggest reading the documentation of both properties in order to make an informed decision on which one is most suitable for your situation.
In your RadioButtonList set the property of RepeatLayout="Flow" and RepeatDirection="Horizontial". This will make items in a radio button list horizontal instead of vertical.
Why dont you try adding each radio button to <div> or <li> tag and then set float:left in Css for each <li>. That way i think it will render in one line. Just make sure to set width:__ style to accommodate all radio buttons

Gridview height issue

This is a simple one but it is defeating me.
Ok, I have a gridview, lovely stuff. I have attempted to set the height of the headers so that the height is maintained regaardless of the content of the gridview.
However, if a data row requires a bit more height itself (to include the data), the height of the heading also increases.
How do I go about ensuring the height of the header is maintained but not at the expense of the data rows themselves?
GridView provides interesting styling features using asp.net tags in grid view, If you want to style height of a header, you can do something like this:
<asp:GridView id='grd' runat='server'>
<HeaderStyle Height="30px"/>
&lt/asp:GridView>
or in headerStyle you can also use CssClass where you can assign the css style class specified.
Hope this helps
I found the reason behind my mysterious expanding rows!!
Bascially, I had set the height of my gridview. When the gridview was full with data and resulted in paging, the heading remained as it should. However, the rows expanded when this gridview was below it's quota of data - essentially .net was being clever and trying to fill the space I had created by setting the height by expanding what it could.
All I did was to remove the height of my gridview and it worked a treat.
Thanks for all the pointers though : )
You can use styles to set almost all presentation attributes. Try out using a css or add style attributes.

How to set columns widths in a GridView control to the widest necessary width

I have a gridview control that can get loaded with multiple pages worth of data. When I switch pages, the columns widths will change to accommodate the largest value in the column for that page.
If possible, I would like to set the widths of each column to the widest necessary width for the entire dataset.
You can set the ItemStyle-Width property on each TemplateField, BoundField, etc. in your gridview to whatever you want. That should hold across paging. You will want to either not set the gridview width, or be sure you don't use a percentage if you do.
If you want to figure this out dynamically, you will have to examine your data first, before binding your grid, figure out the width that you want, then bind your gird and dynamically set the ItemStyle-Width in the RowDataBound event of the gridview.
Tring things, in the edit colum menu of your grid you should try the auto size mode, I configure my to cell and it work pretty well for my needs..
This is available when you are not autogenerating the columns.
Try it.

Resources