I have a Gridview in an Updatepanel with paging enabled. When I click on the page link to go to page 2 or 3 the entire site still refreshes. Also, I have SelectedIndexChanged event enable to kick of the populating of a listbox. That does not seem to be
updating in the Updatepanle either. I read about triggers but not sure how to use them on the listbox. Any ideas?
Thank you for your response. I tried to follow your example but am still unable to get this to work. I removed the Updatepanel from the Gridview and added on to my listbox. The listbox is set to update based on the SelectedIndexChange Event from the Gridview.
Can you see what is wrong here?
Perhaps i wasnt very clear on what i meant, sorry.
Place both of them in the updatePanel , the gridview and the listbox.
The use of the Async trigger is correct , just on a side note , each control has a default event so some times you dont need to say which is the event.
jsolo
Member
1 Points
22 Posts
Gridview SelectedIndexChanged event not working in Updatepanel
Oct 23, 2009 03:00 PM|LINK
Hello,
I have a Gridview in an Updatepanel with paging enabled. When I click on the page link to go to page 2 or 3 the entire site still refreshes. Also, I have SelectedIndexChanged event enable to kick of the populating of a listbox. That does not seem to be updating in the Updatepanle either. I read about triggers but not sure how to use them on the listbox. Any ideas?
Many thanks,
James
GRIDEVIEW
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:GridView ID="GridViewProgram" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataSourceID="dsProgram"
onselectedindexchanged="GridViewProgram_SelectedIndexChanged"
Width="1000px" PageSize="8">
<Columns>
<asp:CommandField ButtonType="Button" ShowSelectButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
<asp:BoundField DataField="EVENT DATE" HeaderText="EVENT DATE" ReadOnly="True"
SortExpression="EVENT DATE" />
<asp:BoundField DataField="PROGRAM NAME" HeaderText="PROGRAM NAME"
SortExpression="PROGRAM NAME" />
<asp:BoundField DataField="TYPE" HeaderText="TYPE" SortExpression="TYPE" />
<asp:BoundField DataField="SUB TYPE" HeaderText="SUB TYPE"
SortExpression="SUB TYPE" />
<asp:BoundField DataField="STATUS" HeaderText="STATUS"
SortExpression="STATUS" />
<asp:BoundField DataField="PROGRAM CITY" HeaderText="PROGRAM CITY"
SortExpression="PROGRAM CITY" />
<asp:BoundField DataField="PROGRAM STATE" HeaderText="PROGRAM STATE"
SortExpression="PROGRAM STATE" />
<asp:BoundField DataField="PROGRAM COUNTRY" HeaderText="PROGRAM COUNTRY"
SortExpression="PROGRAM COUNTRY" />
<asp:BoundField DataField="OFFICE" HeaderText="OFFICE"
SortExpression="OFFICE" />
</Columns>
<SelectedRowStyle BackColor="#C86A02" Font-Bold="True" ForeColor="White" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
LISTBOX
<asp:ListBox ID="lbOffice" runat="server" AutoPostBack="True"
DataSourceID="dsOffice" DataTextField="OFFICE" DataValueField="OFFICE"
Height="115px" onselectedindexchanged="lbOffice_SelectedIndexChanged"
SelectionMode="Multiple" Width="100%" Font-Names="Arial" Font-Size="8pt"></asp:ListBox>
Rick_brandao
Member
54 Points
12 Posts
Re: Gridview SelectedIndexChanged event not working in Updatepanel
Oct 23, 2009 03:44 PM|LINK
When you use a updatePanel you Can't update anything outside it if the postback comes from inside.
Since your indexChanged is inside the updatePanel the async Postback code wont update the listbox.
You can place the listbox inside the updatePanel or then you can try using the triggers.
With triggers you can specify which controls will cause a postBack and which will do a AsyncPostBack.
You place it inside the <asp:UpdatePanel> as in the following:
<asp:UpdatePanel> <Triggers> <asp:AsyncPostBackTrigger ControlID="myAsyncControl" /> <asp:PostBackTrigger ControlID="myPostbackControl" /> </Triggers> <ContentTemplate> my content </ContentTemplate> </asp:UpdatePanel>and on the PostBackTrigger controlID you place which control you want to cause a postback.
As i said before the easiest solution is placing the listbox inside the updatePanel.
jsolo
Member
1 Points
22 Posts
Re: Gridview SelectedIndexChanged event not working in Updatepanel
Oct 23, 2009 05:51 PM|LINK
Hello Rick,
Thank you for your response. I tried to follow your example but am still unable to get this to work. I removed the Updatepanel from the Gridview and added on to my listbox. The listbox is set to update based on the SelectedIndexChange Event from the Gridview. Can you see what is wrong here?
Many thanks,
J
<asp:UpdatePanel ID="UpdatePanel_lbOffice" Updatemode="Conditional" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="GridViewProgram" EventName="SelectedIndexChanged" /> <asp:PostBackTrigger ControlID="lbOffice" /> </Triggers> <ContentTemplate> <asp:ListBox ID="lbOffice" runat="server" DataSourceID="dsOffice" DataTextField="OFFICE" DataValueField="OFFICE" Height="115px" onselectedindexchanged="lbOffice_SelectedIndexChanged" SelectionMode="Multiple" Width="100%" Font-Names="Arial" Font-Size="8pt"></asp:ListBox> </ContentTemplate> </asp:UpdatePanel>Rick_brandao
Member
54 Points
12 Posts
Re: Gridview SelectedIndexChanged event not working in Updatepanel
Oct 23, 2009 06:04 PM|LINK
Perhaps i wasnt very clear on what i meant, sorry.
Place both of them in the updatePanel , the gridview and the listbox.
The use of the Async trigger is correct , just on a side note , each control has a default event so some times you dont need to say which is the event.
http://msdn.microsoft.com/en-us/library/system.web.ui.asyncpostbacktrigger.eventname.aspx
The use of the postback trigger is also correct if you need to update something outside the updatePanel.
EDIT: something like this :
<asp:UpdatePanel ID="UpdatePanel_lbOffice" UpdateMode="Conditional" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="GridViewProgram" EventName="SelectedIndexChanged" /> <asp:PostBackTrigger ControlID="lbOffice" /> </Triggers> <ContentTemplate> <asp:GridView ID="gvTest" runat="server"> </asp:GridView> <br /> <asp:ListBox ID="lbOffice" runat="server" DataSourceID="dsOffice" DataTextField="OFFICE" DataValueField="OFFICE" Height="115px" OnSelectedIndexChanged="lbOffice_SelectedIndexChanged" SelectionMode="Multiple" Width="100%" Font-Names="Arial" Font-Size="8pt"></asp:ListBox> </ContentTemplate> </asp:UpdatePanel>jsolo
Member
1 Points
22 Posts
Re: Gridview SelectedIndexChanged event not working in Updatepanel
Oct 24, 2009 01:49 PM|LINK
Thanks Rick. In addition to your suggestions I also moved the Scriptmanger just below the start of the <form> tag. All is well!