Skip to content Skip to sidebar Skip to footer

How To Update Controls[datagrid,textboxes And Label] Based On A Row Selection Made In Datagrid That Resideds In A Updatepanel?

I have got a grid[Grid1] that build its dataRows when a button[search] is clicked, I managed to Ajaxify it by placing it in an UpdatePanel and it worked fine. Before Ajaxifying Gri

Solution 1:

In the properties for the UpdatePanel, set the update mode to "Conditional" and ChildrenAsTriggers to "true".

Another option would be to move the button inside the update panel so that you wouldn't have to have the trigger.

Solution 2:

A GridView is a complex asp.net server control. You will have a lot of difficulty updating Grid2 after Grid1 is updated inside of the UpdatePanel. However, it is possible to a execute JavaScript on the client after Grid1 is updated. You could update Grid1 inside of the update panel, execute JavaScript after Grid1 has been updated that will update HTML on the page. The problem is that updating Grid2 with Javascript is going to be a nightmare amount of work.

Here's an example of what I'm talking about: Ajax Enabled Gridview using JavaScript in ASP.NET. It is a total hack, a huge amount of work, and your co-workers will hate you when they have to maintain it.

If you wanted to update a label or a dropdown list then that would be possible but updating a GridView using Javascript and having those updates persist across postbacks is a daunting challenge.

Solution 3:

Use multiple UpdatePanels on one page. It won't affect the layout.

You can then use triggers (for the panels) in order to affect which controls you want affected.

Here's a page that will help you understand.

http://www.asp.net/ajax/tutorials/understanding-asp-net-ajax-updatepanel-triggers

Solution 4:

Your problem is down to the way you are triggering the postback on row click, i.e.: this method

protectedvoid grdJobs_ItemDataBound(object sender, DataGridItemEventArgs e)
{
  e.Item.Attributes.Add("onclick", "javascript:__doPostBack('grdJobs$ctl" + ((Convert.ToInt32(e.Item.ItemIndex + 3).ToString("00"))) + "$ctl00','')");
}

Manually writing the __doPostBack script is generally always a bad idea. I believe what you need to use instead is ClientScriptManager.GetPostBackEventReference which will create a similar looking postback script for you, but will take into account all sorts of other things including AJAX-ification of the control.

Try something like this instead:

protectedvoidgrdJobs_ItemDataBound(object sender, DataGridItemEventArgs e)
{
  e.Item.Attributes.Add("onclick", ClientScriptManager.GetPostBackEventReference(e.Item, string.Empty);
}

Post a Comment for "How To Update Controls[datagrid,textboxes And Label] Based On A Row Selection Made In Datagrid That Resideds In A Updatepanel?"