I am creating a SqlDataSource connected to a stored procedure that needs parameters. I have connected my SqlDataSource to a ASP.NET devexpress grid and would like to use a combo box drop down from the grid to be the parameter to the SQLDataSource Parameter source Control. I can see other controls in the list but not any from the grid.
How can I get a Combo Drop down to be the control for the parameter? I am using VB.Net
Select the required ASPxComboBox control from the ControlID list and ASPxComboBox.Value property as PropertyName:
Tutorial 5: Declarative Parameters
Take a look at the following samples, which may be helpful:
E2040
E2041
Related
I have changed the DefaultMode property of my details view to Insert since I wanted to create default insert form for my sql server table. Now I wish to add the validators, like RequiredFieldValidator,RegularExpressionValidator etc.
So is that possible? If not, then is there a shortcut way to create an Insert form for a database table in Asp.net like SQLFORM in python framework web2py(refer here)?
Convert all boundfields to TemplateField, open EditItemTemplate of each TemplateField to add validation controls.
I am confused about something really simple in ASP.NET. I have seen many times a pattern where there is a three column table, with label, control and validator in each column, which I can put together pretty straightforwardly. However, what I don't understand is how to handle binding here. If I have a table with Customer record and FirstName, LastName and PhoneNum, I want a page that takes customerId in the query string, and binds that record to the page so that I can use Bind() as the text box values.
However, there is no DataSource property on the page to bind the record to. I know I am missing something obvious, but I can't figure it out.
Any help would be appreciated.
You need to put your controls (labels, textboxes, validators) inside a control that accepts data binding (ie. FormView, GridView, Repeater, etc.etc.) and then bind your data to that control.
One way to do this is to use a DataSource Control such as a SqlDataSource and use it in conjunction with a Data Control that will bind to the previous datasource control like a DetailsView. Then you configure your DataSource control to only bring in data for the particular CustomerId; the SqlDataSource allows you to use a QueryStringParameter as part of the select statement to the database.
Each of the above controls have wizards that will allow you to easily configure them.
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.
I have to maintain an ASP.net application in VB.Net.
There is a page with a FormView bound to a ObjectDataSource.
I have to add some business logic on the ItemUpdating event of this FormView.
Unfortunately, some the data that I need to add this business logic is not exposed on the FormView user-interface itself, so I can not use FindControl to get the values (I could add the controls, bind them to the fields I need and set their visible property to true, but that's ugly).
So, what I would need to do is to get access to the Data Row corresponding to the currently selected item in the FormView from the code behind as it has the data I need to add my business logic code.
Unfortunately, I don't manage to get access to the row.
Thanks in advance for your help.
Try this:
Dim myData As Object = DirectCast(formview1.DataItem, DataRowView)("MyColumn")
EDIT:
If I remember correctly the DataItem is Nothing on ItemUpdating so my solution above does not work, does it? Then you have to load it from your Datasource with the given ID(CommandArgument).
Thanks, I managed to sort it using the Select method of the ObjectDataSource object.
This returned me a DataView containing the row that was currently being edited.
I have a form that contains a GridView control which is databound to an ObjectDataSource Control. There are several TextBox controls that are already being used as ControlParameters for the ObjectDataSource. I also have a custom data object that the ObjectDataSource is associated with {TypeName="myDataClass"}. The values are passed from the ObjectDataSource to myDataClass.
Now I need to also use a multi-select ListBox as a ControlParameter. When I use the SelectedValue parameter of the ListBox, the ObjectDataSource is only seeing the first selected item in the list.
Here's the question: How can I get all the multi-select ListBox values passed into my custom object "myDataClass" instead of just the first one selected? Hence the ["multi-select"]
Thanks for any help!
Multi-select list boxes are tricky. You need to loop through the items in code to build a list of selected values. So you will probably need to implement a custom parameter that does this for you.
You might end up needing to bind to the grid from code-behind, instead of doing it declaratively.
This is typical problem. multi-select list box always return the first selected value and not all the selected value. We have to loop through the entire collection and check each individual value if selected or not.