The is the step-by-step procedure for creating dynamic tabs using SQL Server 2008 and above with conditions.
Program output 
Step 1: Create .dbo (table) and sp (Stored Procedure) that is displayed at the front.
Table City
Table Property
Stored Procedures

Step 2: Write the Business Access Layer (BAL) that is in the App_Code Folder with this code:
- public String View_All_HotProperty(String PN, String PS, String PB)
- {
- try
- {
- output = String.Empty;
- dt = new DataTable();
- DataTable dt11 = new DataTable();
- DataTable dt1 = new DataTable();
- DataTable dt2 = new DataTable();
- DataTable dt3 = new DataTable();
- DataTable dt4 = new DataTable();
- DataTable dt5 = new DataTable();
- DataTable dt6 = new DataTable();
- DataTable dt7 = new DataTable();
- DataTable duplidt = new DataTable();
- int c = 0;
- int c1 = 0;
- int t = 0;
- int jump = 0;
- string match = string.Empty;
- int count=1;
- int ii=0;
- dt = objDal.GetDataTableHot(ref dt, "sp_View_All_HotProperty3");
- dt1 = objDal.GetDataTableHot(ref dt1, "sp_View_All_HotProperty1");
- dt2 = objDal.GetDataTableHot(ref dt2, "sp_View_All_HotProperty2");
- dt3 = objDal.GetDataTableHot(ref dt3, "sp_View_All_HotProperty");
- dt4 = objDal.GetDataTableHot(ref dt4, "sp_View_All_HotProperty4");
- dt5 = objDal.GetDataTableHot(ref dt5, "sp_View_All_HotProperty5");
- dt6 = objDal.GetDataTableHot(ref dt6, "sp_View_All_HotProperty6");
- dt7 = objDal.GetDataTableHot(ref dt7, "sp_View_All_HotProperty7");
- //dt1= dt.Select("sateid like '%"+1+"%'");
- output = String.Empty;
- output += "<div class=\"container\">";
- output += "<ul class=\"tabs\">";
- output += "<li><a href=\"#tab1\">Dubai</a></li>";
- output += "<li><a href=\"#tab2\">Ajman</a></li>";
- output += "<li><a href=\"#tab3\">Al ain</a></li>";
- output += "<li><a href=\"#tab4\">Abu dhabi</a></li>";
- output += "<li><a href=\"#tab5\">Fujairah</a></li>";
- output += "<li><a href=\"#tab6\">Ras al kahimah</a></li>";
- output += "<li><a href=\"#tab7\">Sharjah</a></li>";
- output += "<li><a href=\"#tab8\">Umm al quwain</a></li>";
- output += "</ul>";
- output += "<div class=\"tab_container\">";
- //For Tab1
- output += "<div id=tab1 class=\"tab_content\">";
- output += "<div class=\"pantool\">";
- //For Abudhabi
- output += "<div id=propheading><u>Dubai Properties For Sale and Rent</u> </div>";
- // output += "<div id=propheading><hr></hr></div>";
- output += "<div class=\"pan_tab1\">";
- //for (int i = dt.Rows.Count; ; i++)
- for (ii = dt.Rows.Count - 1; ii >= 0; ii--)
- {
- c = int.Parse(dt.Rows[0]["cityid"].ToString());
- t = 0;
- for (int j = 0; j < dt.Rows.Count; j++)
- {
- if (c == int.Parse(dt.Rows[j]["cityid"].ToString()))
- {
- t = t + 1;
- jump = int.Parse(dt.Rows[j]["cityid"].ToString());
- }
- }
- output += "<div class=\"pan_tab\">› <a href='SearchwithLocation.aspx?id=" + dt.Rows[0]["cityid"].ToString() + "&for=" + dt.Rows[0]["PropFor"].ToString() + "'>" + dt.Rows[0]["cityname"].ToString() + "(" + t + ")" + "</a></div>";
- output += "<div class=\"PropFor\">‹ " + dt.Rows[0]["PropFor"].ToString() + "</div>";
Output
This output string variable provides this result:
- match = dt.Rows[0]["cityname"].ToString();
- foreach (DataRow dr in dt.Rows)
- {
- if (dr["cityname"].ToString() == match)
- {
- dr.Delete();
- }
- }
- dt.AcceptChanges();
- count = dt.Rows.Count;
- ii = count;
- output += "</div>";
- //For Abudhabi
- output += "</div>";
- output += "</div>";
- //For Tab2
- output += "<div id=tab2 class=\"tab_content\">";
- output += "<div class=\"pantool\">";
- //For sale start
- output += "<div id=propheading><u>Ajman Properties For Sale and Rent</u> </div>";
- output += "<div class=\"pan_tab1\">";
- for (ii = dt1.Rows.Count - 1; ii >= 0; ii--)
- {
- c = int.Parse(dt1.Rows[0]["cityid"].ToString());
- t = 0;
- for (int j = 0; j < dt1.Rows.Count; j++)
- {
- if (c == int.Parse(dt1.Rows[j]["cityid"].ToString()))
- {
- t = t + 1;
- jump = int.Parse(dt1.Rows[j]["cityid"].ToString());
- }
- }
- output += "<div class=\"pan_tab\">› <a href='SearchwithLocation.aspx?id=" + dt1.Rows[0]["cityid"].ToString() + "'>" + dt1.Rows[0]["cityname"].ToString() + "(" + t + ")" + "</a></div>";
- output += "<div class=\"PropFor\">‹ " + dt1.Rows[0]["PropFor"].ToString() + "</div>";
Output
This output string variable provides this result:
- //For matching
- match = dt1.Rows[0]["cityname"].ToString();
- foreach (DataRow dr in dt1.Rows)
- {
- if (dr["cityname"].ToString() == match)
- {
- dr.Delete();
- }
- }
- dt1.AcceptChanges();
- count = dt1.Rows.Count;
- ii = count;
- }
- output += "</div>";
- //For sale End
- output += "</div>";
- output += "</div>";
- //For Tab3
- output += "<div id=tab3 class=\"tab_content\">";
- output += "<div class=\"pantool\">";
- //For Abudhabi
- output += "<div id=propheading><u>Al ain Properties For Sale and Rent</u> </div>";
- output += "<div class=\"pan_tab1\">";
- for (ii = dt2.Rows.Count - 1; ii >= 0; ii--)
- {
- c = int.Parse(dt2.Rows[0]["cityid"].ToString());
- t = 0;
- for (int j = 0;j < dt2.Rows.Count; j++)
- {
- if (c == int.Parse(dt2.Rows[j]["cityid"].ToString()))
- {
- t = t + 1;
- jump = int.Parse(dt2.Rows[j]["cityid"].ToString());
- }
- }
- output += "<div class=\"pan_tab\">› <a href='SearchwithLocation.aspx?id=" + dt2.Rows[0]["cityid"].ToString() + "'>" + dt2.Rows[0]["cityname"].ToString() + "(" + t + ")" + "</a></div>";
- output += "<div class=\"PropFor\">‹ " + dt2.Rows[0]["PropFor"].ToString() + "</div>";
Output
This output string variable provides this result:
- match = dt2.Rows[0]["cityname"].ToString();
- foreach (DataRow dr in dt2.Rows)
- {
- if (dr["cityname"].ToString() == match)
- {
- dr.Delete();
- }
- }
- dt2.AcceptChanges();
- count = dt2.Rows.Count;
- ii = count;
- }
- output += "</div>";
- //For Abudhabi
- output += "</div>";
- output += "</div>";
- //For Tab4
- output += "<div id=tab4 class=\"tab_content\">";
- output += "<div class=\"pantool\">";
- //For Abudhabi
- output += "<div id=propheading><u>Abu Dhabi Properties For Sale and Rent</u> </div>";
- output += "<div class=\"pan_tab1\">";
- for (ii = dt3.Rows.Count - 1; ii >= 0; ii--)
- {
- c = int.Parse(dt3.Rows[0]["cityid"].ToString());
- t = 0;
- for (int j = 0; j < dt3.Rows.Count; j++)
- {
- if (c == int.Parse(dt3.Rows[j]["cityid"].ToString()))
- {
- t = t + 1;
- jump = int.Parse(dt3.Rows[j]["cityid"].ToString());
- }
- }
- output += "<div class=\"pan_tab\">› <a href='SearchwithLocation.aspx?id=" + dt3.Rows[0]["cityid"].ToString() + "'>" + dt3.Rows[0]["cityname"].ToString() + "(" + t + ")" + "</a></div>";
- output += "<div class=\"PropFor\">‹ " + dt3.Rows[0]["PropFor"].ToString() + "</div>";
Output
This output string variable provides this result:
- match = dt3.Rows[0]["cityname"].ToString();
- foreach (DataRow dr in dt3.Rows)
- {
- if (dr["cityname"].ToString() == match)
- {
- dr.Delete();
- }
- }
- dt3.AcceptChanges();
- count = dt3.Rows.Count;
- ii = count;
- }
- output +="</div>";
- //For Abudhabi
- output += "</div>";
- output += "</div>";
- //For Tab5
- output += "<div id=tab5 class=\"tab_content\">";
- output += "<div class=\"pantool\">";
- //For Abudhabi
- output += "<div id=propheading><u>Fujairah Properties For Sale and Rent</u> </div>";
- output += "<div class=\"pan_tab1\">";
- for (ii = dt4.Rows.Count - 1; ii >= 0; ii--)
- {
- c = int.Parse(dt4.Rows[0]["cityid"].ToString());
- t = 0;
- for (int j = 0; j < dt4.Rows.Count; j++)
- {
- if (c == int.Parse(dt4.Rows[j]["cityid"].ToString()))
- {
- t = t + 1;
- jump = int.Parse(dt4.Rows[j]["cityid"].ToString());
- }
- }
- output += "<div class=\"pan_tab\">› <a href='SearchwithLocation.aspx?id=" + dt4.Rows[0]["cityid"].ToString() + "'>" + dt4.Rows[0]["cityname"].ToString() + "(" + t + ")" + "</a></div>";
- output += "<div class=\"PropFor\">‹ " + dt4.Rows[0]["PropFor"].ToString() + "</div>";
Output
This output string variable provides this result :





Rohatash KumarPosted Oct 25, 2013, 4:53 AM
Dileep, nice article. I have only problem that when we select tab and refresh whole page. It show first tab not selected tab.