0

我正在尝试在 aspx 中使用 jquery ui 主题(选项卡)。$(function () { $('#tabs').tabs(); });

<form id="form1" runat="server">    
<div id="tabs">
    <ul>
        <li><a href="#tabs-1">tab 1</a></li>
        <li><a href="#tabs-2">tab s2</a></li>
        <li><a href="#tabs-3">tab 3</a></li>
    </ul>
    <div id="tabs-1">
        tab-1
    </div>
    <div id="tabs-2">
        tab-2
    </div>
    <div id="tabs-3">
        Gridview is here
    <asp:Button ID="Button2" runat="server" Height="31px" Text="Button" 
             onclick="Button2_Click" />
    </div>
    </div>
    </form>

现在我正在调用函数 button2_click 在 Gridview 上执行一些操作,但我收到错误 Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server

protected void Button2_Click(object sender, EventArgs e)
    {
        ExportToExcel(GridView1, "HElloWorld");
    }
    private void ExportToExcel(GridView gv, string filename)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment;filename=" + filename + ".xls");

        Response.Charset = "";

        Response.ContentType = "application/vnd.ms-excel";

        StringWriter sw = new StringWriter();

        HtmlTextWriter hw = new HtmlTextWriter(sw);


        gv.RenderControl(hw);



        string style = @"<style> .textmode { mso-number-format:\@; } </style>";

        Response.Write(style);
        //Response.Write(GetMessage());
        Response.Output.Write(sw.ToString());
        // Response.Write(GetFooter());
        Response.Flush();

        Response.End();

    }

gv.RenderControl(hw) 出现错误;

4

1 回答 1

1

那是因为您缺少一个 div 结束标记。放在</div>前面</form>,它应该可以工作。

谷歌搜索得到我这个,只需重写方法 Page.VerifyRenderingInServerForm 方法,如下:

public override void VerifyRenderingInServerForm(Control control) { return; }

就是这样。您将摆脱该错误...

于 2012-09-03T13:31:28.150 回答