Why is my dynamically created asp:table retaining information on Postback? - asp.net

I have a cart page.
The top lines are the products.
Then the Subtotal, Shipping, discount, Total lines.
Obviously this is all dynamic.
I call the exact same LoadTable() Sub in my Page_LoadComplete event.
First time around it looks great.
But if I edit the data and postback then it goes crazy:
If I remove a product, and the result is that my table is 1 row shorter.
The last row of the table, instead of showing "TOTAL" and the total amount, it displays what was in the row before the postback (ie. repeating the line before it).
The table is loaded into asp:panel and the beginning of my Sub starts with:
pnlCurrentOrder.Controls.Clear()
Dim tblCurrentOrder As Table = New Table()
tblCurrentOrder.Rows.Clear()
I have given the Totals Row and cells IDs and when I look at the source, they do have the correct ID information, but they have the wrong data in the cells.
This is very strange to me, Does anyone know whats going on?
Thanks

Try EnableViewState="false" on your table, to make it not remember the previous values.

Related

ASPXGridView (devexpress) Hyperlink column sorting

I have a DevExpress ASPx GridView control and am trying to implement sorting for the grid columns.
The gridView contains has integer values in one column, text in the rest. I also have a column which contains hyperlinks and is added through the code behind during run time.
I am using the Aspxgrid_CustomColumnSort event for sorting the grid.
I can achieve the sorting for the column which contains the integer values and texts successfully, however the same code is not working for the column with hyperlinks.
When I click on the column header the hyperlinks sorts in ascending order,
but when I click the header the second time the grid isnt getting sorted in the descending order, the hyperlinks are sorted in randomn order ( neither ascending nor descending)
And, further clicks on the header do not do anything.
Any advice/suggestion will be greatly appreciated.
Maybe this link will help: http://www.devexpress.com/Support/Center/p/B145444.aspx. In this page, someone had reported an issue using the GridViewDataHyperLinkColumn.

RDLC report footer with value from "Current Record"

