简体   繁体   中英

ASP.net GridView - using dataSource - C#

I am using a showGrid in an ASP website that is linked to a dataSource (class in the business logic). the dataSource has two methods - Retrieve and Update.

When I update an item on the showGrid it automatically sends the parameters of the updated row to the method and then I use the method to update the database.

How can I return a message to the presentation logic saying that it has successfully updated? everything is done automatically and I don't even use the GridView1_RowUpdating handler and can't find how communications happen between the showGrid and dataSource.

This is how I added the method as a dataSource for the showGrid 这是我向showGrid添加数据源的方法

and this is the function that get's called

 public bool UpdateSpecificSubject(string sj_name, string sJ_descr, Int32 sj_max_enrollment_no, bool sj_avail, string sj_prerequisite_no, string sj_id)
    {
        try
        {

            SubjectsDSTableAdapters.subjectsTableAdapter subjectsAdapter1 = new SubjectsDSTableAdapters.subjectsTableAdapter();
            subjectsAdapter1.UpdateOneSubject(sj_name, sJ_descr, sj_max_enrollment_no, sj_avail, sj_id);
            subjectsAdapter1.UpdatePrerequisite(sj_prerequisite_no, sj_id);
            return true;

        }

        catch (Exception)
        {
            Console.Write("Error in connecting to Subjects table");
            return false;

        }

    }

Any help would be appreciated... Thanks!

to understand the working of grdiview and datasource, you need to go though this article

as you are binding the class so right now you only need to focus on objectdatasource

here is the MSDN article....

To get the return value from the function in your class.. kindly implement the following events Updated and Inserted of ObjectDataSource. and ObjectDataSourceStatusEventArgs event argument will return the Return value as e.ReturnValue.

  <asp:ObjectDataSource OnUpdated="ObjectDataSourceStatusEventHandler" />

I had the very same problem. What appeared to be was that you need to use the events onUpdated and Oninserted referring to the ObjectDataSource that you use in your code. The ObjectDataSourceStatusEventArgs will then return the value as e.ReturnValue.

<asp:ObjectDataSource OnUpdated="ObjectDataSourceStatusEventHandler" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM