Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
360
How to clear the data from all rows?
posted

When the page loads, it populates the UltraWebGrid with available data. I want to give the customer the option to clear everything so they can start with a fresh empty grid. I am trying to find a way to clear the data either client side or server side.

thanks.

Parents
No Data
Reply
  • 28464
    Verified Answer
    posted

    Hello,

    It really depends whether you are binding the grid in bound or unbound mode, and if you are in bound mode, are you using DataSourceID and use a declarative datasource (like AccessDataSource, LinqDataSource, etc) or are you using DataSource with a runtime datasource like DataTable, business object, etc?

    Also, are you using InitializeDataSource event (it gets automatically called when grid needs rebinding, so it may override some of the custom actions you do, depending on where in the page lifecycle you are using them.

    Something you can try is setting DataSourceID to String.Empty and/or DataSource to null and then call DataBind() explicitly. Alternatively, you can create a very simple empty DataTable and bind the grid to it (just with the columns you need)

    e.g.

    private DataTable CreateEmptyDataTableWithSchema()
    {

    DataTable myDataTable = new DataTable();

    DataColumn myDataColumn;

    myDataColumn = new DataColumn();
    myDataColumn.DataType = Type.GetType("System.String");
    myDataColumn.ColumnName = "id";
    myDataTable.Columns.Add(myDataColumn);

    myDataColumn = new DataColumn();
    myDataColumn.DataType = Type.GetType("System.String");
    myDataColumn.ColumnName = "username";
    myDataTable.Columns.Add(myDataColumn);

    myDataColumn = new DataColumn();
    myDataColumn.DataType = Type.GetType("System.String");
    myDataColumn.ColumnName = "firstname";
    myDataTable.Columns.Add(myDataColumn);

    myDataColumn = new DataColumn();
    myDataColumn.DataType = Type.GetType("System.String");
    myDataColumn.ColumnName = "lastname";
    myDataTable.Columns.Add(myDataColumn);

    return myDataTable;

    ....

    UltraWebGrid1.DataSource = CreateEmptyDataTableWithSchema();

    UltraWebGrid1.DataBind();

    ....

Children
No Data