Adding line-height style to a label in asp.net - asp.net

In my webpage there is label having multiple lines of text.
I need to add line-height property to that label in asp.net.
Thanks.

There are 2 ways to do this.
1) add a style for this. and give cssClass for that label.For example,
.line
{
line-height:150%;
}
And add the class to your label.
<asp:Label ID="Label1" runat="server" cssClass="line" />
2) Add style in code behind
Label1.Style.Add("line-height","150%");
Change the line-height value to whatever you want

Try below code:
LabelID.Style.Add("line-height", "100px")

Related

Align Checkbox in asp:TreeView

I have in my asp.net page asp:TreeView which generates checkboxes in codebehind.
<asp:TreeView ID="TreeView1" Width="250px" NodeWrap="true"
ExpandDepth="1 ShowCheckBoxes="All" runat="server">
</asp:TreeView>
In the code behind elements and child elements are generated in this fashion inside a resultset loop.
TreeNode tn1 = new TreeNode();
TreeNode tn2 = new TreeNode();
tn2.Text = "Child1";
tn2.Value = "Child2";
tn1.ChildNodes.Add(tn2);
However in the page the checkboxes are not aligned properly. I want to align them horizontally left.
Any suggestions please.
The treeview uses a specific HTML structure that is going to be hard to change... But you could look to using CSS to adjust the location of the checkboxes, or use an alternative control (repeater bound to a datasource that has an index parameter indicating how many spaces to indent, but this would not have the expand collapse functionality).
Added a css class and now whitespaces are removed before the checkboxes and horizontal alignment is working properly.
.tv table tbody tr
{
display: inline-block;
padding: 0px;
margin-left :5px;
width: 100%;
}
<asp:TreeView ID="TreeView1" CssClass="tv" NodeIndent="2" NodeWrap="true" ExpandDepth="1" ShowCheckBoxes="All" runat="server">

How can i change the color of dropdownlist arrow?

How can i change hover color of dropdownlist arrow button ? here when hover on dropdown its in blue color . i want change this to yellow . how can do this?
Alternate solution: use Ajax DropDownExtender you can easily change css style.
<ajaxToolkit:DropDownExtender runat="server" ID="DDE"
TargetControlID="TextLabel"
DropDownControlID="DropPanel" />
visit this link for demo:DropDown Demonstration
this will be done on page load
foreach(ListItem item in ddlName.Items) {
if(item.Value == "someStringValue") {
item.Attributes.Add("style", "color:red")
}
}
If that doesn't work, you can move this code to the DataBound event of the Drop Down List.

default border color for .net textbox

I change the border style and border color on a .net textbox to solid red respectively. After a postback I am attempting to return the textbox to its default values, but I cannot seem to get the color right. I have googled this, and tried to get the default values in the debugger, but the values in the debugger always look too dark of a gray when applied. Is there an easy way to return to the default look and feel of a textbox?
try this:
TextBoxTitle.BorderColor = System.Drawing.Color.Empty;
You can write two CSS classes:
.tb_with_border {
border: 1px #FF0000 solid;
}
.tb_without_border {
border: none;
}
.. and then you can change styles by assigning CssClass property of your textbox, for example:
Textbox1.CssClass = "tb_without_border";
or in markup:
<asp:TextBox id="Textbox1" runat="server" CssClass="tb_with_border" />
If you're just switching the particular element style off then this works:
Textbox1.BorderColor = Nothing
You should be using CSS to do this anyways...
Textbox1.Style.Remove("border")
txt_TextBox.BorderColor = System.Drawing.Color.Empty;
txt_TextBox.BorderStyle = BorderStyle.NotSet;
Simple. Add another textbox or dropdownlist with default values and make it hidden.
To RESET to defaults, just set your textbox's border color, width and style to that of the hidden textbox like so:
txtMyTextBoxToReset.BorderColor = txtHiddenTextBox.BorderColor;
txtMyTextBoxToReset.BorderWidth = txtHiddenTextBox.BorderWidth;
This works in all browsers and works for Drop down lists as well

Line break in Label

when i m writing a long sentence in label without line break then it does wrap automatically.
i m putting that label in tag. how can i wrap that long sentence.
Unclear, but you can force a line break by adding a <br /> in it.
<label>Some long long long long long long<br /> long long long label</label>
create style sheet like this "
.label { word-wrap: break-word }
and assign to you label
check the link for more detail : http://www.css3.com/css-word-break/
I'd hesitate to use the CSS3 solution without some kind of IE fallback.
You need to add the following CSS to your label:
label { display: block; width: 100px; }
Then change the width to the width you'd like your label to be and the sentence will wrap within the space.
By default a label has inline display which makes width control difficult.
If you still need the label to be inline with your input field, float the label.

ASP.NET How can i add superscript into a label control?

For example currently, the value is set with lblAmount.Text = Amount & " €"
How can i add (dynamically) superscript to the € sign?
use the SUP tag.
lblAmount.Text = Amount & "<sup>€</sup>"
You do this best by adding either a style attribute or by adding a class (and adding the style in a style tag or a css file.
<asp:Label id="lblAmount" runat="server"></asp:Label><asp:Label id="lblAmountSymbol" runat="server" CssClass="yourclass"></asp:Label>
span.yourclass {
font-size:9px;
vertical-align:top;
}
or
<asp:Label id="lblAmount" runat="server"></asp:Label><asp:Label id="lblAmountSymbol" runat="server"></asp:Label>
and this, in your code file
Me. lblAmount.Style.Add(HtmlTextWriterStyle.FontSize, "9px")
Me. lblAmount.Style.Add(HtmlTextWriterStyle.VerticalAlign, "top")
You could also use the html equivalent sup:
Me. lblAmount.Text = Amount & " <sup>€</sup>"
Goto Start->Programs->Accessories->System tools->Character Map
Now select this Character ² from the Characters listed.
Click Select
Click Copy
Then try to change the text of any control by pasting this Character in the Lable or Button Caption at Properties.
Even you can wrting code also like this:
Code\Button1.Text = "mm ²"\Code
This is working fine with me.

Resources