How to update controls [DataGrid, TextBoxes and Label] based on row selection in DataGrid, which is in updatePanel?

I have a [Grid1] grid that builds its dataRows, when the [search] button is pressed, I managed to Ajaxify by putting it in the UpdatePanel and it worked fine. Before Ajaxifying Grid 1, another grid [Grid2] and some other controls [Text and Labels] are used to populate or update when a row is clicked in Grid 1.

Grid2 and other controls used to populate / update in OnItemCommand Event Grid 1.Its code in OnItemCommand, which associates the associated data with Grid2 and other controls.

After I placed Grid 1 in the update panel, they stopped updating. It will work fine if I put Grid2 and other controls in the same update panel, but the page was designed in such a way that I cannot have these controls in the same UpdatePanel as the first Grid, and I do not intend to Use a different update panel.

Hope I make sense. I am new to .Net, so please excuse me. Please find the code below.

 <asp:ScriptManager EnablePartialRendering="true" ID="ScriptManager1" runat="server"></asp:ScriptManager>
     <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers ="True">
      <ContentTemplate>
       <asp:DataGrid ID="grdJobs" runat="server" AllowPaging="true" 
        AlternatingItemStyle-CssClass="gridAltItemStyle"
        AutoGenerateColumns="False" CellPadding="0" 
        DataKeyField="code"
        CssClass="datagridBox" 
        GridLines="horizontal" 
        PagerStyle-Mode="NumericPages"
        HeaderStyle-CssClass="gridHeaderStyle" 
        ItemStyle-CssClass="gridItemStyle"
        PagerStyle-CssClass="gridPagerStyle" 
        Width="445px" OnPageIndexChanged="grdJobs_PageIndexChanged" OnItemCreated="grdJobs_ItemCreated" OnItemCommand="grdJobs_ItemCommand"             OnItemDataBound="grdJobs_ItemDataBound">
         <Columns>
          <asp:BoundColumn  DataField="J_ID" HeaderText="Job"></asp:BoundColumn>
          <asp:BoundColumn  DataField="Contract" HeaderText="Contract" ReadOnly="True"></asp:BoundColumn>
          <asp:BoundColumn  DataField="J_Fault_Line1" HeaderText="Fault" ReadOnly="True"></asp:BoundColumn>
          <asp:BoundColumn  DataField="j_p_id" HeaderText="Fault" Visible="false" ></asp:BoundColumn>
          <asp:ButtonColumn Text="<img src=images/addFeedback.gif style=border: 0px; alt=Add Feedback>" ButtonType="LinkButton"  HeaderText="Add"                   CommandName="Load" ItemStyle-cssClass="Col_9_Item_2"></asp:ButtonColumn>
         </Columns>
        </asp:DataGrid>
       <asp:ImageButton ID="cmdLkp"  ImageUrl="Images/search.gif" runat="server" OnClick="cmdLkp_Click" />

       </ContentTemplate>
      </asp:UpdatePanel>

The code below in the code that stopped working

protected void grdJobs_ItemCommand(object source, DataGridCommandEventArgs e)
    {

        if (e.CommandName == "Load")
        {
            functionToBindDataToGrid2();
            functionToBindDataToOtherControls();
        }
}

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

GridView - asp.net. Grid2 Grid1 UpdatePanel. Grid1 JavaScript . Grid1 , JavaScript Grid1, HTML . , Grid2 Javascript .

, : Ajax Enabled Gridview JavaScript ASP.NET. , , , .

, , GridView Javascript - .

+2

UpdatePanel "" "" "true".

- , .

+4

Your problem boils down to how you trigger the postback when you click on a row, i.e.: this method

protected void 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 a __doPostBackscript is usually always a bad idea. I suppose you need to use ClientScriptManager.GetPostBackEventReference instead , which will create a similar postback script for you, but will take into account all kinds of other things, including the AJAX identity of the control.

Try something like this:

protected void grdJobs_ItemDataBound(object sender, DataGridItemEventArgs e)
{
  e.Item.Attributes.Add("onclick", ClientScriptManager.GetPostBackEventReference(e.Item, string.Empty);
}
+1
source

All Articles