How to implement Drop Down Box that loads element on select? - c#

I'm creating a webpage and I'd like to implement a drop down list that loads a specific .jpg somewhere else on the same page when the user selects an option from aforementioned box. I'm using Visual Studio 2010 & I'm looking to implement this in pure HTML rather than CSS or C# code.. But if I have to use either of the 2 then fine.
This drop down list is filled in from a database. Just in case that matters.

Add a SelectedIndexChanged event on the drop down list and set AutoPostBack for the control to true.
In the SelectedIndexChanged event, programmatically add the image.

In addition to what user1948635 says, Yes it is through ASP and you can do this inside an UpdatePanel using the ScriptManager so that you don't have to refresh the whole page in the DropDownList's postback event and just refresh that specific part (.Net AJAX feature)

Related

Get all items from Repeater's datasource when using pagination

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

Asp.net MVC C# - DropDownList SelectedIndexChanged not firing

I have a drop down list which is being populated with data from a database using a datasource in visual studio 2010. All the values are unique and I have set up an event to carry out an action when a new value is selected. When I select a new value in the drop down list the new value is selected but the event does not fire. I put a break point in the code to see if it was being executed which was not being hit.
I read about setting the drop down lists AutoPostBack to true but all this seems to do is refresh the page and set the list back to its original selected state (possible why the event is not firing?).
I also read something about enabling the ViewState as this could cause it to not fire, I tried putting EnableViewState = "true" at the top of the View to no avail. The EnableViewState property is also set to true on the drop down list.
I would be grateful if anyone has any insight into a solution?
Thanks
With Asp.Net MVC you do not have events and postback like Asp.Net.
You should use a form tag to handle the values of your drop down, because it's a classic HTML page. If you want to handle in a async way, use javascript connected to the onchange of your dropdown
I usually find this is caused by databinding. If code in Page_Load binds the dropdownlist without checking Page.IsPostBack (Or somewhere else in the pipeline before control events are handled) that will suppress the SelectedIndexChanged event.
Another possibility is that you haven't got OnSelectedIndexChanged="DropDownListId_SelectedIndexChanged" in the decalrative markup for the control, or in the #Page directive you don't have AutoEventWireup=true.
Can you post your code?
Just seen tag and #iridio's post. Is this really MVC ? I would'nt expect to see System.Web.UI.WebControls used in an MVC app, but I am no MVC expert.

Dynamics controls lost on postback

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 need to change Multiview or place holder whenever I select different values in dropdown list

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

C# ASP.NET Collapsible Gridview

Is there a way to create a collapsible ASP.NET gridview displaying a parent child relationship based on a check box click?
An easy solution would be to wrap your GridView in an UpdatePanel, and just code everything as you would with normal postbacks. But this is a very heavy-handed approach.
Another option is to use Microsoft's AJAX Library to invoke PageMethods. See the second example here: http://www.asp.net/ajax/documentation/live/Tutorials/ExposingWebServicesToAJAXTutorial.aspx . Once the page loads, you can bind a function to the checkboxes' click events that invokes a PageMethod to inject the appropriate HTML labels and inputs into the row, with a link that passes the values from the form to a different PageMethod.
I don't think that any of the Microsoft grids can do that. However, third party grids will do this. We used ComponentArt's grid control on my last project, and used it to do exactly what you want.

Categories