In GridView, the Edit/Update/Delete feature is an inbuilt one and can be achieved without writing a line of code with the help of DataSource controls. Likewise, the ListView control also have inbuilt Edit/Update/Delete feature and additionally, insert feature is also introduced as an inbuilt one.
Edit/Update/Delete/Insert feature using DataSource controls
Configuring SqlDataSource Control
Drag a SqlDataSource control from the data tab of Visual Studio 2008. Configure it with the Database Server; I have used a database in App_Data folder. To configure the DataSource control to handle insert, update and delete click “Advanced...” button. Refer the below snapshot.
Check the “Generate Insert, Update and Delete statements as shown in below figure. Click OK.
Configuring ListView Control
Drag a ListView control from the data tab of Visual Studio 2008. Click the Smart tag of ListView control and select the datasource control; Refer the below figure, SqlDataSource1 in our example.
Click “Configure ListView...” option as seen in the above figure to choose the display Layout for the ListView. Choose a display layout, I have selected “Grid” in our example, as seen in the below figure. Click Ok.
You can check “Enable Paging”, which will add a DataPager control in the LayoutTemplate of the ListView control. Read my previous article onPaging in ListView to understand more.
The insert item position can be configured as a LastItem or FirstItem using InsertItemPosition property of ListView control. Executing the page will give you an output similar to the below figure. In the below output, I have added paging feature using DataPager control.
if you use dropdown in your insertert template then to passvalue to parameter use below code
Not working:Try manually editing your SqlDataSource1 to make it use your DDL as a parameter with something like:
Fix:
protected void ListView2_OnItemInserting(object sender, EventArgs e)
{
string sv = ((DropDownList)ListView2.InsertItem.FindControl("DropDownList2")).SelectedValue;
SqlDataSource31.InsertParameters.Add("Parameteridforinsert", sv);
}
|
0 comments:
Post a Comment