I've got a Repeater control, bound to a PagedDataSource, which datasource is a list of custom controls I've made. These custom controls contains a couple of text boxes.
I have a save button, and when it is clicked I want to save the data in all the custom controls to a database, no matter which page they are on - but currently I only got access to the custom controls displayed on the current page.
What I've tried to do is to, in the btnSave_Click event, create a new temporary datasource equal to the current one, except its not a PagedDataSource. That way my repeater contains all custom controls - BUT - the changes made in the textbox fields are no longer available. I then tried to add JavaScript onchange events on the textboxes in the custom control, so that a postback would be fired whenever text was changed, and the property in the user control codebehind would be updated. This didnt work either.
Any ideas?
save the changed values on each page index changing event (or prev /next buttons) into your persistance object (List)
http://www.dotnetfunda.com/articles/show/1611/how-to-select-multiple-records-from-multiple-pages-of-the-gridview-and
The reason your non-PagedDataSource is empty is because the changes in your text box exist in the client and not on the server - you'll need to synchronise the values from your controls with the empty slots in your repeater.
The Repeater does not have built-in Pagination (like the GridView or other complex controls) so it does not offer events such as the PageIndexChanging event. I assume therefore, that you have your own Page navigation implementation. You should therefore call the function you have presented within that implemented function.
Try Using a generic List and Skip and Take methods of that
Related
I am creating a set of tables, dropdowns, buttons, labels dynamically on OnInit() event on the basis of list of objects( fetched from database). I have bound events with these dynamic controls as well.
On dropdowns_SelectedIndexChanged event I have to populate my list of objects again from database on the basis of selected value and recreate these tables, labels again.
First time dropdown selection is working fine for me, but as soon as I am recreating control here on dropdowns_SelectedIndexChanged, the event of dropdowns are not bound (as it is compulsory to add dynamic controls on OnInit() to bound events with them) .
Now for an alternative I am trying to get dropdown's selected value on any Page event near by pre_render() so that I could recreate my controls there with updated objects List without any dropdowns_SelectedIndexChanged event.
Any help will be appreciated. Thanks in advance.
Yes, here is one nasty way!
You can index the Request.Form["__EVENTTARGET"] that should get you what your after.
BUT I wouldn't necessarily/always recommend it. Even when adding controls dynamically you should be able to get the selected value, in the correct event handler. It's probably owing to where you are adding the control in the page lifecycle.
I have a repeater control that pulls back some data from a database and creates a radiobuttonlist for values related to each row. I don't know how many rows will be coming back, so I don't know how many radiobuttonlists there will be. This repeater is inside of a form, and once I click "Submit" on the form I need to get the values from the radiobuttons generated by the repeater.
Any thoughts on how to do this?
There are a few options.
One is to use a nested Repeater to display the RadioButtons.
The other is to create the controls during the original repeaters. Repeater.ItemDataBound event.
In either case, you need to be very aware of the Page Lifecycle.
You'll want to avoid databinding in the Page_Load event, unless the databinding is being done with an if(!Page.IsPostback) block. If you fail to check for postback, you'll run into issues where the Page_Load calls a DataBind() call that then wipes the values of the repeater before any event handlers can use it.
Alternatively, you can do your binding in Page_Init, which occurs BEFORE the viewstate can be applied, so you won't lose your values.
You can also use USer Controls for the RadioButtons. There's a previous post that covers how to use nexsted user controls within a Repeater here.
This old chestnut again.
My page is constructed as follows; I have a dropdownlist which is databound on first load. When the user selects a value from this, a postback is performed which then databinds a repeater control.
The ItemTemplate of this repeater control contains a placeholder control. In code behind in the ItemDataBound event of the repeater, I am adding two controls dynamically to this placeholder, a hiddenfield and a checkbox.
When the user clicks the save button, I then want to iterate over all those dynamically created hiddenfields and checkboxes and determine their values. However when the user clicks the save button, those controls no longer exist as shown in the page trace.
I know this is a lifecycle issue and the articles I've seen on this suggest using Init methods to dynamically create your controls but I can't because of the way my page works, e.g. the repeater control only appears and binds after a value is chosen from the dropdownlist.
What do I need to do to maintain the dynamic controls through the postback caused by clicking on the save button?
The problem is when you hit the save button probabily you dont re-bind the repeater and the controls you have added at run time withint the ItemDataBound event are not longer available(because they don't exist anymore)
Why don't you add those control at design time using the Eval function the set up the value of the hidden field?
You just don't create them dynamically just on the on selection change of the drop-down set visibility true or false for the repeater that will solve your problem.on post back you have to again create those control as they are Dynamically created.
I am creating online booking page.
I got some example page you can see in this link
http://www.parkercorporate.co.uk/webbookercc/OneForm.asp
I need the same behaviour in my site whenever user selects value in pickup dropdown list in the right side I need to change the text values or view.
To do this behaviour how should I write code in ASP.NET and c#.
Thanks
Ranam
First, use an UpdatePanel so you don't see any visual postback.
Second, set the AutoPostBack property on your DropDownList to True.
Third, handle the DropDownList's SelectedIndexChanged event. This will now fire after every change in the DropDownList, because you enabled AutoPostBack.
In the event handler, you can now change the ActiveViewIndex of the MultiView, or show/hide controls, change textboxes, etc.
First, create different blocks (i.e divs) and give ID's to them.
Then, for each value in the dropbox, fill the divs w.r.t it.
Assign "OnChange" event to the dropdown, and in the handler, set visible or invisible to corresponding block.
On the other hand, If you want to do this on client side, I strongly suggest you to use JQuery, to prevent a lot of requests going to server.
Check this out with JQuery:
make visible div on dropdown select in jquery
If you won't fetch values from database, there is nothing complex about this page. Because it just writes hospital if you choose hospital etc. and changes control's visible state.
Even if you think you need db queries when dropdown's selected change event, actually at this page there is no need. Just store db values in hidden controls (like Hospital- for Hospital) and when dropdown selection changes, write hidden's value completely in javascript
I have this GridView that have it's DataSource as a list of previously selected products.
For every item on it, I need to Eval it's ID and load a specifc form that the user must fill, then after that i've got to update the GridView.
I have made those specific forms as User Controls, is this the best approach for this scenario?
If yes, how can I dynamically load them, in a way that I can make queries/postbacks then update back my gridview?
What you want to develop is called Master/Detail view.
It is described for example in http://www.asp.net/data-access/tutorials/master-detail-using-a-selectable-master-gridview-with-a-details-detailview-cs .
The only difference that as Detail you need use FormView, where on some initialization event (like DataBound http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basedataboundcontrol.databound.aspx )you need to dynamically create you control and set its parent to current template of FormView