开发者

How to get a returned value of an insert function called by asp:ObjectDataSource

I'm using an asp:ObjectDatasource to handle an insert (done through Linq to SQL) to my SQL database. The insert function returns an integer.

My problem is that how could I get the returned value of the function. Should I manually call the insert function through code behind or could I get it from the asp:ObjectDataSource as a key/value pair like how I send data through the asp:ObjectDataSource for the insert function to use?

Here's the insert function code:

public static int InsertSpotlightList(string spotlight_list_name)
        {
            ALI_DBDataContext ctx = new ALI_DBDataContext();

            DAL.Plugin_Spotlight_List temp_spotlight_list = new Plugin_Spotlight_List();
            temp_spotlight_list.Spotlight_List_Name = spotlight_list_name;
            temp_spotlight_list.Spotlight_List_IsDeleted = false;
            temp_spotlight_list.Spotlight_List_ForMall = false;

            try { 
                ctx.Plugin_Spotlight_Lists.InsertOnSubmit(temp_spotlight_list);
                ctx.SubmitChanges();
            }
            catch(Exception ex) {  }

            开发者_运维百科return temp_spotlight_list.Spotlight_List_Id;
        }


Found the answer, you need to use: the OnInserted event of the asp:ObjectDataSource.

Here's an example:

protected void ObjDS_OnInserted(object sender, ObjectDataSourceStatusEventArgs e)
{
    var ret_val = e.ReturnValue;
}

Sorry for the trouble. Should've researched more until I really can't think of a solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