ASP.NET label text alignment
6 answers
When you add your label to the .aspx page, declare it using a CSS class or with style = "text-align: right;".
<asp:Label id="Label1" runat="server" width="100px" style="text-align: right;" />
If you want to change the alignment at runtime, your best bet is to change the CssClass property of the label.
Label1.CssClass = "right_align";
In your CSS:
.right_align { text-align: right; }
+9
source to share
I don't understand why you are trying to align behind the code. Place a label in a control on a page that has a specific alignment set. If you are creating a label in the code behind, create a control with a specific alignment, which can have a label programmatically inserted into it.
+3
source to share
In C #, as pseudocode for asp.Net:
var label = new Label();
label.TextAlign = ContentAlignment.MiddleRight; // Aligns to right
label.RightToLeft = RightToLeft.Yes; // Changed direction to rtl (might reverse the meaning of TextAlignment
Or if you want to use adding lines:
string pad, aaaa = "aaaa";
pad = aaaa.PadLeft(6); // " aaaa"
pad = aaaa.PadLeft(6, '-'); // "--aaaa"
pad = aaaa.PadRight(10); // "aaaa "
pad = aaaa.PadLeft(6).PadRight(8); // " aaaa "
pad = aaaa.PadLeft(6).PadRight(8, '.'); // " aaaa.."
+1
source to share