Gridview更新和使用ObjectDataSource删除

问题描述:



我是金奈的阿伦.我已经用objectdatasource创建了一个gridview.
页面索引,编辑,取消编辑工作正常,但我不知道如何使用Update&删除.

我输入的更新命令为
更新位置集惯例= @ practice,location = @ location,其中sno = @ sno

但是如何在代码文件中声明它却很令人困惑.

请帮帮我.

谢谢.

Default.aspx:

Hi,

This is Arun from Chennai. I ve created a gridview with objectdatasource.
Page Indexing, Edit, CancelEdit are working fine but I dont know how to go further with Update & Delete.

I entered update command as
Update location set practice=@practice,location=@location where sno=@sno

but quite confusing how to declate it in the Code File.

Please help me out.

Thanks.

Default.aspx:

<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="5"
EnableSortingAndPagingCallbacks="False"  AutoGenerateColumns="true" AutoGenerateEditButton="True"
OnPageIndexChanging="gvpageindex"
OnRowEditing="gvrowediting"
OnRowUpdating="gvrowupdating"
OnRowCancelingEdit="gvrowcanceling" >
</asp:GridView>



Default.aspx.cs:



Default.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using DataSet1TableAdapters;


    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        LocationTableAdapter ds1 = new LocationTableAdapter();

        protected void Button1_Click(object sender, EventArgs e)
        {
            GridView1.DataSource = ds1.GetData();
            GridView1.DataBind();
        }

        protected void gvpageindex(object sender, GridViewPageEventArgs e)
        {
            
            GridView1.PageIndex = e.NewPageIndex;
            GridView1.DataSource = ds1.GetData();
            GridView1.DataBind();
        
        }

        protected void gvrowediting(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            GridView1.DataSource = ds1.GetData();
            GridView1.DataBind();
        }

        protected void gvrowupdating(object sender, GridViewUpdateEventArgs e)
        {
            
        }

        protected void gvrowcanceling(object sender, GridViewCancelEditEventArgs e)
        {
            GridView1.EditIndex = -1;
            GridView1.DataSource = ds1.GetData();
            GridView1.DataBind();
        }




}

检查
[ ^ ]


[
Check
This[^]
and

This[^] Link


查看 ^ ]