asp.net datalist - change styling - asp.net

<asp:DataList ID="ItemsList" RepeatDirection="Vertical" runat="server">
<ItemTemplate>
<asp:LinkButton
ID="SecondLevelItem" runat="server" CommandName="second"
OnCommand="SecondLevelItem_Onclick" CommandArgument="<%# Container.DataItem %>"
Text="<%# Container.DataItem %>" >
</asp:LinkButton>
</ItemTemplate>
</asp:DataList>
everything works fine. except that I do not have any control over the styling on the items. I mean I have the styling on the datalist externally but I want to add some spacing (vertically) between each item. How do I do tht? Thanks

In general, to control style, you can apply the <ItemStyle> tag inside the <asp:DataList>.
You can optionally inject CSS properties into the asp:LinkButton tag, either with the class attribute or directly with style, controlling the height or other CSS properties.
If it's applicable, you can still add a on the bottom of the template (but this will add a vertical space to the last item too, and I don't know if you want it).
Hope to have been of help.

In the code behind databound method for the list, you may be able to add a css class via the attributes collection.
In fact you may be able to that declartively too, just checking now...
eg asp:DataList id="blah" runat="server" ItemStyle-CssClass="someClass"

Related

Button position isn't changing despite adding style to it

I am trying to move the button to the right, and it's on a modal form if that somehow makes a difference, but it's not budging no matter what I do. I cannot create a separate CSS class for the code, just use the universal one.
Here's the code:
<asp:Panel ID="PnlUpdateSubjectPin" runat="server" CssClass="row" Visible="false">
<asp:Panel ID="Panel140" runat="server" CssClass="col-6">
<asp:Button ID="BtnGenNewPin" runat="server" Text="Generate Pin" CssClass="btn-success margin-left: 50px" />
You can't put the style elements in to the "class" you specify for that button.
Use a Style for things you want to add - the CssClass does NOT allow css, but ONLY allows you to specify existing css class(s) you want to use.
So, try this:
<asp:Button ID="BtnGenNewPin" runat="server"
Text="Generate Pin" CssClass="btn-success"
Style="margin-left:25px" />
the above should work just fine. So, don't try to put/shove css into the CssClass setting. You are free to use Style= in above, and it will be respected, and in fact should not mess nor bother with the existing class(s) you specified in the CssClass settings.
CssClass simple does not allow you to add or put css into that setting - only class(s) can be used by that setting.
Use Style -- you should be just fine.

how to place control in a td

I try to set two control in a td.
1. use a panel. as follow.
<td style="display: inline;">
<asp:Panel ID="pContainer" runat="server" Wrap="false">
<telerik:RadTextBox ID="rtxtBookingID" runat="server"></telerik:RadTextBox>
<asp:RequiredFieldValidator ID="rfvBookingID"
runat="server" ControlToValidate="rtxtBookingID" ErrorMessage="|Booking ID"
Display="Dynamic"></asp:RequiredFieldValidator>
<telerik:RadButton ID="rbtnOpen" runat="server" Text="Browse" OnClientClicked="openViewWindow()"/>
</asp:Panel>
</td>
how to solve the problem.
if I use two td to place the two control . but the first control in the td will gernerate a div. so the two control distance is far?
As long as it works and you get ok behaviour you are fine and for layout issues you should use css. The way you place the controls on the page also depends on overall page design and structure, keep in mind that usage of tables to control layout is not promoted anymore and you should use divs and css whenever possible... again depending on whole page design of course.

asp.net cssclass vs assigning class to asp.net object directly

