Update asp:Label after Grid edit

4 posts, 1 answers
  1. Najid Hanif
    Najid Hanif avatar
    92 posts
    Member since:
    Jul 2011

    Posted 22 Sep 2011 Link to this post

    I have a an asp:Label on the same page as my grid. I would like to update the text on the asp:Label after my grid has been updated. My Label gets updated fine OnItemDataBound but I also want to update the label after the grid has been edited. When I try OnItemUpdated its like the label is not found. How can I do this?

    Thanks
  2. Answer
    Dan Lehmann
    Dan Lehmann avatar
    103 posts
    Member since:
    May 2011

    Posted 22 Sep 2011 Link to this post

    Can you post the parts of the asp and codebehind that are relevent to this problem?
    Dan
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Najid Hanif
    Najid Hanif avatar
    92 posts
    Member since:
    Jul 2011

    Posted 22 Sep 2011 Link to this post


    The Label i am trying to update
    <asp:Label runat="server" ID="Label1" CssClass="selection-result" />

    The CS that updates the label
    protected void RefreshUnassignedText()
    {
        int count = 0;
        string mess = "";
        conn.Open();
        SqlCommand cmd = new SqlCommand("select count(*) as 'blah' from RM_Queue WHERE statusid = 1", conn);
        count = (int)cmd.ExecuteScalar();
            if (conn != null)
            {
                conn.Close();
            }
     
     
            switch (count)
            {
                case 0:
                    mess = "";
                    break;
                case 1:
                    mess = "There is " + count + " unassigned request";
                    break;
                default:
                    mess = "There are " + count + " unassigned requests";
                    break;
            }
            Label1.Text = mess;
            //return mess;
    }

    called OnDataBound="RadGrid1_DataBound" This works and updates the label when the page is loaded
    protected void RadGrid1_DataBound(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(gridMessage))
        {
            DisplayMessage(gridMessage);
        }
        RefreshUnassignedText();
    }

    Called OnItemUpdated="RadGrid1_ItemUpdated" This does not update the Label.
    protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)
    {
        if (e.Exception != null)
        {
            e.KeepInEditMode = true;
            e.ExceptionHandled = true;
            SetMessage("Update failed. Reason: " + e.Exception.Message);
        }
        else
        {
     
            SetMessage("Request has been updated! " + e.Item.KeyValues);
            RefreshUnassignedText();
        }
    }
  5. Najid Hanif
    Najid Hanif avatar
    92 posts
    Member since:
    Jul 2011

    Posted 22 Sep 2011 Link to this post

    Of course after going through that I now see its because my Label is not in the RadAjaxLoadingPanel / RadAjaxPanel

    Problem solved
Back to Top