我对 ASP C# 真的很陌生,我想弄清楚如何在 AsyncPostBackTrigger 中控制 gridview 分页。这是我的代码:
<div id="grid_layer">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:GridView ID="GridView1" CssClass="result_grid" runat="server" CellPadding="3" ForeColor="Black"
GridLines="Vertical" BackColor="White" BorderColor="#999999"
BorderStyle="Solid" BorderWidth="1px" AllowPaging="True" PageSize="15"
>
<AlternatingRowStyle BackColor="#CCCCCC" />
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSearch" />
<asp:AsyncPostBackTrigger ControlID="GridView1" EventName="PageIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="Gridview1" EventName="PageIndexChanging" />
</Triggers>
</asp:UpdatePanel>
<br />
<br />
</div>
我的 aspx.cs 代码:
private void BindGridviewDataWebloan()
{
string ConnectionStringB = ConfigurationManager.ConnectionStrings["conWebloan"].ConnectionString;
using (SqlConnection connectionB = new SqlConnection(ConnectionStringB))
{
connectionB.Open();
SqlCommand cmdWebloan = new SqlCommand("Select a.ldatetime as Date, b.action_name as Action, a.description as Description, a.username as Username from webloan.dbo.logbook a join webloan.dbo.action_def b on a.action_no=b.action_no where DATEDIFF(day,ldatetime,@date_exec) = 0", connectionB);
cmdWebloan.Parameters.AddWithValue("@date_exec", txtDate.Text);
SqlDataAdapter da = new SqlDataAdapter(cmdWebloan);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
connectionB.Close();
}
}
我没有使用 SQLdatasource 我正在使用数据集...谢谢..