Answered by:
Data controls for a new web form page

Question
-
User-127506019 posted
In a vb.net 2010 web form application, I have a request from the user to be able to insert,update, and/or delete a row
in a single table. Thus I have the following questions to ask:
1. I am trying to decide if I should use a detailsviews, formview, gridview, and/or a different control for this purpose. Thus would you tell me what control you would recommend and why you would recommend that particular control?
2. For the different options for insert, update, and delete, would I use the buttons that are on the control that you
recommend? If not would I use, new buttons that I place on the webform page?
3. For the control that you recommend that I use, should I place the sql 'embedded' in the sqldatasource, the control
you recommend and/or access the sql from a different location(vb.net code in a new location)?
Would you tell me , show me with pictures, and/or point to me to links (urls) that will show me how to accomplish
this
Tuesday, July 12, 2016 9:52 PM
Answers
-
User283571144 posted
Hi peggy_girl,
Can you tell me how the code you just listed, to show one row in girdview you could refer to follow codes?According to my code, I used sqldatasource to bind girdview to show data from database.
We could write select command as database queries in sqldatasource to decide which record could be shown into gridview.
If the ProductID is primary key, using the code will return one record because primary key will not repeat .
SelectCommand="SELECT * FROM [Alphabetical list of products] where [ProductID]=1">
You could also use the following code:
SELECT top 1 * FROM [Alphabetical list of products]
Can you tell me how to setup the insert, delete, and update sql using the gridview control?I suggest you could refer to follow link.
Best Regards
Brando
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, July 14, 2016 10:51 AM
All replies
-
User-2010311731 posted
I would recommend a GridView for what you are trying to accomplish. If you need to develop rapidly, use the default buttons. If you have a little time and want it to look better, then you can create your own buttons and style them as you like.
A good place to start is here...
http://www.asp.net/web-forms/overview/aspnet-data-controls
Or if you are using an older version...
http://www.asp.net/web-forms/overview/data-access
Matt
Tuesday, July 12, 2016 10:10 PM -
User-127506019 posted
Why would I use a gridview control? Should I use a formview or detailsview control since this is data for a one row in a table.
How would I use a gridview control for one row in a table in a sql server database?
Wednesday, July 13, 2016 4:08 AM -
User283571144 posted
Hi peggy_girl,
I am trying to decide if I should use a detailsviews, formview, gridview, and/or a different control for this purpose. Thus would you tell me what control you would recommend and why you would recommend that particular control?AS far as I know, the differences between DetailsView,FormView,GridView ,DataList,Repeater as below:
The DetailsView : The DetailsView control renders a single record at a time as a table and provides the capability to page through multiple records, as well as to insert, update, and delete records. The DetailsView control is often used in master-detail scenarios where the selected record in a master control such as a GridView control determines the record displayed by the DetailsView control.
The FormView : It is similar to the DetailsView control, the difference between the FormView and the DetailsView controls is that the DetailsView control uses a table-based layout where each field of the data record is displayed as a row in the control. In contrast, the FormView control does not specify a pre-defined layout for displaying a record.
The GridView : it supports paging but it doesn't provide a flexible layout , since its mainly used to display the data in a table based layout. And If we looked at data inserting , the Gridview doesn't have a built in support for inserting data( since it doesn't call the insert method of it underlying data source when you click on a button with a CommadName set to "Insert" ).
The DataList : it support data grouping ( through its RepeatColumns property) , but it doesn't have a built in support for paging,inserting ,deleting , updating the data. and if you looked at its laout , you will find that by default the datalist renders as html table and you will have to set its flowLayout to "Flow" to stop that behavior.
The Repeater control : you will find that it provides a flexible layout but it doesn't support data grouping ,inserting,deleting , updating and paging through the data .
More details about Data-Bound web server controls you could refer to follow link.
https://msdn.microsoft.com/en-us/library/ms228214.aspx
I suggest you could use GridView because you could find a lot of demo about it and it's easy to be used.
2. For the different options for insert, update, and delete, would I use the buttons that are on the control that you
recommend? If not would I use, new buttons that I place on the webform page?
Gridview could do as you wish.
You could use commandfield,buttonfield or custom button for the different options about insert, update, and delete.
If you want to use commandfield you could refer to follow link:
http://www.vkinfotek.com/gridview/gridview-commandfield.html
If you want to use buttonfield you could refer to follow link:
http://www.vkinfotek.com/gridview/button-fields-gridview-control.html
If you want use custom button you could refer to follow link:
3. For the control that you recommend that I use, should I place the sql 'embedded' in the sqldatasource, the control
you recommend and/or access the sql from a different location(vb.net code in a new location)?
According to your description, I suggest you place the sql 'embedded' in the sqldatasource because it could be easily used.
More details about how to bind GridView using sqldataSource you could refer to follow link
Best Regard
Brando
Wednesday, July 13, 2016 9:37 AM -
User283571144 posted
Hi peggy_girl,
Why would I use a gridview control? Should I use a formview or detailsview control since this is data for a one row in a table.Based on my experience, gridview is a table to displays data as a table and provides the capability to sort columns, page through data, and edit or delete a single record.
Detailsview or formview control renders a single record at a time as a table and provides the capability to page through multiple records, as well as to insert, update, and delete records.
We often use gridview to show the table form the database and use Detailsview to show the details infomation about gridview's selected data.
More details you could refer to follow links:
https://msdn.microsoft.com/en-us/library/aa581796.aspx
How would I use a gridview control for one row in a table in a sql server database?As far as I know, you could select a record to bind gridview by using select command.
If the query is not based on the primary key, there may be multiple records.
More details about how to show one row in girdview you could refer to follow codes:
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="ProductID" HeaderText="ProductID" ReadOnly="True" SortExpression="ProductID" /> <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" /> <asp:BoundField DataField="SupplierID" HeaderText="SupplierID" SortExpression="SupplierID" /> <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" SortExpression="CategoryID" /> <asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit" SortExpression="QuantityPerUnit" /> <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" /> <asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" /> <asp:BoundField DataField="UnitsOnOrder" HeaderText="UnitsOnOrder" SortExpression="UnitsOnOrder" /> <asp:BoundField DataField="ReorderLevel" HeaderText="ReorderLevel" SortExpression="ReorderLevel" /> <asp:CheckBoxField DataField="Discontinued" HeaderText="Discontinued" SortExpression="Discontinued" /> <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Alphabetical list of products] where [ProductID]=1"></asp:SqlDataSource>
Best Regards
Brando
Wednesday, July 13, 2016 9:47 AM -
User-127506019 posted
Can you tell me how the code you just listed, to show one row in girdview you could refer to follow codes?
Can you tell me how to setup the insert, delete, and update sql using the gridview control?
Wednesday, July 13, 2016 8:51 PM -
User283571144 posted
Hi peggy_girl,
Can you tell me how the code you just listed, to show one row in girdview you could refer to follow codes?According to my code, I used sqldatasource to bind girdview to show data from database.
We could write select command as database queries in sqldatasource to decide which record could be shown into gridview.
If the ProductID is primary key, using the code will return one record because primary key will not repeat .
SelectCommand="SELECT * FROM [Alphabetical list of products] where [ProductID]=1">
You could also use the following code:
SELECT top 1 * FROM [Alphabetical list of products]
Can you tell me how to setup the insert, delete, and update sql using the gridview control?I suggest you could refer to follow link.
Best Regards
Brando
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, July 14, 2016 10:51 AM