Question : asyncronous update gridview when ListBox_SelectionIndexChanged

Hello experts, I have a problem I didn't find yet a solution:
I have a List Box with several values. When user selects an item, I need to update a data bound  grid view, but without post back, because page refresh redirect the user to the top of the page, that is not very friendly.
The Update Panel solution doesn't work (please check the code attached). Neither asynchronous trigger (not included in attached code) doesn't work
Any solution (including JavaScript) would be greatly appreciated.
Thanks!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>
………………………………………..
<asp:UpdatePanel ID="UpdatePanelTotalTrafic" runat="server" ChildrenAsTriggers="True" UpdateMode="Always">    
  <ContentTemplate>                                 
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"                                    onselectedindexchanged="ListBoxServiceType_SelectedIndexChanged">
<asp:ListItem Selected="True">Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
</asp:ListBox>
      <asp:GridView ID="GridViewTotalTrafic" runat="server">
            <RowStyle CssClass="RowStyle" />
            <HeaderStyle CssClass="HeaderStyle" />
            <AlternatingRowStyle CssClass="AlternateRowStyle" />
      </asp:GridView>
      <asp:SqlDataSource ID="SqlDataSourceTotalTrafic" runat="server" 
    ConnectionString="<%$ConnectionStrings: ConnectionStringSQL %>"                                     SelectCommand="some_storedprocedure" SelectCommandType="StoredProcedure">
          <SelectParameters>
<asp:SessionParameter Name="CustomerIdList" SessionField="SelectedCustomersList" Type="string" />
<asp:ControlParameter ControlID="ListBoxServiceType" DefaultValue="Voce Out" Name="ServiceType" PropertyName="SelectedValue" Type="String" />
          </SelectParameters>
      </asp:SqlDataSource>                            </ContentTemplate>
</asp:UpdatePanel>  

protected void ListBoxServiceType_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewTotalTrafic.DataSource = SqlDataSourceTotalTrafic;
        GridViewTotalTrafic.DataBind();
    }

Answer : asyncronous update gridview when ListBox_SelectionIndexChanged

Hi,

Since the page directive is not included in the code you have posted i cant see whether you have tried this but there is a property called "MaintainScrollPositionOnPostback" that you can set to true in the page directive which will force the page to maitain the scroll position on postback.

/Carl.
Random Solutions  
 
programming4us programming4us