Click here to Skip to main content
15,903,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written this html code in aspx page--

<td align="center">
<asp:LinkButton ID="viewdata" runat="server" onclick="viewdata_Click">
    <br />
    <asp:GridView ID="GridView1" runat="server">

And i have written this code in my cs page::--

protected void viewdata_Click(object sender, EventArgs e)//Code to View 

        //// the data from the SQL Server
        SqlConnection conn = new SqlConnection("user id=sa;" +
                                       "password=prodip@km;server=PRODIP;" +
                                       "Trusted_Connection=yes;" +
            SqlDataAdapter sda = new SqlDataAdapter("select * from emp", conn);
            DataSet ds = new DataSet();
            GridView1.DataSource = ds;


But the problem is ==the following two line shown as red underline & show the mess that
GridView1 dose not exit in current context..
the line are--

GridView1.DataSource = ds;

please help me where is my mistake..
Updated 17-Aug-13 0:21am

Looks like you have copied aspx code from other project. Sometime Visual studio does not add controls when text is copied from somewhere rather than dragging and dropping controls on form. If that is the case, you can remove your existing gridview control and try to add it again.
Share this answer
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900