Add values to an existing session without removing values - asp.net

I am looking into adding new values to an existing session. That session will have values in it and I hope that when I add these new ones into it, it would not remove whatever values that is already in that session. E.g. Before adding, the session has 1 value in it. After adding, it should show 2 values in it.
This is what I have tried:
List<string> toAdd = Session["SendData"] as List<string> ??new List<string>();
toAdd.Add(TxtData.Text.Trim());
Session["behzadList"] = behzadList;
I know that there is already some solutions regarding to this problem( the code above is 1 of them) However, when I tried this code, whatever values that were already in the session is being removed and the new values that I have just add would appear instead. So I am not too sure is there any other ways to solve this problem.
Thanks in advance.

List<string> toAdd = Session["SendData"] as List<string> ??new List<string>();
toAdd.Add(TxtData.Text.Trim());
Session["SendData"] = toAdd; // this was wrong it seems. You dont add to the same
session

So, I managed to solve it myself. I used 3 datatables, 1 to store the session values, 1 to store the values that I am going to add in. The last one, is used to merge both datatables values together.
Reason why so many datatables is actually based on your needs and your functions.
For me, it is actually not to confuse the user. I previously only used only 1 datatable. The steps are almost the same as the one I am showing below, but only difference is that you don need to do merging. However, when I add in the new values, it will display not just the values added, but also the values that were already in the session.
This is what I have changed:
//First store session values into the first datatable
DataTable dt = (DataTable)Session["SendData"]
//Create a second datatable to store the values you are going to add in
Datatable DT = new DataTable();
// Do whatever you need to fill this datatable with the values that are going to be added in.
//E.g. add columns, then use datarow to add into datatable or even sql query then fill etc.
//After that create a third datatable to do the merging
DataTable DT3 = new DataTable();
//At this point is where you will merge 2 datatables together.
DT3 = dt.Copy();
DT3.Merge(DT);
//The session will linked be the third datatable instead as it has all the values that you want
Session["SendData"] = DT3;
It kinda looks lengthly but I have to do the explaination as it can be confusing. You could possibly change some things here and there depending on what you want to do with the code. To anyone that may need this for some reference, hope this helps.
To the people that help me by commenting on this post, thanks for giving me suggestions.

Related

A list(of String) I have fails to populate on a post back but populates just fine on the initial page load

