Click here to Skip to main content
15,886,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Thanx all for the help...now I need an another help....
need to insert data in that table....with a button click....plz help....
below was my previous question.....



I am using the below code to connect my database to gridview. then after debugging i am getting the following error....

what else do i need to do?
C#
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridView();
        }
    }
 
    private string GetConnectionString()
    {
        return System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
    }
 
    #region Bind GridView
    private void BindGridView()
    { 
        DataTable dt = new DataTable();
        SqlConnection connection = new SqlConnection(GetConnectionString()); 
        try
        {
            connection.Open();
            string sqlStatement = "SELECT Top(10)* FROM Customers";
            SqlCommand cmd = new SqlCommand(sqlStatement, connection);
            SqlDataAdapter sqlDa = new SqlDataAdapter(cmd);
 
              sqlDa.Fill(dt);
              if (dt.Rows.Count > 0)
              {
                GridView1.DataSource = dt;
                GridView1.DataBind();
              }
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
                string msg = "Fetch Error:";
                msg += ex.Message;
                throw new Exception(msg);
        }
        finally
        {
            connection.Close();
        }
    }
    #endregion
}





********Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS1061: 'ASP.default2_aspx' does not contain a definition for 'GridView1_SelectedIndexChanged' and no extension method 'GridView1_SelectedIndexChanged' accepting a first argument of type 'ASP.default2_aspx' could be found (are you missing a using directive or an assembly reference?)

Source Error:

 

Line 9:           
Line 10:     <p>
Line 11:         <asp:GridView ID="GridView1" runat="server" 
Line 12:             onselectedindexchanged="GridView1_SelectedIndexChanged">
Line 13:         </p>
Posted
Updated 19-Apr-12 23:51pm
v4
Comments
P.Salini 20-Apr-12 4:12am    
What is your Problem, are you getting any error?
sourch7373 20-Apr-12 4:53am    
Getting the following error


********Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1061: 'ASP.default2_aspx' does not contain a definition for 'GridView1_SelectedIndexChanged' and no extension method 'GridView1_SelectedIndexChanged' accepting a first argument of type 'ASP.default2_aspx' could be found (are you missing a using directive or an assembly reference?)

Source Error:



Line 9:
Line 10: <p>
Line 11: <asp:GridView ID="GridView1" runat="server"
Line 12: onselectedindexchanged="GridView1_SelectedIndexChanged">
Line 13: </p>.

Just Check The aspx.cs code that Selected_Changed event is clicked or not ?
& If not Click the properties of gridview & On Events Click Selected_Changed COde To remove the error
Hope it will be Helpful.
Thanks
 
Share this answer
 
Comments
sourch7373 20-Apr-12 5:31am    
thanx...gt it
sourch7373 20-Apr-12 5:49am    
I need one more help plz....Its working now...i am getting the table from database on my website...now I want to insert data in that....what should I do?
[no name] 20-Apr-12 6:17am    
Thanks If I solved your problem please Accept it & Vote it up(Show some kindness).
What kind of data you want to insert & How? Please Provide detail Information .
Thanks
sourch7373 24-Apr-12 1:58am    
I need to create an application like below....
there should be some text box.after giving the data into the text box i need to click the add button. then the data should be included in the gridview as well as in my database...how should i do that?
C#
SqlConnection conn = new SqlConnection("server=Servername;database=DatabaseName;uid=UserID;pwd=Password");

        try
        {
            conn.Open();
            SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Table_Name , conn);

            DataTable dt = new DataTable();
            adapter.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                GridView1.DataSource = dt;
                GridView1.DataBind();                
        }
        catch (Exception ex)
        {
           //Exception message
        }
        finally
        {
            conn.Close();
        }
 
Share this answer
 
v2

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