rejnev rejnev - 1 year ago 103
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.Title="some title";
newTab.ParentId=0 /*--here is my problem--*/

TabController controller = new TabController();

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

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

Answer Source

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);

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

tab.ParentId = DotNetNuke.Common.Utilities.Null.NullInteger;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download