Why doesnt the AsyncCallback update my gridview?
Posted
by Naruji
on Stack Overflow
See other posts from Stack Overflow
or by Naruji
Published on 2010-04-06T12:33:31Z
Indexed on
2010/04/06
14:23 UTC
Read the original article
Hit count: 453
Hi all,
I started working with delegates last week and i am trying to update my gridview async on the background. All goes well, no errors or such but i dont get a result after my EndInvoke. does anyone know what i am doing wrong?
Here is a code snippet:
public delegate string WebServiceDelegate(DataKey key);
protected void btnCheckAll_Click(object sender, EventArgs e)
{
foreach (DataKey key in gvTest.DataKeys)
{
WebServiceDelegate wsDelegate = new WebServiceDelegate(GetWebserviceStatus);
wsDelegate.BeginInvoke(key, new AsyncCallback(UpdateWebserviceStatus), wsDelegate);
}
}
public string GetWebserviceStatus(DataKey key)
{
return String.Format("Updated {0}", key.Value);
}
public void UpdateWebserviceStatus(IAsyncResult result)
{
WebServiceDelegate wsDelegate = (WebServiceDelegate)result.AsyncState;
Label lblUpdate = (Label)gvTest.Rows[Convert.ToInt32(key.Value)].FindControl("lblUpdate");
lblUpdate.Text = wsDelegate.EndInvoke(result);
}
© Stack Overflow or respective owner