Block of detailsViews

Last post 02-19-2007 7:58 AM by camper. 7 replies.

Sort Posts:

  • Block of detailsViews

    02-15-2007, 4:18 AM
    • Loading...
    • camper
    • Joined on 04-28-2006, 8:48 AM
    • Posts 74

    Hi,

    I have on an aspx page about 16 detailsView controls. Some are 4 rows deep, some 3 and some 2. The problem I have is that the code is immense because i am setting properties of various rows ie. text size and backcolor depending on the text status of the row. To try and cut down on code I am trying to write a class or a function to detect whether the details view is 2,3,or 4 rows deep, this could be assigned manually however. The main part of the function would encompass the following i.e

    DetailsView1.Rows[3].Font.Size = 8;

        protected void XX_DataBind(object sender, EventArgs e)
        {
            if (DetailsView1.Rows[3].Cells[1].Text == "No Fault" && DetailsView4.Rows[0].Cells[1].Text == "aa")
            {
                DetailsView1.BorderColor = Color.LawnGreen;
            }
           
            }
            if (DetailsView1.Rows[3].Cells[1].Text != "No Fault" && DetailsView4.Rows[0].Cells[1].Text == "bb")
            {
                DetailsView1.BorderColor = Color.Yellow;
                DetailsView1.Rows[3].BackColor = Color.Yellow;
                DetailsView1.Rows[0].BackColor = Color.Yellow;
                DetailsView1.Rows[1].BackColor = Color.Yellow;
                DetailsView1.Rows[2].BackColor = Color.Yellow;
                DetailsView1.Rows[3].ForeColor = Color.Red;
            }

          There would be many more conditions in the lines above , and I am trying to replace the DetailsView1 with a generic DetailsView? in a function / class etc?

    Hope this is clear, any help would be great, thanks- Harry

              

    Filed under: , , ,
  • Re: Block of detailsViews

    02-15-2007, 9:45 AM

    You can cast the sender object to DetailsView and you are done.

    protected void XX_DataBind(object sender, EventArgs e)
    {   
       DetailsView dv = (DetailsView)sender;
    
       //your generic code referencing "dv"
    }
    
    Hope this helps
    "look ma' no hands!"

    kpeguero
  • Re: Block of detailsViews

    02-15-2007, 6:15 PM
    • Loading...
    • camper
    • Joined on 04-28-2006, 8:48 AM
    • Posts 74
    Could you expand I don't follow, thanks.
  • Re: Block of detailsViews

    02-15-2007, 6:44 PM

    No problem.

     

    What I say is that by casting the sender, and of course asociating all GridView to the same event handler, you get a generic function.  Because you won't need to specify a fixed gridview name, just cast and you'll have the one that generate the event.

     

    Hope it is clear, if not just let me know.

    "look ma' no hands!"

    kpeguero
  • Re: Block of detailsViews

    02-16-2007, 4:07 AM
    • Loading...
    • camper
    • Joined on 04-28-2006, 8:48 AM
    • Posts 74
    Could anybody write a small code example as I am still a bit confused, thanks!
  • Re: Block of detailsViews

    02-16-2007, 7:58 AM
    • Loading...
    • camper
    • Joined on 04-28-2006, 8:48 AM
    • Posts 74

    So would write:

    Protected void Test (object sender, EventArgs e)

    {    DetailsView dv = (DetailsView)sender;

    DetailsView dv.Rows[1].BackColor = color.Red;  (but this will not work because of errors?)

    }

    then on the databinding event properties select Test from the dropdown list? for each detailsView used.

    Can anybody help please? - thanks

  • Re: Block of detailsViews

    02-16-2007, 2:23 PM
    Answer

    Protected void Test (object sender, EventArgs e)

    {    DetailsView dv = (DetailsView)sender;

    dv.Rows[1].BackColor = color.Red; //Without "DetailsView " from the beg. of the line

    }

    "look ma' no hands!"

    kpeguero
  • Re: Block of detailsViews

    02-19-2007, 7:58 AM
    • Loading...
    • camper
    • Joined on 04-28-2006, 8:48 AM
    • Posts 74

    Many thanks,Big Smile

Page 1 of 1 (8 items)
Microsoft Communities
Page view counter