事件未在网格视图中触发 [英] Event not fire in grid view
问题描述
我想在网格视图中提供自定义分页...
i want to provide custom paging in grid view...
<asp:GridView ID="gvFirst" runat="server" AutoGenerateColumns="false"
AllowPaging="true"
ondatabound="gvFirst_DataBound" >
<Columns>
<asp:BoundField DataField="ID" HeaderText="ProductID"/>
<asp:BoundField DataField="Name" HeaderText="ProductName" />
</Columns>
<PagerTemplate>
<asp:Panel ID="pnlPager" runat="server">
</asp:Panel>
</PagerTemplate>
</asp:GridView>
如果我在此处创建按钮并绑定单击事件,则将引发火灾...但是问题是,每行与网格绑定都会出现这种现象.
If i create button here and bind click event then it is fire...but problem is this evet occur for each row bind with grid
protected void gvFirst_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Pager)
{
Panel pnPager = e.Row.FindControl("pnlPager") as Panel;
if (pnPager != null)
{
Button btnFirst = new Button();
btnFirst.Text = "1";
btnFirst.Click += new EventHandler(btnFirst_Click);
pnPager.Controls.Add(btnFirst);
}
}
}
如果我在此处创建按钮并绑定click事件,则不会触发...在所有行都绑定到grid..so之后将触发此事件.因此,它只会发生一次..
If i create button here and bind click event then it is not fire...this event fire after all the rows bind to grid..so it will occur only once..
protected void gvFirst_DataBound(object sender, EventArgs e)
{
GridViewRow gvRow = gvFirst.BottomPagerRow;
if (gvRow != null)
{
Panel pnPager = gvRow.FindControl("pnlPager") as Panel;
if (pnPager != null)
{
Button btnFirst = new Button();
btnFirst.Text = "1";
btnFirst.Click += new EventHandler(btnFirst_Click);
pnPager.Controls.Add(btnFirst);
}
}
}
void btnFirst_Click(object sender, EventArgs e)
{
using (_NorthWindDataContext = new NorthWindDataContext())
{
var ProductInformation = from p in _NorthWindDataContext.Products
select new
{
ID = p.ProductID,
Name = p.ProductName
};
gvFirst.DataSource = ProductInformation.Skip(5).Take(5);
gvFirst.DataBind();
}
}
请帮助我了解这一点...
**我面临的另一个问题是** ...
我想提供自定义分页,现在我已将页面大小设置为5,并且正在从查询中获取5条记录,因此无法显示我的网格分页器,请帮我解决这个问题.
pls help me to understand this...
**Another problem which i am facing is**...
i want to provide custom paging , now i have set page size to 5 and i am fetching 5 record from query so my grid pager is not display please help me out of this...
推荐答案
对于分页,您可以检查此[ ^ ]
For Paging you can check this [^]
已添加PageIndexchanged事件吗?
受保护的void GridView1_PageIndexChanging(对象发送者,GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
}
试试这个,
HAve u added PageIndexchanged event ?
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
}
try this ,
这篇关于事件未在网格视图中触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!