I am relatively new to programming so please bare with me if I use improper terminology for the question I am about to ask.
Currently, I have a list(of String) that I am populating with 2 values that I am pulling from a database. Code Below.
objCn.Open()
sqlTermSelect.Connection = objCn
sqlTermSelect.CommandText = "Select PartsTerm, LaborTerm FROM SKU INNER JOIN Agreement On SKU.SKU = Agreement.SKU WHERE Agreement = #Agreement"
sqlTermSelect.Parameters.Add("#Agreement", SqlDbType.VarChar, 50).Value = txtAgreement.Text
Dim termDA As New SqlDataAdapter(sqlTermSelect)
Dim termDT As New DataTable()
termDA.Fill(termDT)
For i As Integer = 0 To termDT.Rows.Count - 1
listValues.Add(termDT.Rows(i)("PartsTerm").ToString())
listValues.Add(termDT.Rows(i)("LaborTerm").ToString())
Next
objCn.Close()
I am then storing the values of this list in two variables that I use as checks to see whether certain controls on my page should be enabled/visible or disabled/invisible.
The page that this is affecting operates(for lack of a better word) in two ways, the first is a brand new page with empty controls that the user fills out. The second way is if the user begins to fill out the page and leaves, the data they filled out is saved and they can return later to continue filling it out (I am not 100% certain but I believe when a user returns to an "in progress" page it is a post back, I could be wrong, I'm not terribly sure how this is handled).
The problem I am having comes to when this list is populated with the database values. When I go to a brand new page, the list is populated and the controls mentioned above are enabled/disabled appropriately with no issues, the issue arises when I go to an "in progress" page the list values don't populate and the controls that should be disabled are enabled. Essentially, I am looking for a way to populate this list every time a page is opened, "in progress" or brand new. The code above that populates the list is in the PageLoad() event and I have verified that it is not in a "If Not IsPostBack" statement.
Any and all help would be greatly appreciated, if there is anything I should add to this post code related I would be more than happy to supply it.

How to get the value of `write_date` to a variable

In odoo every model will be having a write_date column which will store the last edited time and date of the record.I want to take the value of that field to a variable/ field. But when I print this , it is printing False . What to do.?
code
variable = self.write_date
Thanks in Advance..
The problem is that you're getting in self a new recordset (odoo.models.NewId object at 0x7fe0c05717d0). Therefore, you're trying to get the write_date of a record which has not been created yet. If the record has never been updated (even not created), it's not going to have a value in write_date.
Remember that write_date stores the latest date in which the record was updated.
So, first, at least, you must create the record, and then, you will be able to apply this: variable = self.write_date.
But take a look at this:
What's happening with these transient models' IDs?
May be you get the write_date without creating the record, give a try to this: variable = self._origin.write_date.
Even though we can see a field named write_date in the table, First of all, what we have to do is that you have to add a field named write_date into your model and then try the same.
write_date = fields.Datetime(string='Write Date') solved my problem.Thanks everyone for helping.

Using 'Filter by Column Value' and multi column filtering using a java vector - xPages

I have an xPage which I have built with 3 combo boxes and 1 view control. I would like to use the 'Filter by column value' option within the view control to provide the options to filter the values, allowing the user to display any combination of the combo boxes. e.g. Only comboBox1, or comboBox1 and comboBox2, or comboBox3 only, or comboBox1 and comboBox2 and comboBox3.
I used the example in the 'xPages Demonstration Application' (http://www-10.lotus.com/ldd/ddwiki.nsf/dx/xpagesdemoapp.htm or http://xpagesblog.com/XPagesHome.nsf/Entry.xsp?documentId=AAC8E26599256FDC852578CB0066CC13) to do the multi-column filtering using a vector of non-categorized columns.
So, I have come across what appears to be a fairly major issue whereby the data needs to be sorted by date. Date is not one of the filters, but it needs to be the first column in order for the data to be sorted correctly. So my first column is a string, YYYYMMDD, to ensure the data is sorted correctly. I tried to use the sort option within the view control and that does not appear to work with the column filtering implemented in this manner.
So, as Date one of the criteria I am filtering by, I have passed that as an empty string - using the thought process that an empty string will select all (as in the url examples above).
The code I have used to do the filtering is:
var vtr:java.util.Vector = new java.util.Vector();
var t1 = sessionScope.Email;
var t2 = sessionScope.Own;
var t3 = sessionScope.Module;
vtr.addElement("");
#If(sessionScope.Own=="My calls",vtr.addElement(t1),vtr.addElement(""));
#If(sessionScope.Own=="My calls",vtr.addElement(""),vtr.addElement(t2));
#If(sessionScope.Status=="Open",vtr.addElement("Open"),vtr.addElement(""));
#If(sessionScope.Module=="All",vtr.addElement(""),vtr.addElement(t3));
return vtr;
What I have found is that not all data is being returned. I thought this might be due to the date field. So I removed it (changing the view and removing the first add element), and yet I still find that not all data is being returned. I suspect that this might be due to the empty strings being passed, or, that this does not actually work the way I had hoped.
Does anyone know if I can get this working the way I want it to, and if not, do you have any suggestion on how I can go about this?
Date is not needed as the first sortable column in the view. The first column does need to be sorted for the lookup to work just like the Notes view needs to be sorted for #DbColumn and #DbLookup to work. XPages uses the same underlining architecture. This example - http://dev.openntf.org/demos/demoapp.nsf/viewFilteringVector.xsp - works without the data being sorted by Date.
My guess as to why your example isn't working is down to how your Notes view sorted. Try creating a new view with column 1 (email) ascending sort, column 2 (own) ascending sort, and column 3 (module) again ascending sort. You should be able to get vector filtering working in this situation.
If all that doesn't work for you, you might consider multi-layer category filtering (new to 853). This filtering type in XPages is related to how categoryFilter works but allow you to filter a view by the sub-category (or sub-categories) too. This technique might suit your scenario better. Hope this helps.

AdvancedDataGrid (grouping) quick jump to row

I have a problem with the AdvancedDataGrid widget. When the dataProvider is an ArrayCollection (of arrays), the nth array (within the collection) is also the nth row within the grid, and I can jump and display the i-th row by scripting
adg.selectedIndex = i;
adg.scrollToIndex(i);
now, when I add a Grouping, the dataProvider ends up being a GroupingCollection2, and now the index in the dataprovider's source does not correspond to the index in the adg anymore (which is understandable, because it's being grouped).
How can I select and display a row in grouped data efficiently? Currently, I have to traverse the adg and compare each found item with its data attributes in order to find the correct index of the row within the adg, and jump to it like above. This process is very slow. Any thoughts?
edited later:
We already used a caching object as Shaun suggests, but it still didn't compensate for the search times. In order to fully construct a sorting of a list of things (which this problem equates to, as the list is completely reordered by the grouping), you always have to know the entire set. In the end we didn't solve that problem. The project is over now. I will accept Shaun's answer if no one knows a better way in three days.
Depending on what values your comparing against you can store the objects in a dictionary with the lookup using the property/properties that would be searched for, this way you have a constant time look-up for the object (no need to look at every single item). Say for example your using a property called id on an object then you can create an AS object like
var idLookup:Object = {};
for(myObject in objects)
idLookup[myObject.id] = myObject;
//Say you want multiple properties
//idLookup[myObject.id]={};
//idLookup[myObject.id][myObject.otherProp] = myObject;
now say the user types in an id you go into the idLookup object at that id property and retrieve the object:
var myObject:Object = idLookup[userInput.text];
myAdg.expandItem(myObject, true);
now when you want to get an object by id you can just do
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/AdvancedDataGrid.html#expandItem()
I haven't done any thorough testing of this directly, but use a similar concept for doing quick look-ups for advanced filtering. Let me know if this helps at all or is going in the wrong direction. Also if you could clarify a bit more in terms of what types/number of values you need to lookup and if there's the possibility for multiple matches etc. I may be able to provide a better answer.
Good luck,
Shaun

Gridview Edit not working after Sorting ASP.NET

I am using C#,ASP.NET
I have a Gridview for which I have provided Sorting, Edit functionality. I am not able to perform EDIT when I perform Sorting. After sorting edit is set on some other row. I think there is some problem with the index it is taking..
Can any one help me how to fix this..
Regards
sbmarya
I think the issue is that the sorting is using a different call/datasouce than the editing. So in the RowEditing event I am getting an index relative to the sort order (either ASC() or DESC()). But then I am binding using getUsers() which is returning the data in a different order.
What I did is I stored some kind of a flag(Value) in ViewState to indicate what sort order I am in and made use of that when I am binding in the Editing event, so that I can call the right method to return the same datasource.
Regards,
sbmarya
I faced this problem as well. This is how I fixed it. (In my example the gridview is sorted on a column called submit date).
a. When the underlying dataTable of the gridview is crated and sorted store it in a session variable. The trick is, before storing to a session variable make sure you store the sorted view.
dt.DefaultView.Sort = "Submit Date" + " " + "DESC";
GridView1.DataSource = dt;
GridView1.DataBind();
Session["gridViewData"] = dt.DefaultView.ToTable(); //Only storing dt will not have the sorted table stored in session.
b. next, perform all edit/update operation using the dataTable stored in session in the above step. It will always come up in proper sorted order and you will not see the issue of row index changing unexpectedly after update.

Resources