Add button column to datatable

13,606

Solution 1

Add Buttoncolumn in DataTable its wired ...thats not possible at all...

The DataTable DataColumn DataType property supports the following base .NET Framework data types:

  1. Boolean
  2. Byte
  3. Char
  4. DateTime
  5. Decimal
  6. Double
  7. Int16
  8. Int32
  9. Int64
  10. SByte
  11. Single
  12. String
  13. TimeSpan
  14. UInt16
  15. UInt32
  16. UInt64

Sample code to add coplumn

DataTable workTable = new DataTable("Customers"); 
DataColumn workCol = workTable.Columns.Add("CustID", typeof(Int32));
workCol.AllowDBNull = true;

Solution 2

You can add a button only on DataGrid not DataTable.

Share:
13,606
user1292656
Author by

user1292656

Updated on June 06, 2022

Comments

  • user1292656
    user1292656 almost 2 years

    I am trying to insert a button column into a datatable but it says that its an error. Any help pleasE?

            ButtonColumn col = new ButtonColumn();
            col.CommandName = "select";
            col.ButtonType = ButtonColumnType.LinkButton;
            col.HeaderText = "Edit";
            dt.Columns.Add(col);
    
  • Renatas M.
    Renatas M. about 12 years
    I think OP actually trying to add column to datagrid-datasource is datatable so that's why :)
  • Pranay Rana
    Pranay Rana about 12 years
    @Reniuz - i m wating for the update from op side so that i can update my answer according to that...
  • Tim Schmelter
    Tim Schmelter about 12 years
    I'm missing Byte[] in the above list. msdn.microsoft.com/en-us/library/…