kanuri1 -2 Junior Poster in Training

hi i wants to import gridview data into excel format..
here iam writing the code but here iam getting the error as
"Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server."
here my code is given below please correct the code.........

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Call fillgrid()
        End If
    End Sub

    Private Sub fillgrid()
        adp1 = New SqlDataAdapter("select indentno as 'Indent No.',Convert(Varchar,issuedate,103) as 'Issue Date ', itemname as 'Item_Name', serialnos as 'Serial Nos.',location as 'Location',project as 'Project', qtyissued as 'Qty Issued' from indent", con)
        adp1.Fill(ds, "issues")
        GridView1.DataSource = ds
        GridView1.DataBind()
        GridView1.Dispose()
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Response.Redirect("menu.aspx")
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        Response.ClearContent()
        Response.AddHeader("content-disposition", "attachment; filename=indent.xls")
        Response.Charset = ""
        Response.ContentType = "application/excel"
        Dim sw As New IO.StringWriter()
        Dim htw As New HtmlTextWriter(sw)
        GridView1.DataSource = ds
        GridView1.RenderBeginTag(htw)
        GridView1.RenderControl(htw)
        Response.Write(sw.ToString())
        Response.End()

    End Sub

    Protected Overloads Overrides Sub Render(ByVal writer As HtmlTextWriter)
        If Request.Form IsNot Nothing Then
            If Request.Form(Button1.ClientID) IsNot Nothing Then
                writer.WriteLine("The page was rendered")
                Exit Sub
            End If
        End If
        MyBase.Render(writer)
    End Sub
End Class
<body bgcolor="cornsilk">
    <form id="form1" runat="server">
    <div style="text-align: center">       &nbsp;&nbsp;&nbsp;
        <asp:Label ID="Label2" runat="server" BackColor="White" BorderStyle="Outset" BorderWidth="2px" Font-Bold="True" Font-Size="X-Large" Style="position:relative; left: 58px; top: -8px; z-index: 100;" Text="INDENT REPORT" Width="200px" ForeColor="Maroon"></asp:Label>&nbsp;&nbsp;
        &nbsp;
        <asp:Button ID="Button1" runat="server" Style="position: relative; left: 258px; top: -6px; z-index: 101;" Text="Back to Main Menu" CausesValidation="False" Width="144px" Font-Bold="True"></asp:Button><br />
        <br />
        <center>
    <asp:GridView ID="GridView1" runat="server" Style="position: relative; left: -21px; top: 6px; z-index: 102;" BackColor="cornsilk" BorderColor="Black" BorderStyle="Solid" ForeColor="#0000C0" CellPadding="1" CellSpacing="1">
        <RowStyle BorderColor="#000040" BorderStyle="Solid" />
        <PagerStyle Width="16px" />
        <SelectedRowStyle HorizontalAlign="Center" />
        </asp:GridView>
            <asp:Button ID="Button2" runat="server" Style="z-index: 104; left: 693px; position: absolute;
                top: 51px" Text="Button" />
        </center>
    </div>
    </form>
</body>

please correct the code
thnx.............

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.