none
Urgent: How to persist data in DataTable that is Appended RRS feed

  • Question

  •  

    Hello Guys and Gals,

     

    I need to know the following two items:

     

    1. How to append rows to a DataTable between PostBacks?

     

    2. Or how to DataView.Row.Filter based on contents in another different DataTable Data View?

    Tuesday, November 20, 2007 5:52 PM

All replies

  • Do you need to find out what rows have been appended so you can do the inserts? If so, the following code will grab them.

     

    Code Block

     

    DataTable added = table.GetChanges(DataRowState.Added);

     

     

     

    Tuesday, November 20, 2007 8:28 PM
  • No I have a dynamic list of dropdowns that need to be filled...

     

    What I need is the DataTable that I have which contains the invalid DDL Values to be appended to a master DataTable which I can then use to remove the matching DDL Values from another DataTable...

     

    Tuesday, November 20, 2007 8:32 PM
  • Are the schemas of the tables the same?

     

    Tuesday, November 20, 2007 8:53 PM
  • Yes but the problem is that on every postback, instead of adding to the DT it clears it of previous values and I want it to append and keep the values until the session is over.

     

    Tuesday, November 20, 2007 8:56 PM
  • So you need a way to persist the tables between postbacks? If it's not too much data, you can add it to the Session.

     

    Code Block

     

    Session["table"] = table;

     

     

    Tuesday, November 20, 2007 9:01 PM
  • Let me try it...I will post back if it is a solution as Answered...

     

    Tuesday, November 20, 2007 10:01 PM
  • Don't forget to retrieve it from the session on the way back. table = (DataTable)Session["table"];

     

    Tuesday, November 20, 2007 10:03 PM
  • Thank You but it really is not doing what I need...But thank you...

     

    I really need the following:

     

    I have DT#1 with four target columns that I care about(it has total of 6 columns).

    I have an ArrayList.

    I have DT#2 (Main DataTable)

     

    I need to see if DT#2 Row with values of Col#1 and Col#2  equals 'indexof +","+ value' of any of the ArrayList. If so I need to remove Row of DT#1 that equals values in Col#3 and Col#4 of same Row identified above in DT#2

     

    To Visualize:

     

    DT#2:

    ====================

     

    Col#1                   |       Col#2            |           Col#3            |     Col#4            

       1                       |       1                   |           43                 |     7

    3                         |       1                   |           23                 |     2

    ...

     

     

                             

    Tuesday, November 20, 2007 10:36 PM
  • I understand what you're asking here, and I can provide code to do just that. However, I'm very confused. I thought we were talking about appended or appending rows? The problem you have presented in this last message is about removing rows.

     

    Can you provide source for what you currently have? If there are missing sections that you're having problems with, you can put a comment in.

    Tuesday, November 20, 2007 11:08 PM
  • yeah...

     

    I thought that since I had a datatable with the invalid items every round trip, I could append the DataTable to a new clean DataTable and use this for filtering...but the problem as I most recently posted is the REAL problem...

     

    Any and all help will be much appreciated....! The code is too long to post all so hear is pertinent snippets:

     

    "

    for (i = 0; i < SelectionTotalCount - 1; i++)

    {

    DropDownList DDL = new DropDownList();

    CheckBox ChkBox = new CheckBox();

    Label newlbl = new Label();

    Label newlblb = new Label();

    myEventArgs configErr = new myEventArgs(DDL.ID);

    using (DDL)

    {

    DDL.ID = "DropDown" + (i + 1);

    DDL.DataTextField = "Description";

    DDL.AutoPostBack = true;

    DDL.Visible = true;

    DDL.DataValueField = "SelCriterion";

    DDL.SelectedIndexChanged += new EventHandler(DDL_SelectedIndexChanged);

    }

    using (ChkBox)

    {

    ChkBox.ID = "CheckBox"+(i+1);

    ChkBox.Enabled = true;

    ChkBox.Visible = true;

    ChkBox.CheckedChanged += new EventHandler(ChkBox_CheckedChanged);

    ChkBox_CheckedChanged(ChkBox.ID, configErr);

    }

    using (newlbl)

    {

    newlbl.ID = "Labelnw" + (i + 1);

    newlbl.Text = Request.Params[DDL.ID];

    newdata += resultArray.Add(Request.Params[DDL.ID]);

    if (IsPostBack && i == 0)

    {

    newdata += (Int32.Parse(Request.Params[DDL.ID])) + "(" + Request.Params[ChkBox.ID] +")" + ",";

    }

    else

    {

    newdata += Request.Params[DDL.ID] + "(" + Request.Params[ChkBox.ID] + ")" + ",";

    }

    newlbl.Visible = true;

    }

    using (newlblb)

    {

    newlblb.ID = "Labelnwb" + (i + 1);

    newlbl.Visible = true;

    }

    //end using

    configDescripTbl = configDescriptions.ConfigParsed();

    configView = configDescripTbl.DefaultView;

    OptionalViewRS = configDescripTbl.DefaultView;

    configView.RowFilter = "SelectionNum = '" + (i + 1) + "' ";

    {

    PlaceHolder1.Controls.Add(new LiteralControl("<br />"));

    PlaceHolder1.Controls.Add(configLabel);

    OptionalViewRS.RowFilter = "SelectionNum = '" + (i + 1) + "'AND SelectionFlag='O'";

    if (OptionalViewRS.Count > 0)

    {

    PlaceHolder1.Controls.Add(new LiteralControl("<br/>Skip"));

    PlaceHolder1.Controls.Add(ChkBox);

    }

    configView.RowFilter = "SelectionNum = '" + (i + 1) + "' ";

    PlaceHolder1.Controls.Add(new LiteralControl("<br />"));

    PlaceHolder1.Controls.Add(DDL);

    PlaceHolder1.Controls.Add(new LiteralControl("<br />"));

    }

    if (!IsPostBack)

    {

    DDL.DataSource = configView;

    DDL.DataBind();

    }

    else

    {

    DDL.DataSource = newdt;

    DDL.DataBind();

    }

    } //end for

    Tuesday, November 20, 2007 11:15 PM