I am trying to synchronise the selectedvalue of a combobox when navigating through records. Setting the combobox.selectedvalue doesn't work. I have tried refreshing the combobox but that doesn't work either. The combobox is databound.
If your ComboBox is data-bound (i.e. you've properly set its DataSource property), then you also need to make sure its DisplayMember and ValueMember properties are set to the correct fields.
Related
I am using ArrayCollection as the dataprovider to my datagrid and retrieving the information from MySQL using JSP and adding them to the ArrayCollection. I would like to transfer the selected item from one datagrid to other datagrid by changing the status of the file. As of know, am able to do this fine but I need to refresh the webpage manually for the updated results in both the datagrids.
I tried to do the following thing : dataGrid.invalidateDisplayList()
I called this method on both the datagrid's but it's not refreshing the datagrid, I still need to refresh my webpage for the updated results. Any ideas or suggestions would be greatly appreciated.
There is no need to refresh the DataGrid.
Just make your ArrayCollection variable Bindable which is your dataprovider of DataGrid.
So, whenever you will make a change in your dataprovider(ArrayCollection) and it will be reflected on your DataGrid automatically.
I have a Listbox in a PivotItem, as well as a ListBox in a Grid which is normally collapsed. Both ListBoxes have their ItemSource and SelectedItem properties bound to a view model. I put a breakpoint on the getters and setters of the ViewModel properties and noticed that they get called even if the bound controls are not visible or collapsed. Is it possible to have the binding only active when the bound control can be interacted with?
Only if you want to write code to unbind and rebind it. Not possible with pure markup.
I'm using an ObjectDataSource and a FormView.
In the FormView I have a set of controls. When the FormView is in edition, I have in particular a ComboBox and a TextBox which are related as follows:
when the ComboBox takes some special values, the TextBox must be read only or not.
For the moment I get that behaviour as follows: the ComboBox triggers a postback when its selected item is changed and in the 'OnPreRender' of my page I get the value of the ComboBox and update the Readonly property of the TextBox accordingly.
What I don't like with this method is that I don't use my object model which is consumed by the ObjectDataSource. The problem is simply that when the FormView is in edition there does not seem to be a way to get the instance of the object which is being edited. The 'DataItem' is null and I haven't found any way to automatically build a new object from the values in the controls to pass it to my business layer. Of course I could do the whole job myself by getting explicitly all the values in the controls, but that's not nice.
Has anybody ever met such a scenario ? Any ideas on how to get a clean design ?
How about using DataItemIndex or DataKey? I would probably use DataKey and then use the business method to look up for the object for the key.
Depending on the case, I'd like to hide a databound control in a page. But no matter what I try, it seems like the control will try biding no matter what. I've tried setting Visible="false", but it would still try to bind. I've tried putting the control into a placeholder and then hide the placeholder, it will try to bind anyway. I've also tried putting it into a MultiView, same thing. You would think that in a wizard interface using a MultiView you would not want the controls in the next steps of the wizard to bind, but no. It binds anyway...
The only way I've found is to unset and set the DataSourceID property which seems to prevent binding.
Is this really the only option?
Thank you.
I think that you are on a good path. Do not set the data source id. When it comes time to display the data (which I presume is triggered by a user click), explicitly databind your control.
when you set the datasourceid on your control, then the asp.net framework will automatically data bind when the page's OnDataBind event occurs.
Could it be that you're using a datasource control to bind to? The DataSourceID property being set indicates so. If you don't want it to bind to such a control you can opt to take out the DataSourceID property in markup and explicitely set it in codebehind only when you need it.
I am updating an existing ASP .NET site. This site has a custom grid control class that extends the GridView control to add a few features. Many pages in the site use the built in declarative two-way binding feature that is built into the base GridView, i.e. column templates make calls to Bind() so that data can be shown and updated automatically. This works fine in most cases. However, when binding DropDownList controls there is now a problem.
Recently I had to add a feature that allows records in some tables to be marked as 'Closed', i.e. they can no longer be referenced by new records being inserted into other tables.
When editing a data grid row that has a DropDownList of child records that can be closed, the SelectedValue property might be bound to an ID that does not exist in the list. This causes an ArgumentOutOfRange exception to be thrown. I just want the DropDownList to default to no selection if the record is closed and therefore not in the list.
I'm looking for the easiest way to solve this. If possible I don't want to have to make a lot of changes to existing code.
I can programmatically set the selected index of the DropDownList in the RowDataBound event. But I can't find a way of updating the value whilst keeping the existing update functionality.
The actual question:
Is there some way to extend the DropDownList to make it ignore invalid values for the SelectedValue property? The only example I have seen so far does not work. I think that the DropDownList caches the value in case it has not yet had its DataSource property set, so overriding the SelectedValue property is not sufficient.
Alternatively, if there is a way to use the OnRowUpdating event to manually add the data to the update then that would be OK. I have tried adding values to the NewValues dictionary on the GridViewUpdateEventArgs class but it doesn't seem to work. Note that the grids are bound to lists of objects, not DataSourceControl derived controls.
Any help would be appreciated. Thanks.
If anyone's interested, I think I solved this by overriding the PerformDataBinding method and catching the ArgumentOutOfRangeException there. I suspect that the SelectedValue property might need to be overridden as well if the order in which the two properties are bound can vary.