I am facing a problem like this: I have it in HTML page:
<div class="bar bar-success" style="width:80%;"></div>
BUT I'd like to use this 80% comming from a database.
so I'd tried this:
<div id="Percent" runat="server" class="bar bar-warning" style='width: <%# DataBinder.Eval(Container.DataItem, "number") %> %'>
But It didn't work. Can anyone help me to save my problem?
You can convert it to a server control, a Panel
is rendered as a div.
<asp:Panel ID="PanelSuccessBar" CssClass="bar bar-success" runat="server"></asp:Panel>
codebehind:
// number is a double value that is comeing from database
PanelSuccessBar.Width = new Unit(number, UnitType.Percentage);
You will need to remove runat attribute from here if you want to set the inline width like below:
<div id="Percent" class="bar bar-warning" style='width: <%# DataBinder.Eval(Container.DataItem, "number") %> %'>
Otherwise you can set it from code behind:
<div id="Percent" runat="server" class="bar bar-warning" >
Percent.Style.Add("width", "YourDatabaseValue");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.