添加后,我添加的新按钮列为什么不显示?

时间:2017-09-06 02:23:54

标签: c# asp.net datagridview buttonfield datagridviewbuttoncolumn

从上一个问题开始跟进:Getting and error I cannot fix when trying to add a button column

在接受的答案给出上述更正后,我的代码现在将成功构建。但是,列标题或按钮都不会显示。有什么地方我应该专门添加列吗?我生成表的代码如下:

void LoadDataTable()
    {
        //create table
        DataTable table = new DataTable();
        AddColumnToTable(table);

        //query all students
        IQueryable<Member> query = from mem in SLHS_DB.Members
                                       where mem.RoleId == (int)Credentials.MemberRole.STUDENT
                                       select mem;

        Member[] students = query.ToArray();

        //add them to table
        curStudentIndex = 0;

        foreach (Member student in students)
        {
            AddRowToTable(table, student);
        }


        //bind data to grid view
        gridViewStudent.DataSource = table;
        gridViewStudent.DataBind();

        var btn = new ButtonField();
        btn.HeaderText = "Click Data";
        btn.Text = "Click Here";

        gridViewStudent.Columns.Add(btn);
    }

我尝试添加一列按钮的部分是最后几行。我已经尝试在本地函数AddColumnToTable()中添加一个新列:

void AddColumnToTable(DataTable table)
    {
        table.Columns.Add(NUMBER    , typeof(int));
        table.Columns.Add(FIRSTNAME , typeof(string));
        table.Columns.Add(LASTNAME  , typeof(string));
        table.Columns.Add(AGE       , typeof(int));
        table.Columns.Add(EMAIL     , typeof(string));

        //table.Columns.Add(EDIT      , typeof(ButtonField));
    }

评论部分是我尝试过的,但没有产生任何影响。

0 个答案:

没有答案