Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using gridview to display details of all records but after i execute it,it is not displaying anything.and i am getting exception as- DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'id'.

my c# code is-
C#
protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = Session["name"].ToString();
            if (!IsPostBack)
            {
                detail();
               
            }
            
        }
        public void detail()
        {
             SqlConnection conn = new SqlConnection("Data Source=SNEHAL-PC\\SNEHAL1;Initial Catalog=TEMPRUJU;Integrated Security=True");
        SqlCommand cmd;
        conn.Open();
        //String st = "select name,midname,surname,contact,dob,email,address,ltype,image from login";
            cmd=new SqlCommand("select name,midname,surname,contact,dob,email,address,ltype,image from login",conn);
        DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            SqlDataAdapter ad = new SqlDataAdapter(cmd);
           
            ad.Fill(ds);

            GridView2.DataSource = ds;

            GridView2.DataBind();
             conn.Close();
           }

and my aspx file code-

ASP.NET
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False">
           <columns>
               <asp:TemplateField HeaderText="id" Visible="False">
                   <edititemtemplate>
                       <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("id") %>'>
                   </edititemtemplate>
                   <itemtemplate>
                       <asp:Label ID="Label1" runat="server" Text='<%# Eval("id") %>'>
                   </itemtemplate>
               
               <asp:TemplateField HeaderText="Name">
                   <edititemtemplate>
                       <asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("name") %>'>
                   </edititemtemplate>
                   <itemtemplate>
                       <asp:Label ID="Label2" runat="server" Text='<%# Eval("name") %>'>
                   </itemtemplate>
               
               <asp:TemplateField HeaderText="MiddleName">
                   <edititemtemplate>
                       <asp:TextBox ID="TextBox3" runat="server"  Text='<%# Eval("midname") %>'>
                   </edititemtemplate>
                   <itemtemplate>
                       <asp:Label ID="Label3" runat="server" Text='<%# Eval("midname") %>'>
                   </itemtemplate>
               </columns>
Posted
Updated 13-Feb-14 23:37pm
v2
Comments
Siva Hyderabad 14-Feb-14 5:43am    
you forget the column "id" from select statement..

u need to do one thing match your
Eval("id")
with table coulmn...it seems that your database table coulmn and eval("coulmn_id") both are mismatches...or..

and also select table coulmn id from query like this

cmd=new SqlCommand("select name,id,midname,surname,contact,dob,email,address,ltype,image from login",conn);
 
Share this answer
 
v2
Comments
Member 10523130 14-Feb-14 5:45am    
i checked it.Both are matching.In my table also column name is id.then what is the problem?
Sumit_Pathak 14-Feb-14 5:47am    
have u change your query..?
Member 10523130 14-Feb-14 5:57am    
thanx.It worked
Sumit_Pathak 14-Feb-14 6:01am    
if u got exact answer..then dont remember to mark as solution...
the column name in the database must match check your id ,and in your select you haven't mentioned id
 
Share this answer
 
Comments
Member 10523130 14-Feb-14 5:46am    
i checked it.Both are matching.In my table also column name is id.then what is the problem?
Member 10476757 14-Feb-14 5:50am    
change your sqlquery or else copy and paste your sql query in sqlserver and execute and see the output there
Member 10523130 14-Feb-14 5:46am    
and i have not mentioned id in select because i do not want to display id in gridview.
Member 10476757 14-Feb-14 5:51am    
you made it visible false thats enough the data comes but doesn't displays
Member 10523130 14-Feb-14 5:58am    
okay.Thanx.I change my qury.and selected id.it worked.

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