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");
-
- 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\">";
-
- output += "<div id=tab1 class=\"tab_content\">";
- output += "<div class=\"pantool\">";
-
- output += "<div id=propheading><u>Dubai Properties For Sale and Rent</u> </div>";
-
- output += "<div class=\"pan_tab1\">";
-
- 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>";
-
- output += "</div>";
- output += "</div>";
-
- output += "<div id=tab2 class=\"tab_content\">";
- output += "<div class=\"pantool\">";
-
- 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:
-
- 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>";
-
- output += "</div>";
- output += "</div>";
-
- output += "<div id=tab3 class=\"tab_content\">";
- output += "<div class=\"pantool\">";
-
- 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>";
-
- output += "</div>";
- output += "</div>";
-
- output += "<div id=tab4 class=\"tab_content\">";
- output += "<div class=\"pantool\">";
-
- 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>";
-
- output += "</div>";
- output += "</div>";
-
- output += "<div id=tab5 class=\"tab_content\">";
- output += "<div class=\"pantool\">";
-
- 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 :
- match = dt4.Rows[0]["cityname"].ToString();
- foreach (DataRow dr in dt4.Rows)
- {
- if (dr["cityname"].ToString() == match)
- {
- dr.Delete();
- }
- }
- dt4.AcceptChanges();
- count = dt4.Rows.Count;
- ii = count;
- }
- output += "</div>";
-
- output += "</div>";
- output += "</div>";
-
- output += "<div id=tab6 class=\"tab_content\">";
- output += "<div class=\"pantool\">";
-
- output += "<div id=propheading><u>Ras al kahimah Properties For Sale and Rent</u> </div>";
- output += "<div class=\"pan_tab1\">";
- for (ii = dt5.Rows.Count - 1; ii >= 0; ii--)
- {
- c = int.Parse(dt5.Rows[0]["cityid"].ToString());
- t = 0;
- for (int j = 0; j < dt5.Rows.Count; j++)
- {
- if (c == int.Parse(dt5.Rows[j]["cityid"].ToString()))
- {
- t = t + 1;
- jump = int.Parse(dt5.Rows[j]["cityid"].ToString());
- }
- }
- output += "<div class=\"pan_tab\">› <a href='SearchwithLocation.aspx?id=" + dt5.Rows[0]["cityid"].ToString() + "'>" + dt5.Rows[0]["cityname"].ToString() + "(" + t + ")" + "</a></div>";
- output += "<div class=\"PropFor\">‹ " + dt5.Rows[0]["PropFor"].ToString() + "</div>";
Output
This output string variable provides this result :
- match = dt5.Rows[0]["cityname"].ToString();
- foreach (DataRow dr in dt5.Rows)
- {
- if (dr["cityname"].ToString() == match)
- {
- dr.Delete();
- }
- }
- dt5.AcceptChanges();
- count = dt5.Rows.Count;
- ii = count;
- }
- output += "</div>";
-
- output += "</div>";
- output += "</div>";
-
- output += "<div id=tab7 class=\"tab_content\">";
- output += "<div class=\"pantool\">";
-
- output += "<div id=propheading><u>Sharjah Properties For Sale and Rent</u> </div>";
- output += "<div class=\"pan_tab1\">";
- for (ii = dt6.Rows.Count - 1; ii >= 0; ii--)
- {
- c = int.Parse(dt6.Rows[0]["cityid"].ToString());
- t = 0;
- for (int j = 0; j < dt6.Rows.Count; j++)
- {
- if (c == int.Parse(dt6.Rows[j]["cityid"].ToString()))
- {
- t = t + 1;
- jump = int.Parse(dt6.Rows[j]["cityid"].ToString());
- }
- }
- output += "<div class=\"pan_tab\">› <a href='SearchwithLocation.aspx?id=" + dt6.Rows[0]["cityid"].ToString() + "'>" + dt6.Rows[0]["cityname"].ToString() + "(" + t + ")" + "</a></div>";
- output += "<div class=\"PropFor\">‹ " + dt6.Rows[0]["PropFor"].ToString() + "</div>";
Output
This output string variable provides this result:
- match = dt6.Rows[0]["cityname"].ToString();
- foreach (DataRow dr in dt6.Rows)
- {
- if (dr["cityname"].ToString() == match)
- {
- dr.Delete();
- }
- }
- dt6.AcceptChanges();
- count = dt6.Rows.Count;
- ii = count;
- }
- output += "</div>";
-
- output += "</div>";
- output += "</div>";
-
- output += "<div id=tab8 class=\"tab_content\">";
- output += "<div class=\"pantool\">";
-
- output += "<div id=propheading><u>Umm al quwain Properties For Sale and Rent</u> </div>";
- output += "<div class=\"pan_tab1\">";
- for (ii = dt7.Rows.Count - 1; ii >= 0; ii--)
- {
- c = int.Parse(dt7.Rows[0]["cityid"].ToString());
- t = 0;
- for (int j = 0; j < dt7.Rows.Count; j++)
- {
- if (c == int.Parse(dt7.Rows[j]["cityid"].ToString()))
- {
- t = t + 1;
- jump = int.Parse(dt7.Rows[j]["cityid"].ToString());
- }
- }
- output += "<div class=\"pan_tab\">› <a href='SearchwithLocation.aspx?id=" + dt7.Rows[0]["cityid"].ToString() + "'>" + dt7.Rows[0]["cityname"].ToString() + "(" + t + ")" + "</a></div>";
- output += "<div class=\"PropFor\">‹ " + dt7.Rows[0]["PropFor"].ToString() + "</div>";
Output
This output string variable provides this result:
- match = dt7.Rows[0]["cityname"].ToString();
- foreach (DataRow dr in dt7.Rows)
- {
- if (dr["cityname"].ToString() == match)
- {
- dr.Delete();
- }
- }
- dt7.AcceptChanges();
- count = dt7.Rows.Count;
- ii = count;
- }
- output += "</div>";
-
- output += "</div>";
- output += "</div>";
-
- output += "</div>";
- output += "</div>";
- return output;
- }
- catch (Exception ex)
- {
- }
- return output;
- }
Note: This code also covers the deletion of duplicate data from a column with a condition.
- match = dt7.Rows[0]["cityname"].ToString();
- foreach (DataRow dr in dt7.Rows)
- {
- if (dr["cityname"].ToString() == match)
- {
- dr.Delete();
- }
- }
- dt7.AcceptChanges();
Match and delete data from a row and update the datatable.
Step 3: Call the above function at the .cs page with the following code:
- if (!IsPostBack)
- output = objProject.View_All_HotProperty("1", "25", "5");
Step 4: Call the above function at the .cs page with the following code:
Step 5: For Tab decoration use this jQuery and CSS:
- <script type="text/javascript">
- $(document).ready(function () {
-
- $(".tab_content").hide();
- $("ul.tabs li:first").addClass("active").show();
- $(".tab_content:first").show();
-
- $("ul.tabs li").click(function () {
- $("ul.tabs li").removeClass("active");
- $(this).addClass("active");
- $(".tab_content").hide();
- var activeTab = $(this).find("a").attr("href");
- $(activeTab).fadeIn();
- return false;
- });
- });
- </script>
- <link href="TABSheet.css" rel="stylesheet" type="text/css" />
TABSheet.css
Output
This output string variable provides this final result with select first tab:
To see all the tab results, click one tab for the opt specific output by location.
Note: This code will make 8 tabs with conditions that you gave from the SQL Server side.
I hope this article is very valuable and profitable for making attractive dynamic tabs using SQL Server.