Couple of points to note (and the solution lies therein) :

1. Setting control widths to the fourth decimal place hardly makes
sense. A percent width using integers should be practically
sufficient.

2. The Width property is of type Unit, not Double. Therefore, you need
to convert the Double value to a Unit using one of the shared methods
of the Unit class.

3. Rather than showing you how to do it in code-behind, I show you how
to do it declaratively at :

<http://dotnetdevelopment.pastebin.com/f8070d0a>

Hope this makes things easier ! ;-)

On Jan 13, 10:11 pm, Noobintraining <[email protected]> wrote:
> I need to set the width of the LabelProgressBar2 to the value of num
> (default if the html is "Width="50.9999%"). It used the value of
> "score" (a 0 to 1 fraction) *100. This is all very new as I am juat
> getting stated so any and all constructive critisim is welcomed (of
> course a fix for the problem wouls be great too)  :).
>
> [code]
> <asp:GridView ID="GridView1" runat="server"
> OnRowDataBound="GridView1_RowDataBound">
>        <columns>
>         <asp:templatefield headertext="Percent Score">
>           <itemtemplate>
>
>           <asp:Label ID="ProgressBarContainer2" runat="server"
>             Height="22px" Width="220px" BackColor="Red"
>             Style="border-color: white; border-width: 3px; border-
> style: ridge;">
>             <asp:Label ID="LabelProgressBar2" runat="server"
>                 Style="padding-left: 2px; font-weight:bold;"
>                 Width="50.9999%"
>                 Text='<%# Bind("score", "{0:00.0000%}") %>'
>                 Height="100%"
>                 BackColor="Green">
>             </asp:Label>
>           </asp:Label>
>
>           </itemtemplate>
>          </asp:templatefield>
>         </columns>
>     </asp:GridView>
> [/code]
>
> The code behind snipit...
> [code]
>     protected void GridView1_RowDataBound(object sender,
> GridViewRowEventArgs e)
>     {
>         if (e.Row.RowType == DataControlRowType.DataRow)// Make sure
> it's a datarow
>         {
>             DataRow pr = ((DataRowView)e.Row.DataItem).Row;
>             double num = Convert.ToDouble(pr["score"]);
>             num *= 100;
>             if (num <= 99.9)// Establish threshold
>                 e.Row.Cells[4].ForeColor = System.Drawing.Color.Red;//
> Set text color to RED if less than threshold
>
> //Need to replace the value of the label width with num. The below is
> NOT working :(
>             Label barwidth = (label)e.Row.FindControl
> ("LabelProgressBar2");
>             barwidth.Width = num;
>
>         }
>     }
> [/code]

Reply via email to