I'm looking to create a form that will always be in edit mode but I will need to bind to several tables. I want to display this as a cohesive page. I want to use databinding if possible and write as little code.
What are my options? Basically the FormView looked like a candidate but I don't want the edit buttons. I'll have 3 or 4 tables displayed on one page and I want a single button to submit it.
I know I could create a form and populate it manually but that seems like I may be doing more work then required.
FormView is the right way to go. It is very customizable and you can change the layout by using custom templates. It also allows hiding the edit buttons you are talking about. Put some time learning that control and you will get what you want!
Stay with the FormView; just set the DefaultMode="Edit"
Related
I manage a project and as you know asp.net has many types of data control, I am confused which control should be used in what condition. Which is better control in what situation. Should I still use repeater control because grid view is advance control.
A repeater allows you to have your items repeated both horizontally and vertically unlike a GridView which only by default repeat the items vertically.
The best way to understand the two is if you need a simple grid displayed use a gridview.
If you need to do additional formatting or display data from the database with additional graphics, labels, not in a grid type form than use a repeater. You can easily adjust the repeater to by as dynamic as you need it to be where as a grid view is a simple grid.
With a repeater you will click on the page SOURCE of the .Cs or .vb file and you will see 4 templates. Anything HTML you put in those templates will repeat with the data.
Around 2010 I ran into so much trouble with the GridView, I asked a (now former) Microsoft evangelist for advice. He strongly recommended not to use the GridView ever. Then I stopped and life got easier.
Please excuse me for a probably low quality of this question, since I'm not a web dev, so I possibly don't now some obvious things and don't know what to Google for. I think problem must have some simple solution, but I'm struggling with it for two days now, so I feel myself pretty stupid :-).
I have a custom control which is a set of checkboxes which are added dynamically based on a property which is set in OnLoad event of a page. I have two such controls on a page and second control items should be based on items selected in first control.
The problem is, I can't figure out, how to catch on autopostback which boxes were selected in first control before second contol is constructed to pass this data to it?
Take a look at this.
http://forums.asp.net/t/1440174.aspx
Since your building them dynamically, they are not as easy to find as webforms would like to be, if you added them to the page and wired up events and such.
Your going to look at the Request.Forms list, and search thru it for any controls you want.
I believe checkboxes are like radio buttons, they only return if they are checked, which is good, cause you want to know which ones were checked.
I've used same solution as in the accepted answer for this question: Dynamically Change User Control in ASP.Net , just need to assign an unique id for each dynamically created CheckBox in custom control. Not as clean solution as I want but at least it works.
You can save the data in the ViewState, QueryString or as Session before moving to the next page and you can do modifications based on it.
I have an ASP.NET page with a Wizard control containing several pages of 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. Since the form is long and complex, I would rather use the existing one and not make a duplicate one for editing, especially since I want to keep both forms exactly the same and any edits would have to be made to both. But it looks like this is what I need to do if I'm going to databind it. But this would also involve putting the Wizard inside of a FormView, and then I'd have to use FindControl to access any of the fields which would mean altering all my already-existing code (which of course would be time-consuming). So should I manually enter all the values from the code behind instead of databinding it? Which is better, to use a FormView and have duplicate forms (plus have to go in and redo the way I access the fields), or to do everything from the code behind?
I cheat in this circumstance. :)
Create each screen as 2 separate user controls
One for edit, and one for view
Then you get access to all you usual coding
Then embed the controls into the Wizard/FormView
I would suggest you to Go Ahead using FormView, as using DataBind control you have more control the functionality and layout Insert/Edit/View template. Since you have specified that your form is very complex and long, if you control from code behind you have to do lot of work to handle this in code behind and lot code required.
Since I have personal experience to develope very complex form using FormView and it was easy for me bind the Value in directly in formview instead if you assign/Get Values of each conrol in code behind and sometimes you have to hide.
I'm writing an ASP.NET app in which a table of objects is created by the user client-side.
I envisage them clicking "Add item" and a new 'row' is created in the table with textboxes for them to enter their stuff.
I can do this fine by adding HTML with jQuery. The problem is that one of the fields in the row for the user to fill in needs to be a colour picker.
I have an ASP.NET web user control for my colour picker. How do I add an instance of it to the page within my html row? Or am I barking up the wrong tree here - is there a better way of encapsulating the functionality of my colour picker so that it can be put on every row?
No, you can't add a server-side asp.net control to a page that has already been rendered using client-side techniques (aka Javascript)
Two options:
Firstly, switch to using a client-side colour picker. You can then have the data from this included in the post-back by dynamically adding hidden fields to your form.
Secondly, have a single editing panel which includes your colour picker. Users then select a row to edit, which updates the edit panel with current values etc. Values are stored in hidden fields created when you dynamicaly add rows to your table, and included in the post-back
Without seeing your UI, I can't comment as to which would be best. The asp.net control might look nicer, but it might be difficult to work into your design. A pure client-side solution might fit your designer better, but might not look so good. You also need to consider what happens if / when a users adds lots of rows (this might be 10, 50 or 100 depending on your app /code). Lots of dynamically added controls (the first solution) might cripple the performance of the page.
I'm not sure what version of ASP.NET you're using, one approach that would work is to turn your usercontrol into a custom control. You'd then need to implement ICallbackEventHandler (the first way to do Ajax on asp.net); for sure it's a bit more work but it does give you a good level of control.
Alternatively, you could try this
You can't add ASP.NET controls with jQuery (at least not easily). You could, however, perform a postback when you need to add the colour picker to the row.
In the code in front declaratively define a template of what the new row should look like, then hide it using css.
When the user clicks the 'Add new button' select and cloen the contents of your hidden template and write that into your target div. Just make sure to remove the hiding css when you do this.
You will, of course, just be copying the rednered html of your server controls, but htis apporach may give you a quick and easy way of doing what you need
I am using ASP.Net 2.0. I am using a gridview component over some data because I wanted to get the paging functionality it provides. The rest of my site where I do not need to provide paging because I have used an alphabetical index or because the result set is small enough to fit in the screen I use a repeater. In the repeater I have added the delete shortcut to the end of the table in its own cell. The edit link is provided by clicking on any row in the results and that takes you to a new screen where you can edit the details.
I have not been able to find a way to move the edit and delete columns to the end. Is there perhaps a property that I missed or is the easiest way of doing this going to be extending the Gridview component. If that is the case would it better to extend the component or try and write my own paging functionality to acompany my repeater.
Rather than using the autogenerate delete and edit buttons, you can manually add an edit and delete field using the 'Edit Columns' dialogue from the gridView smart tag. Make sure that Auto Generate fields is not selected and you can then add your columns as desired, and edit, delete and insert are all available as children of the CommandField option.
The best solution of them all would be to get the paging capablilities into your data access solution, so that if you need page 3 you only get those ten records and not the entire list. That way you could also use a repeater to render the list, without having to extend it with paging capabilities - just add another repeater at the bottom that loops out the page numbers as links.
However, if this is not possible, the easiest way would probably be to manually configure the GridView to render the way you want it to (or as close as possible...). It's been a while since I worked with a GridView, but the names I show below are at least close enough for you to find the correct ones with Intellisense in VS.
First, set
AutoGenerateColumns = False
on your GridView. Then, add a <Columns></Columns> section betweeen the <asp:GridView></asp:GridView> tags. Within that section, you should be able to specify each field you want to render, and the order you want them in.