ItemDataBound event

Discussion in 'ASP .Net Datagrid Control' started by Xu ChunMing, Feb 21, 2004.

  1. Xu ChunMing

    Xu ChunMing Guest

    Hi All,
    I see the following on MSDN:

    The DataGrid control supports several events. One of them, the ItemCreated
    event, gives you a way to customize the item-creation process. The
    ItemDataBound event also gives you the ability to customize the DataGrid
    items, but after the data is available for inspection. For example, if you
    were using the DataGrid control to display a to-do list, you could display
    overdue items in red text, completed items in black text, and other tasks in
    green text.

    I nearly want to do the same thing,
    but in the event ,I can't access the value I wanted with the commented
    line, but this statemetn works well on the Item Updat event.

    public void MyDataGrid_DataBound(Object sender, DataGridItemEventArgs e)
    {
    //string s1
    =((System.Web.UI.WebControls.TextBox)e.Item.Cells[7].FindControl("edit_Sate"
    )).Text;
    if(s1=="UT")
    e.Item.BackColor =Color.Green ;
    }

    I wonder how to access the one of the cell's bounded value of the just added
    row.

    Thanks!
    Xu ChunMing, Feb 21, 2004
    #1
    1. Advertising

  2. Hi ChunMing,
    Have you tried doing this in DAtaGrid_ItemCreate
    under this
    try in
    if e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType =
    ListItemType.Item
    =((System.Web.UI.WebControls.TextBox)e.Item.Cells[7].FindControl("edit_Sate"
    )).Text;
    if(s1=="UT")
    e.Item.BackColor =Color.Green ;
    your code to change the color.


    this option is for listing only not in edit mode.

    Check it out.
    Same syntax under this option.

    "Xu ChunMing" <> wrote in message
    news:ezCnBCE%...
    > Hi All,
    > I see the following on MSDN:
    >
    > The DataGrid control supports several events. One of them, the ItemCreated
    > event, gives you a way to customize the item-creation process. The
    > ItemDataBound event also gives you the ability to customize the DataGrid
    > items, but after the data is available for inspection. For example, if you
    > were using the DataGrid control to display a to-do list, you could display
    > overdue items in red text, completed items in black text, and other tasks

    in
    > green text.
    >
    > I nearly want to do the same thing,
    > but in the event ,I can't access the value I wanted with the commented
    > line, but this statemetn works well on the Item Updat event.
    >
    > public void MyDataGrid_DataBound(Object sender, DataGridItemEventArgs e)
    > {
    > //string s1
    >

    =((System.Web.UI.WebControls.TextBox)e.Item.Cells[7].FindControl("edit_Sate"
    > )).Text;
    > if(s1=="UT")
    > e.Item.BackColor =Color.Green ;
    > }
    >
    > I wonder how to access the one of the cell's bounded value of the just

    added
    > row.
    >
    > Thanks!
    >
    >
    >
    >
    >
    Arvind P Rangan, Feb 25, 2004
    #2
    1. Advertising

  3. checkout the message which subject's is "changing row color depending on a
    cell value"
    at this group sended 20/02/2004

    I think it helps you...



    "Xu ChunMing" <> wrote in message
    news:ezCnBCE%...
    > Hi All,
    > I see the following on MSDN:
    >
    > The DataGrid control supports several events. One of them, the ItemCreated
    > event, gives you a way to customize the item-creation process. The
    > ItemDataBound event also gives you the ability to customize the DataGrid
    > items, but after the data is available for inspection. For example, if you
    > were using the DataGrid control to display a to-do list, you could display
    > overdue items in red text, completed items in black text, and other tasks

    in
    > green text.
    >
    > I nearly want to do the same thing,
    > but in the event ,I can't access the value I wanted with the commented
    > line, but this statemetn works well on the Item Updat event.
    >
    > public void MyDataGrid_DataBound(Object sender, DataGridItemEventArgs e)
    > {
    > //string s1
    >

    =((System.Web.UI.WebControls.TextBox)e.Item.Cells[7].FindControl("edit_Sate"
    > )).Text;
    > if(s1=="UT")
    > e.Item.BackColor =Color.Green ;
    > }
    >
    > I wonder how to access the one of the cell's bounded value of the just

    added
    > row.
    >
    > Thanks!
    >
    >
    >
    >
    >
    Volkan Karaboða, Feb 26, 2004
    #3
    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. Tina
    Replies:
    1
    Views:
    374
    Suresh
    Oct 14, 2003
  2. Josh Daws
    Replies:
    2
    Views:
    21,966
    Claes
    Sep 11, 2006
  3. Dave

    ItemDataBound event of DataGrid

    Dave, Oct 7, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,942
    Scott Allen
    Oct 7, 2004
  4. GaryDean
    Replies:
    1
    Views:
    8,691
    Walter Wang [MSFT]
    Aug 18, 2006
  5. NH
    Replies:
    2
    Views:
    528
    Andrew L. Van Slaars
    Dec 17, 2004
Loading...

Share This Page