locked
Color coding of my row header RRS feed

  • Question

  • User-1594116085 posted

    Hi,

    I have a formview in a custom Edit page

    I have 4 colum

    <td ID="Title Line">line name</td>

    <td>dynamic control1</td>

    <td>dynamic control2</td>

    <td>dynamic control3</td>

    My goal is to "calculate" the color of the first cell with a formula based on the value of the three dynamic control

    Ex : if ((Dynamic control1+Dynamic control2+Dynamic control3)/3)<10

    then Title Line.Style="backcolor:Red;" else Title Line.Style="backcolor:Green;"

     Thanks for your help.

    Thursday, November 13, 2008 8:39 AM

Answers

  • User660823006 posted

    This problem has a couple of different elements. If you just want to color the items when the page is first loaded that can be handled by hooking the DataBound event on the FormView. This event is fired after the page is DataBound which would give you access to the underlying data object which would let you check all the values and set the color. If you want to do this client side as the user enters numbers and tabs between the fields then you are going to have to fall back to javascript, basically grabbing the event each textbox fires when the user tabs out and looking at all the values. I can give you an example of the first case if you need but the second one is a little more complex. :-)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 13, 2008 12:57 PM

All replies

  • User660823006 posted

    This problem has a couple of different elements. If you just want to color the items when the page is first loaded that can be handled by hooking the DataBound event on the FormView. This event is fired after the page is DataBound which would give you access to the underlying data object which would let you check all the values and set the color. If you want to do this client side as the user enters numbers and tabs between the fields then you are going to have to fall back to javascript, basically grabbing the event each textbox fires when the user tabs out and looking at all the values. I can give you an example of the first case if you need but the second one is a little more complex. :-)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 13, 2008 12:57 PM
  • User-1594116085 posted

    Hi Scottt, thanks for your help.

    I need the first case, so your code sample will be very welcome :)

    For the second one i have already done my javascript functions and it works fine (was not so easy like you said)

    So today i can chagne my row header cell color according to the user actions BUT i cannot initialize them (and i cannot set my color when i am in the details mode)

     Thanks a lot.

    Friday, November 14, 2008 5:48 AM
  • User-1594116085 posted

    Scott, please send me your sample code [:)]

    Thursday, November 20, 2008 5:24 AM
  • User660823006 posted

    In my case I just created a custom page in the scaffold against the Northwind database. So in my example I created a Products directory under the DynamicData\CustomPages. I copied the existing Details.aspx page into this directory. I then added a Label to the page:

    <asp:Label ID="LabelTitle" runat="server">Your Text Goes Here</asp:Label>

    <asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="DetailsDataSource" OnItemDeleted="DetailsView1_ItemDeleted" CssClass="detailstable" FieldHeaderStyle-CssClass="bold" ondatabound="DetailsView1_DataBound" >

    I then added an event handler to ondatabound see above and then wrote the following code behind:

    protected void DetailsView1_DataBound(object sender, EventArgs e) {
        Product p = (Product)DetailsView1.DataItem;
        if (p.ReorderLevel > 10) {
            LabelTitle.BackColor = System.Drawing.Color.Black;
        } else {
            LabelTitle.BackColor = System.Drawing.Color.Red;
        }

    Since I know this is for the product page I can get the product object that was data bound and use its fields to color the Label. If you want to the full sample email me and I'll send it.
     

     

    Thursday, November 20, 2008 5:56 AM
  • User-1594116085 posted

    Thanks a lot this is exacly the kind of code I search.


     

    Thursday, November 20, 2008 10:34 AM