Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using GridView inside UpdatePanel

I have an Updatepanel and 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 the Griview, it does not fire the events. Any idea?

like image 382
vml19 Avatar asked Feb 13 '12 08:02

vml19


2 Answers

You need to add OnCommand event of GridView and then handle that inside that event like this:

OnRowCommand="gvPrList_OnRowCommand" 

or alternatively add a click event for the individual button and then handle in the code behind 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" />
like image 187
Naveed Butt Avatar answered Oct 09 '22 05:10

Naveed Butt


I had the same issue where column buttons with a OnClick were causing a postback but the OnClick method was not being hit. When I commented out the update panel and it all worked.

I resolved this issue by adding a postback trigger for the grid within the update panel:

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

Hope this helps someone else!

like image 37
John Avatar answered Oct 09 '22 05:10

John