I have a ASP.NET page that contains a formview and ObjectDataSource. On the page I only have 4 fields that are bound to fields in my datasource. My datasource contains 10 fields. When I call an update it is setting the 6 fields I am not binding to to null. The only way I can find it get around this is to add hidden fields for the 6 unbound fields and bind them to the datasource.
Is there anyway around this without using hidden fields? I would think that it should only update the fields you are binding to and ignore the others.
Any suggestions?
Thanks.
The solution is to just change by hand the Update Code on the datasource of your formview.
Just remove the fields that you do not won to update. Its a simple SQL command.
Related
If I have 2 entities that share a navigation property (In my case an entity called Groups and one called Requirements) and I have a Gridview that displays Groups and another Gridview that I want to display the Requirements in the navigation property of the selected Group, should I pull in all the Requirements in the Requirements DataSource and then filter in the Gridview or should I filter in the DataSource?
I tried filtering in the Requirements DataSource by doing some Linq in the OnQueryCreated event, but I realized that OnQueryCreated is called when the page is loaded and then not again. Is there another event I should use?
Basically: Should I filter in the DataSource and if so where? If I should filter somewhere else, where?
I have an ASP.NET page with a Wizard control containing several steps and about 80 form fields. The data is collected and inserted to a database from the code behind page. I need to set this form up so you can not only insert, but edit a record as well. So I want to databind the fields. I'd rather not use a FormView because then I would have to revise my existing code, since you can't access controls inside a FormView directly. Is there a way to databind the fields without using a FormView? I'm new at this by the way so sorry if the answer should be obvious.
A wizard is just a UI control with many steps in it. You can use it to insert, edit, delete or anything else you can think of. You can have an INSERT wizard and an EDIT wizard. The difference would be that there would be two of them and that the code behind for each one (presumably on the CompletedStep) would have slightly different code to persist the data. The insert wizard would call an insert database query and the edit one would call an update query.
That being said, you can access the control inside a FormView, I'm not sure why you said that you can't access controls indie a FormView. You can. See Using FindControl: Accessing Controls in a Formview.
You could even put the two wizards inside the two states of the formview - InsertTemplate and EditTemplate but thats getting a little crazy :)
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.
ASP.NET newbie here. I would like to create a form with multiple types of controls for inserting a single record into a database table. This record has a "Type" field which is a foreign key, and I would like to populate a combobox with the possible values for it. I tried drag'n'dropping the table in design view (like in windows forms), but it always generates a gridview. How can I make it generate a form where I can specify the types of controls?
Thanks in advance
you could check detailsview and formview control.
http://quickstart.developerfusion.co.uk/QuickStart/aspnet/doc/ctrlref/data/detailsview.aspx
http://quickstart.developerfusion.co.uk/QuickStart/aspnet/doc/ctrlref/data/formview.aspx
Sounds like you either want to use a DetailsView or a FormView control.
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.