Datagrid not refreshing with new data

Discussion in 'ASP .Net' started by pv_kannan@yahoo.com, Sep 30, 2005.

  1. Guest

    One of our dev team members is having a strange problem with a
    datagrid...

    We are not seeing a datagrid's data getting refreshed after a new row
    is entered in a popup window inspite of resetting the datasource and
    rebinding it.

    We have a datagrid (enabled viewstate) that binds to a collection class
    that inherits the IList interface. The datagrid displays list of
    associated contacts for a customer order.

    We have a linkbutton to add new contacts. Once this link is clicked, a
    popup window shows up and all contacts for the customer are displayed.
    The user has the option to add a new contact at this point. When they
    do so, a dataentry form shows up in the popup. The user then enters the
    details and chooses to Associate the new contact to the customer. The
    expected behavior is that the new contact should show up in the
    datagrid. But it does not.

    We are calling the method that resets the datasource and binds the data
    to the grid in the data entry screen. Stepping thru the ItemDataBound
    event also shows the presence of the new row in the datasource. But the
    datagrid is not refreshed.

    Is there a way to do this?

    I have posted relevant pieces of code...

    /************************OrderEdit.aspx) **********************/
    Page Load
    ---------------
    linkAddContact.Attributes.Add("onclick","javascript:OpenPopup('ContactSelect.aspx')");


    RefreshOrderContacts()
    ---------------------------
    public void RefreshOrderContacts()
    {
    OrderContactsData = SessionOrder.OrderContacts;
    if (dataGridOrderContact.Items.Count != OrderContactsData.Count)
    {
    dataGridOrderContact.DataSource = OrderContactsData ;
    dataGridOrderContact.DataBind();
    }
    }



    ContactSelect.aspx
    ====================
    <input type="button"
    onclick="javascript:location.href='ContactEdit.aspx?Mode=Add'" value="
    Add New Contact ">


    ContactEdit.aspx
    ==================

    btn_Associate Click event
    -------------------------

    SessionOrder.OrderContacts.Add(SessionOrder.OrderID,
    SessionContact.ContactID);

    labelMessage.Text = "Contact successfully associated!!!";
    labelMessage.Visible = true;

    OrderEdit orderEdit = (OrderEdit) Session["OrderEdit"];
    orderEdit.RefreshOrderContacts();
     
    , Sep 30, 2005
    #1
    1. Advertising

  2. Rob Schieber Guest

    wrote:
    > One of our dev team members is having a strange problem with a
    > datagrid...
    >
    > We are not seeing a datagrid's data getting refreshed after a new row
    > is entered in a popup window inspite of resetting the datasource and
    > rebinding it.
    >
    > We have a datagrid (enabled viewstate) that binds to a collection class
    > that inherits the IList interface. The datagrid displays list of
    > associated contacts for a customer order.
    >
    > We have a linkbutton to add new contacts. Once this link is clicked, a
    > popup window shows up and all contacts for the customer are displayed.
    > The user has the option to add a new contact at this point. When they
    > do so, a dataentry form shows up in the popup. The user then enters the
    > details and chooses to Associate the new contact to the customer. The
    > expected behavior is that the new contact should show up in the
    > datagrid. But it does not.
    >
    > We are calling the method that resets the datasource and binds the data
    > to the grid in the data entry screen. Stepping thru the ItemDataBound
    > event also shows the presence of the new row in the datasource. But the
    > datagrid is not refreshed.
    >
    > Is there a way to do this?
    >
    > I have posted relevant pieces of code...
    >
    > /************************OrderEdit.aspx) **********************/
    > Page Load
    > ---------------
    > linkAddContact.Attributes.Add("onclick","javascript:OpenPopup('ContactSelect.aspx')");
    >
    >
    > RefreshOrderContacts()
    > ---------------------------
    > public void RefreshOrderContacts()
    > {
    > OrderContactsData = SessionOrder.OrderContacts;
    > if (dataGridOrderContact.Items.Count != OrderContactsData.Count)
    > {
    > dataGridOrderContact.DataSource = OrderContactsData ;
    > dataGridOrderContact.DataBind();
    > }
    > }
    >
    >
    >
    > ContactSelect.aspx
    > ====================
    > <input type="button"
    > onclick="javascript:location.href='ContactEdit.aspx?Mode=Add'" value="
    > Add New Contact ">
    >
    >
    > ContactEdit.aspx
    > ==================
    >
    > btn_Associate Click event
    > -------------------------
    >
    > SessionOrder.OrderContacts.Add(SessionOrder.OrderID,
    > SessionContact.ContactID);
    >
    > labelMessage.Text = "Contact successfully associated!!!";
    > labelMessage.Visible = true;
    >
    > OrderEdit orderEdit = (OrderEdit) Session["OrderEdit"];
    > orderEdit.RefreshOrderContacts();
    >


    Make sure to only bind if its not a postback, otherwise you'll lose your
    data because it wont be in viewstate.

    Example...

    If(!Page.IsPostBack)
    RefreshOrderContacts()
    else
    SaveContacts()
    RefreshOrderContacts()

    --
    Rob Schieber
     
    Rob Schieber, Sep 30, 2005
    #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. Replies:
    0
    Views:
    357
  2. Replies:
    1
    Views:
    437
    Bruce Barker
    Jul 28, 2005
  3. Harlan Messinger

    Self-refreshing and non-self-refreshing controls

    Harlan Messinger, Aug 4, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    486
    =?Utf-8?B?Y2xpY2tvbg==?=
    Aug 4, 2006
  4. Kreebog

    Datagrid is not refreshing after postback

    Kreebog, Feb 25, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    136
    Kostia
    Feb 26, 2004
  5. Harlan Messinger

    Self-refreshing and non-self-refreshing controls

    Harlan Messinger, Aug 3, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    215
    Harlan Messinger
    Aug 3, 2006
Loading...

Share This Page