rejnev rejnev - 2 months ago 26
C# Question

DotNetNuke how to add Tab programmatically with null parentId

With below codes I can add new Tabs in DotNetNuke with TabController class.

TabController.AddTab(...) method takes a TabInfo object.

My problem is I want to set the ParentId of the new tabInfo to null, but its not nullable int.

here is my code:

TabInfo newTab=new TabInfo();
newTab.PortalId=PortalId;
newTab.Title="some title";
/*...*/
newTab.ParentId=0 /*--here is my problem--*/

TabController controller = new TabController();
controller.AddTab(newTab);


If the ParentId doesn't exists, It causes a Foreign key error...

How can I set the tab's ParentId to null?!

Answer

I just set the ParentID to a page that I'm sure exists...
After that, with below script I set the ParentID of the new tab to null

TabInfo tab;
tab=new TabInfo()
//set properties of tab object...
//..
tab.ParentId = 38;//38 is my main page tabID
//...
//add new tab code
tabid = controller.AddTab(tab);
//update parentID code
DotNetNuke.Data.DataProvider.Instance().ExecuteSQL("update tabs set parentid=null where tabid=" + tabid);

EDIT:
Based on Javier answer int the comments the result is like this:

tab.ParentId = DotNetNuke.Common.Utilities.Null.NullInteger;