怎样禁止gridview 换页的时候会触发RowCommand事件 gridview 换页的时候会触发RowCommand事件,导致GridViewRow索引超出范围 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是不能禁止的,你把RowCommand事件暂时屏蔽就可以了。 判断下,如果是翻页事件,return 但是选择行要用到RowCommand事件 会触发,RowCommand事件是GridView内生成事件时就会激发 本帖最后由 net_lover 于 2011-07-29 08:58:29 编辑 <asp:GridView ID="gvSubCate" runat="server" DataKeyNames="ID" AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical" AllowPaging="True" onpageindexchanging="gvSubCate_PageIndexChanging" onrowcommand="gvSubCate_RowCommand" onrowdeleting="gvSubCate_RowDeleting" PageSize="5"> <RowStyle BackColor="#F7F7DE" /> <Columns> <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True"> <ItemStyle HorizontalAlign="Center" Width="80px" /> </asp:BoundField> <asp:BoundField DataField="SubCateName" HeaderText="次类名"> <ItemStyle HorizontalAlign="Center" Width="200px" /> </asp:BoundField> <asp:BoundField DataField="CateName" HeaderText="主类名"> <ItemStyle HorizontalAlign="Center" Width="200px" /> </asp:BoundField> <asp:CommandField HeaderText="编辑" SelectText="编辑" ShowSelectButton="True"> <ItemStyle HorizontalAlign="Center" Width="100px" /> </asp:CommandField> <asp:CommandField HeaderText="删除" ShowDeleteButton="True"> <ItemStyle HorizontalAlign="Center" Width="100px" /> </asp:CommandField> </Columns> <FooterStyle BackColor="#CCCC99" /> <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /> <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView> protected void gvSubCate_PageIndexChanging(object sender, GridViewPageEventArgs e) { gvSubCate.PageIndex = e.NewPageIndex; GVBind();//数据绑定 Clear();//清空文本框,设置GridView的EditIndex=-1 } protected void gvSubCate_RowCommand(object sender, GridViewCommandEventArgs e) { int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = gvSubCate.Rows[index];//这里索引会超出范围 int id = Convert.ToInt32(row.Cells[0].Text); BLL.SubCate scBLL = new SubCate(); Model.SubCate sc = scBLL.GetModel(id); for (int i = 0; i < ddCateName.Items.Count; i++) { if (ddCateName.Items[i].Value == sc.CateID.ToString()) { ddCateName.SelectedIndex = i; } } txtSubCateName.Text = sc.SubCateName; btnAdd.Text = " 更 新 "; } 换页会触发 行绑定事件 不会触发RowCommand吧 你看看代码 本帖最后由 net_lover 于 2011-07-29 09:39:55 编辑 加if (!e.CommandName.Equals("Page")) 进行判断 if (!e.CommandName.Equals("Page")) 进行判断 是正解。 ASP.NET网站,日志,后台管理。 网站建三层 关于Theme,httphandle实现换肤,求代码哪里错了,50分哭求~ Asp2.0里如何给页面添加新的事件(双击页面默认是page_load事件,其它事件呢)? 为何不能Server.CreateObject()???? 四级联动菜单,asp.net+xml,请各位帮忙!有代码! 有事请大家帮忙!!!!!!!!!!!!!!!!1 请教···急啊··· 请问用OleDb中那种类型对应SqlDbType.Image中Image类型 asp.net的html控件与web控件分别用在什么地方 动态asp.net网页 找TextBox
<asp:GridView ID="gvSubCate" runat="server" DataKeyNames="ID"
AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE"
BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black"
GridLines="Vertical" AllowPaging="True" onpageindexchanging="gvSubCate_PageIndexChanging"
onrowcommand="gvSubCate_RowCommand" onrowdeleting="gvSubCate_RowDeleting" PageSize="5">
<RowStyle BackColor="#F7F7DE" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True">
<ItemStyle HorizontalAlign="Center" Width="80px" />
</asp:BoundField>
<asp:BoundField DataField="SubCateName" HeaderText="次类名">
<ItemStyle HorizontalAlign="Center" Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="CateName" HeaderText="主类名">
<ItemStyle HorizontalAlign="Center" Width="200px" />
</asp:BoundField>
<asp:CommandField HeaderText="编辑" SelectText="编辑" ShowSelectButton="True">
<ItemStyle HorizontalAlign="Center" Width="100px" />
</asp:CommandField>
<asp:CommandField HeaderText="删除" ShowDeleteButton="True">
<ItemStyle HorizontalAlign="Center" Width="100px" />
</asp:CommandField>
</Columns>
<FooterStyle BackColor="#CCCC99" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView> protected void gvSubCate_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvSubCate.PageIndex = e.NewPageIndex;
GVBind();//数据绑定 Clear();//清空文本框,设置GridView的EditIndex=-1
} protected void gvSubCate_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvSubCate.Rows[index];//这里索引会超出范围
int id = Convert.ToInt32(row.Cells[0].Text);
BLL.SubCate scBLL = new SubCate();
Model.SubCate sc = scBLL.GetModel(id);
for (int i = 0; i < ddCateName.Items.Count; i++)
{
if (ddCateName.Items[i].Value == sc.CateID.ToString())
{
ddCateName.SelectedIndex = i;
}
}
txtSubCateName.Text = sc.SubCateName; btnAdd.Text = " 更 新 ";
}
if (!e.CommandName.Equals("Page")) 进行判断
是正解。