Click here to Skip to main content
15,910,121 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.NET
<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:

C#
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();
        }




}
Posted
Updated 14-Feb-12 2:01am
v2

Check
This[^]
and

This[^] Link
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900