Align a label to the right using ASP.Net
Solution 1
Try something like this:
<div style="text-align:right">
<asp:Label ID="myLabel" runat="server" Text="Label"></asp:Label>
</div>
Solution 2
You could put the label in a div and in the label tag put style="float:left"
.
<div>
<asp:label ID="myLabel" runat="server" style="float:right"></asp:Label>
</div>
Edit:
Also, for completeness, as mentioned by Aimal Khan you can use it in the code behind as:
myLabel.Attributes.Add("Style", "float: right");
![Johnny Bones](https://i.stack.imgur.com/oMs90.jpg?s=256&g=1)
Johnny Bones
Microsoft Access guru, SQL Server master and C# novice. Also worked with HTML, Javascript, VBScript, Visual Basic, Enterprise software, Windows NT Server Author of the World Famous request that killed a badge! I am always available for consultation at computercio at yahoo.com if you would like further instruction or require database design contractors.
Updated on August 31, 2020Comments
-
Johnny Bones almost 4 years
I have a label on an ASP.NET page. Right now, it looks like this:
What I want it to look like is like this:
I've tried using a DIV tag, and I've tried using Style="text-align: right" in the
<asp:Label>
tag, neither of which worked. Any suggestions?EDIT: As per the first comment, this is all inside a table tag:
<asp:Panel ID="Panel2" runat="server" BackColor="#0f6fc6" Height="110px" Width="780px"> <table style="width:780px"> <tr> <td style="width:90px"> <asp:Label ID="lblFunct" runat="server" Font-Bold="True" Text="Function" ForeColor="White"></asp:Label> </td> <td style="width:240px"> <asp:DropDownList ID="ddlFunction" runat="server" AutoPostBack="True" CssClass="textbox" Height="20px" OnSelectedIndexChanged="ddlFunction_SelectedIndexChanged" Width="230px"> </asp:DropDownList> </td> <td style="width:120px"> <asp:Label ID="lblRole" runat="server" Font-Bold="True" Text="Role" ForeColor="White"></asp:Label> </td> <td style="width:240px"> <asp:DropDownList ID="ddlRole" runat="server" AutoPostBack="True" CssClass="textbox" Height="20px" OnSelectedIndexChanged="ddlRole_SelectedIndexChanged" Width="230px"> </asp:DropDownList> </td> </tr> <tr> <td> <asp:Label ID="lblProd" runat="server" Font-Bold="True" Text="Prod Tasks" ForeColor="White"></asp:Label> </td> <td> <asp:DropDownList ID="ddlTask" runat="server" AutoPostBack="True" CssClass="textbox" Height="20px" OnSelectedIndexChanged="ddlTask_SelectedIndexChanged" Width="230px"> </asp:DropDownList> </td> <td> <asp:Label ID="lblOffprod" runat="server" Font-Bold="True" Text="Off Prod Tasks" ForeColor="White"></asp:Label> </td> <td> <asp:DropDownList ID="ddlOffprod" runat="server" AutoPostBack="True" CssClass="textbox" Height="20px" OnSelectedIndexChanged="ddlOffprod_SelectedIndexChanged" Width="230px"> </asp:DropDownList> </td> </tr> <tr> <td colspan="2"> <asp:RadioButtonList ID="rblPlatform" runat="server" EnableTheming="True" Font-Size="XX-Small" Height="10px" RepeatColumns="2" Visible="false" Width="270px" ForeColor="White" Font-Bold="True" TextAlign="Left"> <asp:ListItem Selected="True" Value="0">Facets </asp:ListItem> <asp:ListItem Value="1">Non-Facets</asp:ListItem> </asp:RadioButtonList> </td> <td colspan="2"> <asp:Label ID="lblAccountName" runat="server" Text="Label" ForeColor="White" Visible="true" Style="text-align: right"></asp:Label> </td> </tr> </table> </asp:Panel>
-
Aimal Khan almost 8 yearsused it in Code Behind as this --- createDiv2.Attributes.Add("Style", "float:right;"); --
-
Aimal Khan almost 8 yearsThank you for the idea! Cheers