I have a lot of code that I am reworking in which a single item is wrapped in a div block with a single linked cssstyle. There doesn't seem to be any real difference between wrapping the .Net object in the div and applying the style with the "cssstyle" property. Is there any real difference?
<div class="grid_1">
<asp:FormView ID="FormView8" runat="server" DataSourceID="odsInst">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" ToolTip='<%# Eval("TestScoresPageNrStudents")%>'>(?)</asp:LinkButton>
</ItemTemplate>
</asp:FormView>
</div>
vs
<asp:FormView ID="FormView8" runat="server" DataSourceID="odsInst" CssClass="grid_1">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" ToolTip='<%# Eval("TestScoresPageNrStudents")%>'>(?)</asp:LinkButton>
</ItemTemplate>
</asp:FormView>
The difference would be in the first case, it would render:
<div class="grid_1">
<table>...</table>
</div>
versus:
<table class="grid_1">...</table>
This would have an impact on how you would be able to design your css. My thought is that the first case (the <div>) would be preferable since it would gain more flexibility in designing your css classes -- mainly, you would not be restricted to being solely within a table. Of course, if the grid_1 class is solely for styling tabular data, then the second case would be fine.
It depends on what you need, but basically I guess you should be OK with the second approach since the ASP.NET controls will render some HTML element with the class attribute set to what you specified in CssClass="...".
I think it's best if you look at the HTML code rendered by the ASP.NET controls and if that's OK for you, then you can use the second approach (CssClass="...").
On the other hand, some controls might not exactly render the HTML code you need. E.g. the GridView probably renders a TABLE - if for some reason you really need a DIV element, then you'll have to wrap it as shown in approach one.
If you're keeping this a single item, no. However keep in mind, CSS priority is based on nested levels.
The lower the CSS is applied, the higher the priority it takes over other style classes.
Also, if you add more elements within this div, they will be effected if you keep the style on the container div.
In the first case, the "grid_1" class attribute is applied to the container tag.
In the second case, the "grid_1" class attribute is applied to the main tag of the asp:FormView control.
It is possible to define custom CSS rules for different tags, whose class equals "grid_1"

Why a radiobuttonlist always take a new row?

This is a question about layout. I'm developing a .net page, whenever I add a radiobuttonlist right after a label, it comes down to next row. But in the code side, it still within the same row. The problem is if you browse it in IE, it comes down to the next row. I am sure the width of both label and radiobuttonlist is not oversized. What's the reason and how to resolve this issue? Thanks in advance.
RadioButtonList by default renders as table. You can change set the property RepeatLayout="Flow" and it will be rendered in span.
RepeatLayout Property
Different ways it can render
Add a property to your radiobuttonlist
RepeatDirection="Horizontal"
<asp:RadioButtonList RepeatDirection="Horizontal"
ID="RadioButtonList1" runat="server" style="display:inline">
<asp:ListItem>asdf</asp:ListItem>
<asp:ListItem>sdfg</asp:ListItem>
</asp:RadioButtonList>
this will solve your problem. CHEERS
You can set it's display style to be inline:
<asp:RadioButtonList
ID="RadioButtonList1" runat="server" style="display:inline">
<asp:ListItem>asdf</asp:ListItem>
<asp:ListItem>sdfg</asp:ListItem>
</asp:RadioButtonList>
Warning: Purists will scream that information should be in a CSS class somewhere else.
if you have apply css on page, then it is hard to maintain style of radiobuttonlist.
Mine was fix with below code
#radiobuttonlist label
{
vertical-align: super;
}

Weird spacing of Checkbox labels

when I try to create a number of Checkboxes, I have strange spaces inserted:
image
<td style="width:85%;white-space:nowrap;" colspan=3>
<asp:CheckBox ID="rdoSchool" runat="server" Text="School (NSL)" />
<asp:CheckBox ID="rdoSFS" runat="server" Text="Summer Food Service" />
<asp:CheckBox ID="rdoOther" runat="server" Text="Other (Specify)" />&nbsp<asp:TextBox ID="txtOther" Width="125px" runat="server" />
</td>
How can I make the label closer to the checkbox?
This isn't default styling, and is most likely caused by your CSS. Use a tool like Firebug (on Firefox) or Developer Tools on IE8 to find the applied CSS rules (Should be F12 either way).
Take a look at the markup the CheckBox control generates.
... "Now there's your problem" - Adam Savage, Mythbusters.
Basically the CheckBox control (along with the RadioButtonList control) generates crappy markup. One way to fix this, is to extend and override the Render method to implement some sensible markup-generation code. Another option is to force the HTML-tables the control generates into place with some clever CSS tricks.

Resources