Using GridView Inside UpdatePanel

I have an Updatepanel and a Gridview inside it.

<asp:UpdatePanel ID="uplPanel" UpdateMode="Conditional" runat="server" OnLoad="uplPanel_Load"> <ContentTemplate> <asp:GridView ID="gvPrList" runat="server" AutoGenerateColumns="false" AllowPaging="false" AllowSorting="false" CssClass="list-table" HeaderStyle-CssClass="header"> <Columns> <ItemTemplate> <asp:Button ID="btnEdit" runat="server" Text="Edit" CssClass="button save" OnCommand="onPrItemCmd" CommandName="editRow" CommandArgument='<%#Bind("ID") %>' Style="width: 80px" /> <asp:Button ID="btnDelete" runat="server" Text="Delete" CssClass="button save" OnCommand="onPrItemCmd" CommandName="deleteRow" CommandArgument='<%#Bind("ID") %>' Style="width: 80px" /> </ItemTemplate> </asp:TemplateField> </Columns> 

When I click on my buttons inside Griview, it does not fire events. Any idea?

+8
c # asp.net-ajax updatepanel
source share
8 answers

I did the following and it works

I replace the asp button with the html button and call the javascript method to fire the Panal Load update event.

 <input id="btnDelete1" type="button" onclick="javascript:DeletePrItem('<%# Eval("ID") %>');" value="Delete" class="button save" style="width: 80px" /> 

My js:

  function DeletePrItem(_Id) { __doPostBack('<%= uplPanel.ClientID %>', _Id); } 

My code is:

  protected void uplPanel_Load(object sender, EventArgs e) { var arg = Request.Params.Get("__EVENTARGUMENT"); if (arg != null) { if (arg != "") { string recordId = arg.ToString(); //Do deletetion and rebind data grid } } } 
+2
source share

You need to add the OnCommand GridView event, and then handle this inside this event as follows:

 OnRowCommand="gvPrList_OnRowCommand" 

or, alternatively, add a click event for a single button, and then process the code behind the file:

 <asp:Button ID="btnEdit" runat="server" OnClick="btnEdit_Click" Text="Edit" CssClass="button save" OnCommand="onPrItemCmd" CommandName="editRow" CommandArgument='<%#Bind("ID") %>' Style="width: 80px" /> 
+5
source share

I had the same problem when the column buttons with OnClick caused the postback, but the OnClick method did not get there. When I commented out the update panel and it all worked.

I solved this problem by adding a feedback trigger for the grid in the update panel:

 </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="uxWebDataGrid" /> </Triggers> </asp:UpdatePanel> 

Hope this helps someone else!

+2
source share

I had a similar problem.

Depending on your situation, like mine ... All the controls that you can click inside the update panel, I want to be triggers; So I was just able to use the UpdatePanel property "ChildrenAsTriggers =" true ", so solve the problem.

  <asp:UpdatePanel runat="server" ID="UPCommunicationlogForm" ChildrenAsTriggers="true" > 

This solved my problem, now my edit and delete buttons, which are generated from the ItemTemplate inside my gridview, call their respective methods on the server.

+1
source share

This will be the event handler for your command in code:

 protected void onPrItemCmd(object sender, CommandEventArgs e) { //do whatever you want //probably you will need the "ID" or "CommandArgument": string myArgumentID = e.CommandArgument.ToString(); uplPanel.Update(); //since the UpdatePanel is set *UpdateMode="Conditional"* } 

UPDATE:

You can probably do some validation by clicking on the buttons. If so, you need to add CausesValidation = "false" to your buttons or link properties

0
source share

Add this code to UpdatePanel.

 </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="gvPrList" EventName="Click" /> </Triggers> </asp:UpdatePanel> 
0
source share

I added the OnRowCommand event and add this trigger to the UpdatePanel:

 <Triggers> <asp:AsyncPostBackTrigger ControlID="gvPrList" EventName="RowCommand" /> </Triggers> 

Please note that this is an Async trigger.

0
source share

It helps me. In my case, I changed the value in the asp: DropDownList control and then returned to the server to update my asp: GridView, which is in another asp: UpdatePanel. I just forgot to add the code to update the update panel with the list. As soon as I did this, everything worked fine.

Server side

 System.Data.DataSet ds = MySQL.DAL.GetRecord(sql); GV_View.DataSource = ds; GV_View.DataBind(); UP_MainList.Update(); //refresh the update panel 

Aspx code

  <asp:UpdatePanel runat="server" ID="UP_ListChange" UpdateMode="Conditional"> <ContentTemplate> <asp:DropDownList runat="server" ID="ddFilter" DataTextField="Desc" AutoPostBack="true" DataValueField="Detail" OnSelectedIndexChanged="GV_CodeView_RefreshScreen" ></asp:DropDownList> </ContentTemplate> </asp:UpdatePanel> <div class="medium">Select Filter to view database codes</div> </div> <div class="div-row-header" runat="server" id="divList"> <asp:UpdatePanel runat="server" ID="UP_MainList" UpdateMode="Conditional"> <ContentTemplate> <asp:GridView ID="GV_View" runat="server" AllowSorting="True" AutoGenerateColumns="false" DataKeyNames="id"> <Columns> <asp:BoundField DataField="Id" HeaderText="Id" Visible="false" /> <asp:BoundField DataField="Type_Cd" HeaderText="Code" /> <asp:BoundField DataField="Short_Desc" HeaderText=" Description" /> <asp:TemplateField HeaderText=""> <ItemTemplate> <asp:Button ID="Code_Edit" runat="server" Text="Edit" onClick="GV_Code_Edit_Click" class="button" /> </ItemTemplate> </asp:TemplateField> </Columns> </ContentTemplate> </asp:UpdatePanel> </div> 
0
source share

All Articles