I don't know if its possible or not, but thought I'd ask. Many times reports need data grouping to have anchored to the bottom of the report some summary information, such as invoices. You don't want the totals shifting UPwards based on only 2 detail lines vs another with 20. I've tried working with using the Tablix bound to the data source for the output but couldn't get it quite right... It would either shift up, or force break and appear at top of following page.
So, if anyone has some ideas to help resolve that, that too would be great.
My second approach was to just use a simple report page footer. However, the overall "Report" page is not technically "BOUND" to any datasource. So, if I put a textbox in the footer and want it to show something, I can't pick "the most recent row from the datasource associated with the Tablix", it always requires an aggregate, such as
=First(Fields!SomeField.Value, "SomeDataSource" )
=Sum( ...
=Last( ...
etc...
I just want it to have whatever was the most recent... so I tried to use report variables to create one and was thinking to have it get updated per row being processed, so it always had whatever the "latest" value was and I could just dump that value at the bottom of the report.
Any suggestions to either would be great. Thanks.
I know this is an old question, but I had a very similar problem and came up with a unique solution. I had a statement that needed to have the payment slip print at the bottom of the page even if the statement line items wrapped over to another page. I solved it by:
Making all rows in the report a uniform height.
Calculating how many rows were required to fill the page (minus the height of my payment slip.
Getting the number of line items in the statement.
Calculating the remaining number of rows needed to push my payment slip to the bottom of the page.
Adding a sub-report with the calculated number of blank rows to pad out the necessary space between the line items and the payment slip.
The advantage of that approach was that I could generate bills for multiple customers, and since the padding is part of the group it would be customized for each customer's bill and bottom-justify the pay slip for each of them.
You can use a similar approach to push your "footer" info to the bottom of your page. Since it is still inside of your data group you'll have access to the data values you need as well.
In the footer you can refer to report item from report body, like this:
=ReportItems!myFooterValueTextBox.Value
The catch is that you can refer to only one report item in your footer, so you may need to add invisible footer row in your table and concatenate all your totals into one cell (myFooterValueTextBox) in that row:
=First(Fields!SomeField.Value, "SomeDataSource") + "|" +
Sum(...) + "|" + .... +
Last(...)
I used pipe as deliminator in my example, so then in the footer, I would split the string and place values in appropriate containers, like this:
=Split(ReportItems!myFooterValueTextBox.Value,"|")(0)

Bound DropDownList of "unused" items plus current row item in EditItemTemplate of GridView?

I have 2 tables with unique IDs that can be mapped to each other (one table comes from a database outside of my application but has information about the same entities I'm tracking). I want to provide a UI for linking "my" records with the "other" ones, so I can store the "other" IDs in my table for the matching records. In a nutshell, the key UI element is a dropdownlist showing the available (ie, not-yet-linked) records from the "other" table.
I have a gridview for displaying "my" records in each row, plus a column showing some info from the linked record in the "other" table, if any. The data are about buildings and properties, so it might look like this:
Building1 Dallas TX Building1_Dallas_TX
Building2 Memphis TN Bldg2_Memphis_TN
Building3 Denver CO
Building4 Seattle WA
Building5 Boston MA Building5_Boston_MA
where the first 3 columns show some information from "my" table, and the last one shows the matching record from the "other" table, where the records have already been linked, else a blank where no link has been established. My actual gridview has several more columns from "my" table, but this is enough to illustrate the need.
When Edit (not shown) is clicked for a row, I want to be able to edit all 4 columns. The first 3 are textboxes; the last column should be a dropdownlist showing all of the unlinked records from the "other" table, plus an "Unassigned" option (as the first item in the list) so records can be "unlinked" or simply left unassigned, plus (for those rows that already have a link established) the linked item (it's "used" but it needs to be in there so they can continue to use it).
I can populate the dropdownlist correctly in code-behind in the gridview RowEditing event (except for the Unassigned item which I add as a ListItem in .aspx with the AppendDataBoundItems option set to true), and I can set the correct SelectedValue on the ddl's DataBound event, but on postback when I click to Update the row, the ddl has no items in it anymore (except for the Unassigned item) so the link is always cleared. If I set a link manually by directly editing my table, everything looks fine going into Edit mode -- the ddl has the correct items in it and it pre-selects the correct item, but all is lost on the Update postback. I have tried re-binding the ddl at various stages of the page cycle but clearly I don't quite understand that cycle well enough yet because I cannot figure out how to get the user-selected item to update my table.
I've also tried populating the ddl with a SqlDataSource SelectCommand, but have had no luck including the ID of currently-linked records in the other database (even though it's available in "my" table and I set it as a GridView DataKey and add it as a ControlParameter in the SelectParameters for the SqlDataSource. Without the currently-linked record in the ddl item list, I can't keep existing links.
I'll hold off sending a code sample for now -- this message is already too long! -- in hopes that the solution is obvious from what I've described... I don't think my aim is weird, but I'm open to being persuaded otherwise.
Many thanks in advance!
Chris
Ok, I'm not going into details with code because maybe you already done what I'm about to suggest.
For the last column, the drop down list, you have to execute an SQL statement to grab you the unlinked items. Use the "WHERE xx NOT IN". For the "Unassigned" option, just add an item to the list in the same code scope as above.
Next step is to handle the GridView's editing events manually. Insert, Update and Delete.
I think that way you won't have problems.

How to get proper row index values of grid view after sorting

I have an asp.net application in which I am using a grid view. Paging and sorting are applied to the grid view. One action what I am doing is on click of any grid view row, am getting the column values of the selected row and redirecting to the other page.
The problem is after the grid view is sorted, if I click on any of the row in ayy page (paging index), am getting only first page values even though the visible row is different.
I am getting the row values in gridview_rowcreated() method and putting in some variable. In sorting scenario, before sorting is done, the gridview_rowcreated() method is called but not after the sorting is done.
In case you still need an answer to this...
You should be using the gridview's SelectedIndexChanging event with something like the following:
gridView.Rows.Item(intNewIndex).Cells(# of column, zero-based).Text
This will give each cell's current value, you'll just have to loop through each cell and assign each cell's value to desired variable(s).
Hope this helps!!!

Apply an ID to a GridView

Before you say it, I'm perfectly aware that a data repeater could do it, but I'm looking for the solution using a GridView.
I'm implementing a jQuery feature and require unique ID's to be applied to individual rows in order to respond to click events in the correct manner. I can't see how you're supposed to apply values to an ID or a row.
Basically I'm looking at doing something along the lines of
$('tr').click(function() {
// get the ID of the tr and redirect the page based on that
});
EDIT: Oh, and I can do it for a row cell if that's the value I want to pass as the query string, however, I don't want to do that as it'd mean displaying a unique identifier which is something the user shouldn't be able to see.
Okay, I didn't expect to actually solve my own question. Just for reference, here it is:
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.ID = e.Row.DataItem("Issue_Key")
End If
which is placed in the RowDataBound event.

Resources