its been 6 days passed since i started making this assignment of mine
it is to show how objectdatasource is used,
until now, i still cannot getaway with this error,
The data source for GridView with id 'GridView1' did not have any properties or attributes from which to generate columns. Ensure that your data source has content.
is anybody can help me? and check what is wrong with my codes?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="background-color: #FFCC00" >
<asp:GridView
ID="GridView1" runat="server" DataSourceID="ObjectDataSource1">
<Columns>
<asp:BoundField DataField="id" HeaderText="pID" />
<asp:BoundField DataField="firstname" HeaderText="firstName" />
<asp:BoundField DataField="lastname" HeaderText="lastName" />
<asp:BoundField DataField="age" HeaderText="age" />
<asp:BoundField DataField="contact" HeaderText="contact" />
<asp:BoundField DataField="address" HeaderText="address" />
<asp:BoundField DataField="email" HeaderText="email" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="select" TypeName="yaxclas"
>
</asp:ObjectDataSource>
</div> <br />
<div style="background-color: #800000">
<asp:Button ID="btn_prev" runat="server" Text="previous page" Font-Bold="True"
onclick="btn_prev_Click" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
/// <summary>
/// simple class with select method to be connected
/// to the objectdatasource
/// </summary>
public class yaxclas
{
int id;
int age;
int contact;
string email;
string address;
string firstname;
string lastname;
public yaxclas()
{
}
public yaxclas select()
{
yaxclas yxperson = new yaxclas();
string ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(ConnectionString);
string queryString ="SELECT * FROM person;";
try
{
con.Open();
SqlCommand cmd = new SqlCommand(queryString, con);
cmd.CommandType = CommandType.Text;
SqlDataReader reader = cmd.ExecuteReader();
if(reader.Read())
{
yxperson.id = (int)reader["pID"];
yxperson.firstname = reader["firstName"].ToString();
yxperson.lastname = reader["lastName"].ToString();
yxperson.age = (int)reader["age"];
yxperson.contact = (int)reader["contact"];
yxperson.address = reader["address"].ToString();
yxperson.email = reader["email"].ToString();
}
}
finally
{
con.Close();
}
return yxperson;
}
}