ASPX templates
Version 7.x > ASPX templates > Get ItemID after inserting record into Custom Table View modes: 
User avatar
Member
Member
cvillard-gmail - 3/27/2013 9:13:57 AM
   
Get ItemID after inserting record into Custom Table
Hello!

I am new and working with Kentico custom tables and a custom control I am creating. What I am doing is creating a class that logs very specific user activity so it requires a custom control.

My questions is, after I use the .Insert() function to create my record, I need to be able to get the newly created ItemID and pass it along to another function. I did not see anything in the custom table code in the API examples.

Any ideas?

Charlie

User avatar
Kentico Support
Kentico Support
kentico_filipl - 3/28/2013 3:29:15 AM
   
RE:Get ItemID after inserting record into Custom Table
Hello Charlie,

You can get ItemID of the newly created item of the custom table just by accessing ItemID property. If you have already looked at API example in Developer's Guide, it could look like this for the example mentioned there:
// Creates new custom table item
CustomTableItem newCustomTableItem = CustomTableItem.New(customTableClassName, customTableProvider);

// Sets the ItemText field value
newCustomTableItem.SetValue("ItemText", "New text");

// Inserts the custom table item into database
newCustomTableItem.Insert();

TextBoxItemID.Text = "ItemID: " + newCustomTableItem.ItemID.ToString();

Best regards,
Filip Ligac

User avatar
Member
Member
charlie v - 4/4/2013 7:54:59 AM
   
RE:Get ItemID after inserting record into Custom Table
Thanks much, that worked!