0

跟进我之前提出的问题: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));
    }

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

4

0 回答 0