This is a migrated thread and some comments may be shown as answers.

Update asp:Label after Grid edit

3 Answers 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Najid Hanif
Top achievements
Rank 2
Najid Hanif asked on 22 Sep 2011, 09:58 PM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Dan Lehmann
Top achievements
Rank 1
answered on 22 Sep 2011, 10:49 PM
Can you post the parts of the asp and codebehind that are relevent to this problem?
Dan
0
Najid Hanif
Top achievements
Rank 2
answered on 22 Sep 2011, 11:02 PM

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();
    }
}
0
Najid Hanif
Top achievements
Rank 2
answered on 22 Sep 2011, 11:07 PM
Of course after going through that I now see its because my Label is not in the RadAjaxLoadingPanel / RadAjaxPanel

Problem solved
Tags
Grid
Asked by
Najid Hanif
Top achievements
Rank 2
Answers by
Dan Lehmann
Top achievements
Rank 1
Najid Hanif
Top achievements
Rank 2
Share this question
or