我的listView源码大略如下:(省掉了一些重复项)
<form runat="server" id="form1" >
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<table width="2000px">
<thead>
<tr>
<th>ID</th>
<th>业务类型</th>
<th>订单编号</th>
<th>输入</th>
</tr>
</thead>
<tbody>
<asp:PlaceHolder runat="server" ID="itemPlaceholder" />
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("ID") %></td>
<td><%# Eval("ba01") %></td>
<td><%# Eval("ba02") %></td>
<td>
<asp:Button ID="btnAdd" runat="server" CommandArgument='<%# Eval("ID") %>' OnCommand="btnAdd_Command" Text="输入" />
</td>
<td>
<asp:Button ID="btndeleting" runat="server" CommandArgument='<%# Eval("ID") %>' OnCommand="btndeleting_Command" onclientclick="return confirm('是/否')" Text="删除" />
</td>
<td>
<asp:Button ID="btnediting" runat="server" CommandArgument='<%# Eval("ID") %>' OnCommand="btnediting_Command" Text="修改" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</form>
导出EXCEL的代码如下:
protected void AC_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "employee.xls");
}
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ListView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
报错的地方在 ListView1.RenderControl(hw); 报错的提示如下:
类型“Button”的控件“ListView1_ctrl0_btnAdd”必须放在具有 runat=server 的窗体标记内
我感觉这个提示有误,整个listView1控件都在form1 之内, 不知道在那里纠正,请大师指点,万分感谢.
button 不要ListView1 中
因为我要传值,所以选择了button,那改成什么好呢,能不能给一个示例代码
我改成 LinkButton控件,还是不行,照样报如下错误.
类型“LinkButton”的控件“ListView1_ctrl0_btnAdd”必须放在具有 runat=server 的窗体标记内
@zhengyingcan: 看来没得救了