2017-10-07 68 views
1

射擊我還沒有發現我的問題的任何解決方案:的GridView PageIndexChanging事件是不是裏面的UpdatePanel

GridView的尋呼事件時,它是一個UpdatePanel內gvBanquet_PageIndexChanging不點火。

由於問題的代碼是在這裏:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
    <ContentTemplate> 

    <div class="col-lg-12 table-responsive"> 
    <asp:GridView ID="gvBanquet" runat="server" AutoGenerateColumns="false" 
     OnRowCommand="gvBanquet_RowCommand" AllowPaging="True" PageSize="5" 
     EmptyDataText="No record found!" OnPageIndexChanging="gvBanquet_PageIndexChanging" 
     ShowHeaderWhenEmpty="true"> 
     <Columns> 

     // here are templates 

     </Columns> 
     <PagerStyle CssClass="pagination-ys" /> 
    </asp:GridView> 

    </div> 
    <!-- /.col-lg-12 --> 

    </ContentTemplate> 
    <Triggers> 
     <asp:AsyncPostBackTrigger ControlID="gvBanquet" EventName="PageIndexChanging" /> 
    </Triggers> 
</asp:UpdatePanel> 

這裏是一個尋呼事件:

protected void gvBanquet_PageIndexChanging(object sender, GridViewPageEventArgs e) 
{ 
    gvBanquet.PageIndex = e.NewPageIndex; 

    // fill and bind gridview here 
} 

我添加了一個破發點,但其不點火。

enter image description here

我怎麼能火分頁按鈕?

enter image description here

+0

顯示你的'getdata'代碼 – Webruster

+0

@Webruster我編輯了我的問題。 – AsifAli72090

+0

'DLBqt.SelectBanquet'代碼? – Webruster

回答

0

一個可能的情況下,沒有看到你的getdata代碼是:

你應該閱讀這是用來加載gridview的數據集(你的情況的數據表),每次你的頁面索引被改變。通過這種方式,您可以確保在由gridview頁碼觸發的每個單獨回發中,結果都將被填充。

更新

嘗試添加觸發器

<Triggers> 
     <asp:AsyncPostBackTrigger ControlID="gvBanquet" EventName="PageIndexChanging" /> 
</Triggers> 
+0

它似乎不工作:( – AsifAli72090

+0

@ Asif.Ali請更新您的問題,更新後 – Webruster

+0

'asp:GridView'沒有'AutoPostBack'屬性 –

3

還有就是GridView的沒有約束力的方法,所以我提供兩個方法(這兩部作品)
方法1:與聲明綁定SqlDataSource

<form id="form1" runat="server"> 
    <%--ScriptManager required by UpdatePanel --%> 
    <asp:ScriptManager runat="server" ID="sm" /> 
<div> 
    <asp:UpdatePanel runat="server" UpdateMode="Conditional"> 
     <ContentTemplate> 
    <asp:GridView ID="gvProducts" runat="server" AutoGenerateColumns="False" AllowPaging="true" PageSize="5" DataKeyNames="ProductID" DataSourceID="sqlNWind"> 
     <Columns> 
      <asp:BoundField DataField="ProductID" HeaderText="ProductID" SortExpression="ProductID" /> 
      <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" /> 
      <asp:TemplateField HeaderText="CategoryName" SortExpression="CategoryName"> 
       <ItemTemplate> 
        <asp:Label ID="Label1" runat="server" Text='<%# Eval("CategoryName") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
     </Columns> 
    </asp:GridView> 
    <%--Triggers are redundant because GridView is inside the UpdatePanel --%> 
     </ContentTemplate> 
    </asp:UpdatePanel> 
    <asp:SqlDataSource ID="sqlNWind" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindCnn %>" 
     SelectCommand="SELECT Products.ProductID, Products.ProductName, Products.CategoryID, Categories.CategoryName FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID"> 
    </asp:SqlDataSource> 
</div> 
</form> 

不需要代碼。

方法2:從代碼綁定背後:

.aspx 
<form id="form1" runat="server"> 
    <asp:ScriptManager runat="server" ID="sm" /> 
<div> 
    <asp:UpdatePanel runat="server" UpdateMode="Conditional"> 
     <ContentTemplate> 
    <asp:GridView ID="gvProducts" runat="server" OnPageIndexChanging="gvProducts_PageIndexChanging" AutoGenerateColumns="False" AllowPaging="true" PageSize="5" DataKeyNames="ProductID"> 
     <Columns> 
      <asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False" ReadOnly="True" SortExpression="ProductID" /> 
      <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" /> 
      <asp:TemplateField HeaderText="CategoryName" SortExpression="CategoryName"> 
       <ItemTemplate> 
        <asp:Label ID="Label1" runat="server" Text='<%# Eval("CategoryName") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
     </Columns> 
    </asp:GridView> 

     </ContentTemplate> 
    </asp:UpdatePanel> 
</div> 
</form> 

.aspx.vb 

Private Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load 
    If Not Page.IsPostBack Then 
     BindProds()''//Bind initial 
    End If 
End Sub 
Protected Sub gvProducts_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) 
    gvProducts.PageIndex = e.NewPageIndex 
    BindProds()''//Bind when pageIndex changing 
End Sub 

Private Sub BindProds() 
    Using cnn As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("NorthwindCnn").ConnectionString) 
     Using cmd As New Data.SqlClient.SqlCommand("SELECT Products.ProductID, Products.ProductName, Products.CategoryID, Categories.CategoryName FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID", cnn) 
      Dim da As New Data.SqlClient.SqlDataAdapter(cmd) 
      Dim dt As New Data.DataTable() 
      da.Fill(dt) 
      da.Dispose() 
      gvProducts.DataSource = dt 
      gvProducts.DataBind() 
     End Using 
    End Using 
End Sub 

的代碼是VB.NET。我希望OP能把它翻譯成C#

相關問題