Drop in control to edit a table - asp.net

Is there a control I can just drop on a page, and link it to a sql server table that will then list all the rows in the table and let me edit any of the columns?
Also the ability to add, delete rows.

You can use asp.net dynamic data, it generates a CRUD interface for your tables.
read more
http://www.asp.net/web-forms/videos/aspnet-dynamic-data/getting-started-with-dynamic-data
http://msdn.microsoft.com/en-us/library/ee845452(v=vs.100).aspx

Have a look at the SqlDataSource control. You can set the connection via ConnectionString property, and also utilize the DeleteCommand and InsertCommand properties.
Using a GridView, you can then set the DataSourceID to the ID of your SqlDataSource

Related

ASP.NET Gridview SQL Datasource

I am setting up a Gridview to display data from a SQL database. I know I can set it up in the aspx page or in the code behind. Is there a best practice to follow on deciding the best approach? Do you normally set it up in the code behind?
The SqlDataSource control is a server control just like the GridView control is, so to answer your question there really is no "better" (declaratively only versus imperatively only) way to use server controls.
The few times I have used the SqlDataSource control, I have always declared the control in the markup and set the properties for the data retrieval inside of the markup as well.
Reality usually dictates that you will declare your server controls in your markup for both the GridView and the SqlDataSource and then apply/update the properties of the server controls in your code behind, but probably you will write more code-behind for a GridView than a SqlDataSource, because the GridView needs to react to events on the rows within the grid. If you do not have any dynamic queries, then most of the time your SqlDataSource will have static queries that can be applied in the markup (decaratively).

Validators in DetailsView insert mode

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.

How do I access foreign table data within a repeater

I have my Items table bound to the repeater control. What if I want to display data from another table that is related to this one?
I'm using LINQ to SQL as the datasource in the codebehind.
In the repeater itemDataBound event get any data you need with LINQ and display what you need.

Bind to a page in ASP.NET

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 multiple types of controls to insert a record

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.

Resources