Tuesday, October 25, 2011

Creating tabs from DB-query in ext.net

It's not hard storing all the information you need to create tabs from a database-query in ext.net. You can easily store title, filename and tooltip. To get the icon it's not as straight forward as it expects an enum and, of course, you could get the number and save that but it's a bit of a pain.

Instead do this:
foreach (DataRow dr in dt.Rows) {
            pnl = new Ext.Net.Panel();
            pnl.Title = dr["pagename"].ToString();
            pnl.TabTip = dr["description"].ToString();

            // get icon from string
            icon = (Icon)Enum.Parse(typeof(Icon), dr["icon"].ToString());
            pnl.Icon = icon;
            pnl.Layout = "FitLayout";
            pnl.AutoLoad.Url = dr["relative_url"].ToString() + "?d=" + Request.QueryString["d"];
            pnl.AutoLoad.Mode = LoadMode.IFrame;
            pnl.AutoLoad.NoCache = true;
            pnl.Border = false;

            // add to tabpanel
            tpPack.Items.Add(pnl);
        }
where dr["icon"] is the icon name (duh). :)