ItemCreate event handler changes wrong DataGridItem

Discussion in 'ASP .Net Datagrid Control' started by Chris Smith, Oct 30, 2003.

  1. Chris Smith

    Chris Smith Guest

    I am changing the EditText in a EditCommandColumn in a DataGrid in an
    ItemCreate event handler . The only problem I am having is that instead of
    changing the text in the current row it changes the next row.

    I watch the value in the debugger, and I see it change at what appears to be
    the right time.

    The EnableViewState is set to True.

    Any suggestions or thoughts appreciated!



    I read a value out of the current DataGridItem DataItem (a person's name),
    and use it to replace the EditCommandColumn's EditText field.:

    private void hhItemCreated(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem)
    {
    string HouseholdName;

    DataGrid dg;
    dg = (DataGrid)sender;

    EditCommandColumn ecc;
    ecc = (EditCommandColumn)dg.Columns[0];

    Troop.FunWithXML.TroopDB.HouseholdRow r =
    (Troop.FunWithXML.TroopDB.HouseholdRow)e.Item.DataItem;
    if(r == null) return;

    HouseholdName =
    ((Troop.FunWithXML.TroopDB.HouseholdRow)e.Item.DataItem)["HHName"].ToString(
    );
    ecc.EditText = HouseholdName;
    }
    }
    Chris Smith, Oct 30, 2003
    #1
    1. Advertising

  2. Hi

    > changing the text in the current row it changes the next row.


    I think your example doesn't work because at the ItemCreated event the page
    has already created the LinkButton of the column using the "EditText"
    property of the EditCommandColumn.

    Therefore you must modify directly the "Text" property of the LinkButton.

    here an example:

    private void hhItemCreated(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem)
    {
    string HouseholdName;

    Troop.FunWithXML.TroopDB.HouseholdRow r =
    (Troop.FunWithXML.TroopDB.HouseholdRow)e.Item.DataItem;
    if(r == null) return;

    HouseholdName =
    ((Troop.FunWithXML.TroopDB.HouseholdRow)e.Item.DataItem)["HHName"].ToString(
    );
    ((LinkButton)e.Item.Cells[0].Controls[0]).Text = HouseholdName;

    }


    Hi
    Giorgio
    Giorgio Parmeggiani, Nov 1, 2003
    #2
    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. Gabriël
    Replies:
    1
    Views:
    289
    Gabriël
    May 27, 2004
  2. =?Utf-8?B?U291cmkgQ2hhbGxh?=

    Accessing DataGridItem in ItemCreated Event.

    =?Utf-8?B?U291cmkgQ2hhbGxh?=, Aug 28, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    4,762
    Souri Challa
    Aug 28, 2004
  3. Replies:
    1
    Views:
    694
    Damien
    Feb 22, 2007
  4. Samuel Chowdhuri
    Replies:
    1
    Views:
    311
    Alvin Bruney
    Oct 20, 2003
  5. Sam Kong
    Replies:
    1
    Views:
    105
    Martin Honnen
    Oct 23, 2006
Loading...

Share This Page