Click here to Skip to main content
15,887,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
It is displaying empty in gridview, I think problem is in Business Object. Please help me. I am fed up,Ii am trying from last night.

In BO.cs:
ASP.NET
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:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="BusinessObject.ompany" TypeName="BLL.Employees" SelectMethod="GetEmployees">


        </company></company></company>
Posted
Updated 5-Sep-11 21:44pm
v2
Comments
Abhijit Jana 6-Sep-11 3:46am    
What is the error ?

1 solution

Your accessors are back to front.

E.G. You have written

C#
DateTime _hiredate;

public DateTime? hiredate
{
    get
    {
        return _hiredate;
    }
    set
    {
        value = _hiredate; // back to front
    }
}


But what you should have is
C#
DateTime? _hiredate;

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


N.B. Notice that I have also had to make the member variable a nullable type too - this is required by the set accessor as you may be passing in a null value
 
Share this answer
 

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