Getting error in gridview using object data source.

Posted by Sreekanthv5 under ASP.NET on 9/6/2011 | Points: 10 | Views : 1046 | Status : [Member] | Replies : 1
It is displaying empty in gridview i think problem in Business Object. please help me. I am fed up i am trying from last night.




in BO.cs
namespace Business_Object
{
public class company:Icompany
{
int _empid=0 ;

public int empid
{
set
{
if (value != _empid)
_empid = value;

}
get
{
return _empid;
}

}

string _empname ;

public string empname
{
get
{
return _empname;
}
set
{
value = _empname;
}
}

int _jobid ;

public int? jobid
{
get
{
return _jobid;
}
set
{
value = _jobid;
}
}

DateTime _hiredate;
public DateTime? hiredate
{
get
{
return _hiredate;
}
set
{
value = _hiredate;
}
}
}
}

in BLL.cs
namespace BLL
{
public class Employees
{
public List<company> GetEmployees()
{
company c = new company();
CompanyDataContext db=new CompanyDataContext();
List<company> listemp=new List<company>();
listemp = (from p in db.Employees
select new company { empid = c.empid, empname = c.empname, jobid = c.jobid, hiredate = c.hiredate }).ToList();
return listemp;

}
}
}

in default.aspx.cs
<asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="empid" HeaderText="empid" SortExpression="empid" />
<asp:BoundField DataField="empname" HeaderText="empname"
SortExpression="empname" />
<asp:BoundField DataField="jobid" HeaderText="jobid" SortExpression="jobid" />
<asp:BoundField DataField="hiredate" HeaderText="hiredate"
SortExpression="hiredate" />
</Columns>
</asp:GridView>

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="BusinessObject.ompany" TypeName="BLL.Employees" SelectMethod="GetEmployees">


</asp:ObjectDataSource>




Responses

Posted by: Vuyiswamb on: 9/6/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
In your Code i dont see where you bind the gridview, i see you have a function that GetEmployees() but you dont bind it anywhere. You need something like this

Gridview1.DataSource = GetEmployees;

Gridview1.Databind();


Thank you for posting at Dotnetfunda
[Administrator]

Sreekanthv5, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response