How to get auto-increment column value back into webgrid after insert?

3 replies. Last post: October 16, 2012 10:01 PM by Bernard Xiang
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback

Hi,

WebUI Studio 2009 R2

I have a webgrid bound to a ISDataSource (ISD). The ISD has SchemaType="CustomObject" and InsertMethod="InsertComment". That inserts into a database table called "commnts" with it's primary key as id_comment as autoincrement.

The InsertComment method calls a Stored Procedure in the database that inserts a comment record and returnes the newly inserted id_comment.

Now I have to somehow get that returned id_comment into the new webgrid row. So I tried setting the  oninserted="ISDataSource1_Inserted" for the ISD:

 protected void ISDataSource1_Inserted(object sender,
                                       ISNet.WebUI.DataSource.ISDataSourceStatusEventArgs e)
{
   c_webGrid.RootTable.UpdateRowIdentity("idComment", "-1", e.ReturnValue);
}

 I notice that "e.ReturnValue" is returning the correct newly inserted id_comment, but this call does unfortunately not update the column of the new row in the grid. 
I have also tried using the "DataMember" instead:

c_webGrid.RootTable.UpdateRowIdentity("id_comment", "-1", e.ReturnValue);

But that does not help either.

Where can I put in the returned auto-increment id_comment to the web grid column of the newly inserted row, after insert?

If it helps the SelectMethod of the ISD returns a DataTable from the custom object, one of the columns of the DataTable is id_comment and I have tried to play with all that stuff:

var c = tbl.Columns.Add(Consts.Columns.IdComment, typeof (int));
/*c.AutoIncrement = true;
c.AutoIncrementSeed = 0;
c.AutoIncrementStep = 1;
c.AllowDBNull = false;*/
c.Unique = true;
DataColumn[] pk = new DataColumn[1];
pk[0] = c;
tbl.PrimaryKey = pk;

 But it did not help.

In the webgrid I specify:

<RootTable Caption="tblComments" DataKeyField="id_comment">                         
  <Columns>
    <ISWebGrid:WebGridColumn Caption="ID" 
     DataMember="id_comment" 
     DataType="System.Int32" 
     Name="idComment" 
     EditType="NoEdit" 
     IsAutoIncrement="true" 
     Visible="true" >
     <HeaderStyle HorizontalAlign="Center" />
     <CellStyle HorizontalAlign="Right" />
   </ISWebGrid:WebGridColumn>
   ...
                        

 

Regards

  TJ


All times are GMT -5. The time now is 9:12 AM.
Previous Next