Click here to Skip to main content
15,882,837 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
showing Error

Server Error in '/' Application.
Compilation 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.webform1_aspx' does not contain a definition for 'GridView1_SelectedIndexChanged' and no extension method 'GridView1_SelectedIndexChanged' accepting a first argument of type 'ASP.webform1_aspx' could be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 11:     <div>
Line 12:     
Line 13:         <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
Line 14:             BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" 
Line 15:             CellPadding="3" onselectedindexchanged="GridView1_SelectedIndexChanged" 

Source File: c:\Users\manish\Desktop\my vb program\WebApplication7\WebApplication7\WebForm1.aspx    Line: 13

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;

namespace WebApplication7
    public partial class WebForm1 : System.Web.UI.Page
        public OleDbConnection con;
        public OleDbCommand cmd;
        public OleDbDataAdapter adt;
        public DataSet ds;

        protected void Page_Load(object sender, EventArgs e)

    private void fillGridData()
    con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\manish\Desktop\my vb program\test.accdb");

        adt = new OleDbDataAdapter("select * from demo",con);
        ds=new DataSet();


        protected void Button1_Click(object sender, EventArgs e)
                         con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\manish\Desktop\my vb program\test.accdb");
string data1;
string cname;
string cmobile;
string caddress;
            cname=(GridView1.FooterRow.FindControl("TextBox1") as TextBox).Text;
            cmobile=(GridView1.FooterRow.FindControl("TextBox2") as TextBox).Text;
            caddress=(GridView1.FooterRow.FindControl("TextBox3") as TextBox).Text;
            data1="insert into demo values("+ cname+",'"+ cmobile +"','"+ caddress +"')";
            cmd = new OleDbCommand(data1,con);
            Label4.Text ="data saved successfully";


Updated 15-Feb-18 3:43am
Richard Deeming 15-Feb-18 11:35am    
data1="insert into demo values("+ cname+",'"+ cmobile +"','"+ caddress +"')";

Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]

using (OleDbConnection con = new OleDbConnection("..."))
using (OleDbCommand cmd = new OleDbCommand("insert into demo values (?, ?, ?)", con)
    cmd.Parameters.AddWithValue("cname", cname);
    cmd.Parameters.AddWithValue("cmobile", cmobile);
    cmd.Parameters.AddWithValue("caddress", caddress);

1 solution

Look at the error message

'ASP.webform1_aspx' does not contain a definition for 'GridView1_SelectedIndexChanged'

What is is looking for a method called GridView1_SelectedIndexChanged? Look at your gridview definition


Ok, now look ate your code-behind, do you have a method called GridView1_SelectedIndexChanged? No, so it doesn't know what to do when the selected index changed event is fired.

If you are interested in this event you need to add this event-handler to your code-behind, if you're not interested in the event remove the relevant attribute form your gridview definition.

GridView.SelectedIndexChanged Event (System.Web.UI.WebControls)[^]
Share this answer
manish7664 15-Feb-18 9:55am    
thnx F-ES

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