GridView显示错误 [英] Gridview displaying error

查看:58
本文介绍了GridView显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BO.cs

BO.cs

public class cmp:Icmp
    {
       DateTime? _datetime;
       public int Employeeid
       {
           get;
           set;
       }


       public string EmpName
       {
           get;
           set;
       }

       public int jobid
       {
           get;
           set;
       }

       public int managerid
       {
           get;
           set;
       }

       public DateTime? hiredate
       {

           get { return _datetime; }
           set { value = _datetime; }

       }



在DAL.cs中



in DAL.cs

public List<cmp> GetEmployees()
        {
            List<cmp> listemmployees = new List<cmp>();
            CompanyDataContext db = new CompanyDataContext();
            listemmployees = db.Employees.Select(p => new cmp { Employeeid = p.empid, EmpName = p.empname, hiredate=p.hiredate }).ToList();


            return listemmployees;
        }



在Default.aspx中



in Default.aspx

<asp:GridView ID="gv1" runat="server" DataSourceID="osd"

            AutoGenerateColumns="False" AutoGenerateEditButton="True" DataKeyNames="Employeeid"

             AutoGenerateDeleteButton="True" AllowPaging="True" PageSize="3" AutoGenerateSelectButton="true" EnablePersistedSelection="true" >
            <Columns>
                <asp:BoundField DataField="Employeeid" HeaderText="Employeeid"

                    SortExpression="Employeeid" />
                <asp:BoundField DataField="EmpName" HeaderText="EmpName"

                    SortExpression="EmpName" />
                <asp:BoundField DataField="jobid" HeaderText="jobid" SortExpression="jobid" />
                <asp:BoundField DataField="managerid" HeaderText="managerid"

                    SortExpression="managerid" />
                <asp:BoundField DataField="hiredate" HeaderText="hiredate"

                    SortExpression="hiredate" />
                <asp:BoundField DataField="salary" HeaderText="salary"

                    SortExpression="salary" />
            </Columns>
        </asp:GridView>

推荐答案



我认为您的UI中缺少绑定网格中的员工列表的代码:


Hi,

I think you lack code in your UI to bind list of employees in your grid:


gv1.DataSource = listemmployees;
gv1.DataBind();



希望这可以帮助...

请记住,如果有帮助,请将其标记为答案;如果没有帮助,则将其取消标记.

问候,

代数



Hope this could help...

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Regards,

Algem


这篇关于GridView显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