【发布时间】:2016-05-16 12:42:53
【问题描述】:
目前我无法在单击它时查看我的 gridview 的第 2 页。我不知道为什么并且需要帮助。我按照指示做了 PageIndexChanging,设置了 AllowPaging="True" 但仍然无法解决这个问题。
HTML:
<asp:GridView ID="SiteGridView" runat="server" CssClass="datagrid" GridLines="Vertical"
AutoGenerateColumns="False" Width="100%" AllowPaging="True" AllowSorting="True" PageSize="10"
EnableModelValidation="True" DataKeyNames="promoId" OnRowCommand="GvPage_RowCommand"
OnPageIndexChanging="GvPage_PageIndexChanging" OnSorting="GvPage_Sorting" onRowdatabound="SiteGridView_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="PromotionId">
<ItemTemplate>
<asp:Label ID="lblId2" runat="server" Text='<%# Bind("promoId") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle CssClass="grid_view_hide" />
<ItemStyle CssClass="grid_view_hide" />
</asp:TemplateField>
<asp:TemplateField HeaderText ="Membership Name" SortExpression="name" ItemStyle-Width="50%">
<ItemTemplate>
<asp:Label ID="lblSiteName" runat="server" Text='<%# Bind("titlePromo") %>' />
</ItemTemplate>
<ItemStyle Width="35%" />
</asp:TemplateField>
</Columns>
</asp:GridView>
代码隐藏:
if (!Page.IsPostBack)
{
BindData();
populateDDL();
ViewState["sortDirection"] = ASCENDING;
ViewState["sortExpr"] = "titlePromo";
}
public void BindData()
{
String[,] catNameArr = populateCatID();
name = (String)Session["titlePromo"];
categoryName = (String)Session["membershipType"];
if (categoryName != null)
{
DropDownList1.SelectedValue = categoryName;
}
else
{
Session["titlePromo"] = "";
Session["membershipType"] = "All";
categoryName = "All";
name = "";
DataSet ds = dal.getEventList();
DataView myDataView = new DataView(ds.Tables[0]);
SiteGridView.DataSource = myDataView;
SiteGridView.DataBind();
int count = ds.Tables[0].Rows.Count;
if (count == 0)
{
Label6.Visible = false;
Label15.Text = "No record found";
Label15.ForeColor = System.Drawing.Color.Gray;
}
else if (count == 1)
{
Label6.Visible = true;
Label6.Text = count.ToString();
Label15.Text = "Total record:";
Label15.ForeColor = System.Drawing.Color.Black;
successMsg.Visible = false;
}
else
{
Label6.Visible = true;
Label6.Text = count.ToString();
Label15.Text = "Total record:";
Label15.ForeColor = System.Drawing.Color.Black;
successMsg.Visible = false;
}
}
//if(gridview.row[i].column[1].text/tostring() == ddlcatid.item[j].value.tostring())
if (name == null)
{
DataSet ds = dal.getPrjMgrList(categoryName);
DataView myDataView = new DataView(ds.Tables[0]);
SiteGridView.DataSource = myDataView;
SiteGridView.DataBind();
txtSearch.Text = name;
int count = ds.Tables[0].Rows.Count;
if (count == 0)
{
//show no record message
Label6.Visible = false;
Label15.Text = "No record found";
Label15.ForeColor = System.Drawing.Color.Gray;
//successMsg.Text = "No records found for this search";
//successMsg.Visible = true;
}
else
{ //hide no record message
if (count == 1)
{
Label6.Visible = true;
Label6.Text = count.ToString();
Label15.Text = "Total record:";
Label15.ForeColor = System.Drawing.Color.Black;
successMsg.Visible = false;
}
else
{
Label6.Visible = true;
Label6.Text = count.ToString();
Label15.Text = "Total records:";
Label15.ForeColor = System.Drawing.Color.Black;
successMsg.Visible = false;
}
}
}
//changes as of 15/11/2012
else
{
DataSet ds = dal.getPrjMgrList(categoryName, name);
DataView myDataView = new DataView(ds.Tables[0]);
SiteGridView.DataSource = myDataView;
SiteGridView.DataBind();
int count = ds.Tables[0].Rows.Count;
txtSearch.Text = name;
if (count == 0)
{
//show no record message
Label6.Visible = false;
Label15.Text = "No record found";
Label15.ForeColor = System.Drawing.Color.Gray;
//successMsg.Text = "No records found for this category";
//successMsg.Visible = true;
}
else
{ //hide no record message
if (count == 1)
{
Label6.Visible = true;
Label6.Text = count.ToString();
Label15.Text = "Total record:";
Label15.ForeColor = System.Drawing.Color.Black;
successMsg.Visible = false;
}
else
{
Label6.Visible = true;
Label6.Text = count.ToString();
Label15.Text = "Total records:";
Label15.ForeColor = System.Drawing.Color.Black;
successMsg.Visible = false;
}
}
}
if (categoryName == "All")
{
DataSet ds = dal.getPrjMgrListAll(categoryName, name);
DataView myDataView = new DataView(ds.Tables[0]);
SiteGridView.DataSource = myDataView;
SiteGridView.DataBind();
int count = ds.Tables[0].Rows.Count;
txtSearch.Text = name;
if (count == 0)
{
Label6.Visible = false;
Label15.Text = "No record found";
Label15.ForeColor = System.Drawing.Color.Gray;
}
else if (count == 1)
{
Label6.Visible = true;
Label6.Text = count.ToString();
Label15.Text = "Total record:";
Label15.ForeColor = System.Drawing.Color.Black;
successMsg.Visible = false;
}
else
{
Label6.Visible = true;
Label6.Text = count.ToString();
Label15.Text = "Total record:";
Label15.ForeColor = System.Drawing.Color.Black;
successMsg.Visible = false;
}
}
for (int i = 0; i < SiteGridView.Rows.Count; i++)
{
for (int j = 0; j < DropDownList1.Items.Count; j++)
{
if (((Label)SiteGridView.Rows[i].FindControl("lblId2")).Text == DropDownList1.Items[j].Value)
{
((Label)SiteGridView.Rows[i].FindControl("lblId2")).Text = DropDownList1.Items[j].Text;
}
}
}
}
protected void GvPage_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
SiteGridView.PageIndex = e.NewPageIndex;
BindData();
}
【问题讨论】: