Why will the new button column that I added not show up after I have added it?

72 views Asked by At

Follow up from a previous question I have made: Getting and error I cannot fix when trying to add a button column

After making the aforementioned corrections given by the accepted answer, my code will now build successfully. However, neither the column header or the buttons will show up. Is there someplace I should be adding the column specifically? My code for generating the table looks like such:

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);
    }

And the part where I attempt to add a column of buttons are the last few lines. I have tried adding a new column beforehand in the local function 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));
    }

where the commented part was what I tried, but it made no impact.

0

There are 0 answers