Click here to Skip to main content
15,892,674 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--

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




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

C#
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;" +
                                       "database=Member;");
        try
        {
            SqlDataAdapter sda = new SqlDataAdapter("select * from emp", conn);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();

        }
}


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;
GridView1.DataBind();


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

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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


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