datagrid

Discussion in 'ASP .Net' started by Trond, Apr 18, 2005.

  1. Trond

    Trond Guest

    I have a form with a datagrid that is databound. One of the column is like
    this:

    <asp:BoundColumn DataField="Timediff"
    SortExpression="Timediff"
    HeaderText="Time difference">
    <HeaderStyle Wrap="False"></HeaderStyle>
    </asp:BoundColumn>

    In that column i display a number from 0 to 3 mill

    Is there a way i can replace that with graphics?
    If number is < 60 then green
    if number is = 60 then yellow
    if number is > 60 then red

    best regards
    Trond
    Trond, Apr 18, 2005
    #1
    1. Advertising

  2. Best bet would be to set this up as a template column and put a control in
    there that you can colour. Then in the item_create event for the grid, you
    could check the value for this specific row/col and set the colour of the
    control accordingly

    Dave

    "Trond" wrote:

    > I have a form with a datagrid that is databound. One of the column is like
    > this:
    >
    > <asp:BoundColumn DataField="Timediff"
    > SortExpression="Timediff"
    > HeaderText="Time difference">
    > <HeaderStyle Wrap="False"></HeaderStyle>
    > </asp:BoundColumn>
    >
    > In that column i display a number from 0 to 3 mill
    >
    > Is there a way i can replace that with graphics?
    > If number is < 60 then green
    > if number is = 60 then yellow
    > if number is > 60 then red
    >
    > best regards
    > Trond
    >
    >
    >
    =?Utf-8?B?RGF2ZSBCcml0dG9u?=, Apr 18, 2005
    #2
    1. Advertising

  3. Hi Trond,

    You can process in DataGrid_ItemDataBound event:

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem)
    {
    TableCell cell = e.Item.Cells[TimediffIndex];
    double Timediff = double.Parse(cell.Text);
    if (Timediff == 60)
    {
    cell.BackColor = Color.Yellow;
    }
    else
    {
    if (Timediff < 60)
    {
    cell.BackColor = Color.Green;
    }
    else
    {
    cell.BackColor = Color.Red;
    }
    }
    }


    HTH

    Elton Wang




    "Trond" wrote:

    > I have a form with a datagrid that is databound. One of the column is like
    > this:
    >
    > <asp:BoundColumn DataField="Timediff"
    > SortExpression="Timediff"
    > HeaderText="Time difference">
    > <HeaderStyle Wrap="False"></HeaderStyle>
    > </asp:BoundColumn>
    >
    > In that column i display a number from 0 to 3 mill
    >
    > Is there a way i can replace that with graphics?
    > If number is < 60 then green
    > if number is = 60 then yellow
    > if number is > 60 then red
    >
    > best regards
    > Trond
    >
    >
    >
    =?Utf-8?B?RWx0b24gVw==?=, Apr 18, 2005
    #3
  4. Trond

    Trond Guest

    Thank you so much. What is TimediffIndex? The code reports an error with
    that saying: The name 'TimediffIndex' does not exist in the class or
    namespace

    best regards
    Trond


    "Elton W" <> wrote in message
    news:...
    > Hi Trond,
    >
    > You can process in DataGrid_ItemDataBound event:
    >
    > if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > ListItemType.AlternatingItem)
    > {
    > TableCell cell = e.Item.Cells[TimediffIndex];
    > double Timediff = double.Parse(cell.Text);
    > if (Timediff == 60)
    > {
    > cell.BackColor = Color.Yellow;
    > }
    > else
    > {
    > if (Timediff < 60)
    > {
    > cell.BackColor = Color.Green;
    > }
    > else
    > {
    > cell.BackColor = Color.Red;
    > }
    > }
    > }
    >
    >
    > HTH
    >
    > Elton Wang
    >
    >
    >
    >
    > "Trond" wrote:
    >
    >> I have a form with a datagrid that is databound. One of the column is
    >> like
    >> this:
    >>
    >> <asp:BoundColumn DataField="Timediff"
    >> SortExpression="Timediff"
    >> HeaderText="Time difference">
    >> <HeaderStyle Wrap="False"></HeaderStyle>
    >> </asp:BoundColumn>
    >>
    >> In that column i display a number from 0 to 3 mill
    >>
    >> Is there a way i can replace that with graphics?
    >> If number is < 60 then green
    >> if number is = 60 then yellow
    >> if number is > 60 then red
    >>
    >> best regards
    >> Trond
    >>
    >>
    >>
    Trond, Apr 19, 2005
    #4
  5. TimediffIndex means the index of your Timediff column, e.g. 0 for the first
    column.

    HTH

    Elton Wang

    "Trond" wrote:

    > Thank you so much. What is TimediffIndex? The code reports an error with
    > that saying: The name 'TimediffIndex' does not exist in the class or
    > namespace
    >
    > best regards
    > Trond
    >
    >
    > "Elton W" <> wrote in message
    > news:...
    > > Hi Trond,
    > >
    > > You can process in DataGrid_ItemDataBound event:
    > >
    > > if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > > ListItemType.AlternatingItem)
    > > {
    > > TableCell cell = e.Item.Cells[TimediffIndex];
    > > double Timediff = double.Parse(cell.Text);
    > > if (Timediff == 60)
    > > {
    > > cell.BackColor = Color.Yellow;
    > > }
    > > else
    > > {
    > > if (Timediff < 60)
    > > {
    > > cell.BackColor = Color.Green;
    > > }
    > > else
    > > {
    > > cell.BackColor = Color.Red;
    > > }
    > > }
    > > }
    > >
    > >
    > > HTH
    > >
    > > Elton Wang
    > >
    > >
    > >
    > >
    > > "Trond" wrote:
    > >
    > >> I have a form with a datagrid that is databound. One of the column is
    > >> like
    > >> this:
    > >>
    > >> <asp:BoundColumn DataField="Timediff"
    > >> SortExpression="Timediff"
    > >> HeaderText="Time difference">
    > >> <HeaderStyle Wrap="False"></HeaderStyle>
    > >> </asp:BoundColumn>
    > >>
    > >> In that column i display a number from 0 to 3 mill
    > >>
    > >> Is there a way i can replace that with graphics?
    > >> If number is < 60 then green
    > >> if number is = 60 then yellow
    > >> if number is > 60 then red
    > >>
    > >> best regards
    > >> Trond
    > >>
    > >>
    > >>

    >
    >
    >
    =?Utf-8?B?RWx0b24gVw==?=, Apr 19, 2005
    #5
  6. Trond

    Trond Guest

    Yes I see. Thank you. I changed it to the column number and presto,
    everything is working fine.
    As a newbie I really appreciate that you took time to write code
    Best regards
    Trond

    "Elton W" <> wrote in message
    news:...
    > TimediffIndex means the index of your Timediff column, e.g. 0 for the
    > first
    > column.
    >
    > HTH
    >
    > Elton Wang
    >
    > "Trond" wrote:
    >
    >> Thank you so much. What is TimediffIndex? The code reports an error with
    >> that saying: The name 'TimediffIndex' does not exist in the class or
    >> namespace
    >>
    >> best regards
    >> Trond
    >>
    >>
    >> "Elton W" <> wrote in message
    >> news:...
    >> > Hi Trond,
    >> >
    >> > You can process in DataGrid_ItemDataBound event:
    >> >
    >> > if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    >> > ListItemType.AlternatingItem)
    >> > {
    >> > TableCell cell = e.Item.Cells[TimediffIndex];
    >> > double Timediff = double.Parse(cell.Text);
    >> > if (Timediff == 60)
    >> > {
    >> > cell.BackColor = Color.Yellow;
    >> > }
    >> > else
    >> > {
    >> > if (Timediff < 60)
    >> > {
    >> > cell.BackColor = Color.Green;
    >> > }
    >> > else
    >> > {
    >> > cell.BackColor = Color.Red;
    >> > }
    >> > }
    >> > }
    >> >
    >> >
    >> > HTH
    >> >
    >> > Elton Wang
    >> >
    >> >
    >> >
    >> >
    >> > "Trond" wrote:
    >> >
    >> >> I have a form with a datagrid that is databound. One of the column is
    >> >> like
    >> >> this:
    >> >>
    >> >> <asp:BoundColumn DataField="Timediff"
    >> >> SortExpression="Timediff"
    >> >> HeaderText="Time difference">
    >> >> <HeaderStyle Wrap="False"></HeaderStyle>
    >> >> </asp:BoundColumn>
    >> >>
    >> >> In that column i display a number from 0 to 3 mill
    >> >>
    >> >> Is there a way i can replace that with graphics?
    >> >> If number is < 60 then green
    >> >> if number is = 60 then yellow
    >> >> if number is > 60 then red
    >> >>
    >> >> best regards
    >> >> Trond
    >> >>
    >> >>
    >> >>

    >>
    >>
    >>
    Trond, Apr 19, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave
    Replies:
    0
    Views:
    442
  2. BK Kim

    datagrid in datagrid

    BK Kim, Feb 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    538
    Alvin Bruney [MVP]
    Mar 2, 2004
  3. =?Utf-8?B?U3VyZXNo?=
    Replies:
    0
    Views:
    522
    =?Utf-8?B?U3VyZXNo?=
    Mar 2, 2004
  4. Brian K. Williams
    Replies:
    0
    Views:
    543
    Brian K. Williams
    Mar 2, 2004
  5. Andreas Klemt
    Replies:
    0
    Views:
    293
    Andreas Klemt
    Oct 8, 2003
Loading...

Share This Page