情况一:
<asp:GridView ID="gvFriend" runat="server" AutoGenerateColumns="False" CellPadding="4"
GridLines="None" CellSpacing="1" BackColor="#EEEEEE" Width="577px" OnRowCommand="gvFriend_RowCommand"
BorderStyle="Groove" AllowPaging="True" AllowSorting="True" OnRowDataBound="gvFriend_RowDataBound"
OnRowCreated="gvFriend_RowCreated" OnRowDeleting="gvFriend_RowDeleting" OnPageIndexChanging="gvFriend_PageIndexChanging"
OnSorting="gvFriend_Sorting">
<PagerSettings Mode="Numeric" />
<RowStyle BackColor="White" BorderColor="#EEEEEE" />
<Columns>
<asp:TemplateField HeaderText="番号">
<ItemTemplate>
<%# (Container.DataItemIndex+1).ToString()%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserID" HeaderText="用户ID" />
<asp:BoundField DataField="UserName" HeaderText="用户名" />
<asp:BoundField DataField="Sex" HeaderText="性别" SortExpression="Sex"/>
<asp:BoundField DataField="Age" HeaderText="年龄" SortExpression="Age"
ItemStyle-HorizontalAlign="Right" >
<ItemStyle HorizontalAlign="Right"> </ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Status" HeaderText="Status">
<ItemStyle CssClass="hidden" />
<ControlStyle CssClass="hidden" />
<HeaderStyle CssClass="hidden" />
<FooterStyle CssClass="hidden" />
</asp:BoundField>
<asp:TemplateField HeaderText="操作" ShowHeader="False" ItemStyle-Width="100">
<ItemTemplate>
<asp:Button ID="btnAdd" runat="server" CausesValidation="false" CommandName="Add"
Text="加入" onclick="btnAdd_Click"> </asp:Button> </ItemTemplate> 点击加入按钮时,报“未能加载视图状态。......."错误。 情况二:
在Gridview 中加上 enableView = "false"。错误是不报了,但是后台只进入Page_Load, btnAdd_Click和gvFriend_RowCommand都没有进去。不知道为什么。
<asp:GridView ID="gvFriend" runat="server" AutoGenerateColumns="False" CellPadding="4"
GridLines="None" CellSpacing="1" BackColor="#EEEEEE" Width="577px" OnRowCommand="gvFriend_RowCommand"
BorderStyle="Groove" AllowPaging="True" AllowSorting="True" OnRowDataBound="gvFriend_RowDataBound"
OnRowCreated="gvFriend_RowCreated" OnRowDeleting="gvFriend_RowDeleting" OnPageIndexChanging="gvFriend_PageIndexChanging"
OnSorting="gvFriend_Sorting">
<PagerSettings Mode="Numeric" />
<RowStyle BackColor="White" BorderColor="#EEEEEE" />
<Columns>
<asp:TemplateField HeaderText="番号">
<ItemTemplate>
<%# (Container.DataItemIndex+1).ToString()%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserID" HeaderText="用户ID" />
<asp:BoundField DataField="UserName" HeaderText="用户名" />
<asp:BoundField DataField="Sex" HeaderText="性别" SortExpression="Sex"/>
<asp:BoundField DataField="Age" HeaderText="年龄" SortExpression="Age"
ItemStyle-HorizontalAlign="Right" >
<ItemStyle HorizontalAlign="Right"> </ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Status" HeaderText="Status">
<ItemStyle CssClass="hidden" />
<ControlStyle CssClass="hidden" />
<HeaderStyle CssClass="hidden" />
<FooterStyle CssClass="hidden" />
</asp:BoundField>
<asp:TemplateField HeaderText="操作" ShowHeader="False" ItemStyle-Width="100">
<ItemTemplate>
<asp:Button ID="btnAdd" runat="server" CausesValidation="false" CommandName="Add"
Text="加入" onclick="btnAdd_Click"> </asp:Button> </ItemTemplate> 点击加入按钮时,报“未能加载视图状态。......."错误。 情况二:
在Gridview 中加上 enableView = "false"。错误是不报了,但是后台只进入Page_Load, btnAdd_Click和gvFriend_RowCommand都没有进去。不知道为什么。
解决方案 »
- JS调用ASP.NET问题
- 在datagridview中怎么让单元格只能输入货币类型的值?
- 请教一个AJAX问题
- 急求UpdatePanel 网页导入js 以至不能局部刷新
- 最近用sybase,不知如何备份
- 经验技巧分享--ASP.NET和Ajax应用一个超级实用的设计模式---享元工厂模式(泛型实现,模式名字不重要,关键是有用!)
- 紧急求助:web页面里调用数据库出现问题,怎么回事啊~~~~~~~~
- 关于DNS域名解析速度问题
- 求救:为什么编译错误时浏览器就连接到一个网站“www.internet-optimizer.com”呢?
- 哪位能救我,给我一个在asp.net中用WebService+xml在客户...
- 哪里有问题?急.......
- 遇到问题,散分了.
Text="加入"></asp:Button>添加gridview的rowcommand事件
protected void gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Add")
{
//do here
}
}
gridview就没有状态了,就不知道发生了什么事情,就不会触发事件的
就会报错。