我有代码在它执行if else循环以检查某些数据后会出现一个动态按钮。
但是,gridview无法进行任何分页。它只显示第一页,不能转到第二页,依此类推。 它只能进行寻呼IF i nvr调用下面的方法。
这是我的代码
public void filter_select(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
........
}
该方法将在rowdatabound gridview页面源上调用,如OnRowDataBound="filter_select"
源代码上的gridview代码是:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" CellPadding="2" CellSpacing="2"
HorizontalAlign="Center" OnRowCommand="stop_survey"
OnRowDataBound="filter_select" OnSelectedIndexChanging="selected" PageSize="5"
Width="133%" DataKeyNames="SurveyID" DataSourceID="SqlDataSource1" AutoGenerateColumns="False"
>
<Columns>
<asp:BoundField DataField="SurveyID" HeaderText="Survey ID" ReadOnly="True"
.........
我的onrowCommand代码
public void stop_survey(object sender, GridViewCommandEventArgs e)
{
SqlConnection con;
string sqlcom;
SqlCommand cmd;
//is it because of this code below? as if i comment from this code onwards, the paging works.
GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer;
Button btn = (Button)GridView1.Rows[row.RowIndex].FindControl("btnStop");
...............
答案 0 :(得分:0)
在gridview控件的PageIndexChanging事件中重新绑定gridview
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = DataAcceessLayer.GetEmployeeData();
GridView1.DataBind();
}