0
votes

I am trying to emulate another form that the other developer here created. In the DevExpress gridview, he added a new row button to the filter row, rather than to each row. I figured out how to do that by copying the custom button into the appropriate place in the filter row.

My question is how do I add the functionality to it? I found the addnewrow() method in the documentation, but it required a DataTable() class that I couldn't figure out how to get. Can you help me? I just started working with your ASPxGridView control today so this is all new to me.

Here is some of the code I found for adding a new row on DevExpress's gridview. But it feels like I am on the wrong track. And my first question about it is where do I find the DataTable class? Is there a simpler way to do this?

DataTable GetTable()
    {
        //You can store a DataTable in the session state
        DataTable table = Session["Table"] as DataTable;
        if (table == null)
        {
            table = new DataTable();

            DataColumn colid = table.Columns.Add("ID", typeof(Int32));
            DataColumn nameid = table.Columns.Add("Name", typeof(String));
            table.PrimaryKey = new DataColumn[] { colid };
            colid.ReadOnly = true;

            for (int i = 0; i < 23; i++)
            {
                DataRow aRow = table.NewRow();
                aRow["ID"] = i;
                aRow["Name"] = String.Format("Name{0}", i);

                table.Rows.Add(aRow);
            }
            Session["Table"] = table;
        }
        return table;
    }
    protected void grid_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        ASPxGridView grid = sender as ASPxGridView;

        DataTable table = GetTable();
        table.Rows.Add(new Object[] { e.NewValues["ID"], e.NewValues["Name"] });

        Session["Table"] = table;

        e.Cancel = true;
        grid.CancelEdit();
    }
1
Can you explain what are you trying to achieve? Do you need to use DataTable? Do you want to bind grid to datasource that retrieves data from database? - Filip
I'm trying to add a new button to the filter row, rather than having it in each data row. I don't know if I need to use DataTable. Yes, I want to bind the grid. - sehummel

1 Answers

0
votes

You should get a bit of general knowledge before you do this. Look here for data binding explanation and here for ASPxGridView editing demos. Storing data in session (like in sample you found) is rarely a way to go.
As for add new row you can use ASPxClientGridView.AddNewRow client side method. So, assign ClientInstanceName to your ASPxGridView (e.g. grid1) and call grid1.AddNewRow() on button click event - ASPxButton.ClientSideEvents.Click.