Hazel Mahmud

Hazel Mahmud

  • 1.4k
  • 315
  • 70.7k

hide div when href don't exist jquery

Jan 24 2016 9:27 PM
can anyone help me.. I have coding that generate dynamic div based on database data. I'm using stringbuilder. In the div i have div= menu which has href in it. The href will generate base on database data also. i do i make the dynamic div hide when there is no href in the div=menu. below are my aspx.cs code and jquery. Please help..
 
 aspx.cs 
 
using (SqlConnection stud = ClassConn.GetStudPortConnection())
{
StringBuilder stringBuilder = new StringBuilder();

// stud.Open();

da.SelectCommand = new SqlCommand("SELECT moduleID,moduleDesc FROM Module WHERE systemID = '1'", stud);
SqlDataReader sc = da.SelectCommand.ExecuteReader();

if (sc.HasRows)
{
while (sc.Read())
{
var modID = sc["moduleID"].ToString();
var modDesc = sc["moduleDesc"].ToString();


stringBuilder.Append("<div class=grid id=grid>");

stringBuilder.Append("<div id=module class=module >" + sc["moduleDesc"].ToString() + "</div>");
if (modDesc == "Timetable")
{
DataTable dt = this.BindGrid();

stringBuilder.Append("<table id=tbJadual class=tbJadual >");

//Building the Header row.
stringBuilder.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
stringBuilder.Append("<th>");
stringBuilder.Append(column.ColumnName);
stringBuilder.Append("</th>");
}
stringBuilder.Append("</tr>");

//Building the Data rows.
foreach (DataRow row in dt.Rows)
{
stringBuilder.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
stringBuilder.Append("<td id=td class=td>");
stringBuilder.Append(row[column.ColumnName]);
stringBuilder.Append("</td>");
}
stringBuilder.Append("</tr>");
}

//Table end.
stringBuilder.Append("</table>");

}

if (modDesc == "Profile")
{
DataTable dt = this.studentProfile();

stringBuilder.Append("<table id='tbProfile' class='tbProfile'>");

//Building the Header row.

foreach (DataColumn column in dt.Columns)
{
stringBuilder.Append("<tr>");

foreach (DataRow row in dt.Rows)
{
stringBuilder.Append("<td id=td class=td style='border:1px solid grey;padding-left:5px;height:47px;color:black'>");
stringBuilder.Append(row[column.ColumnName]);
stringBuilder.Append("</td>");

}
stringBuilder.Append("</tr>");
}


//Table end.
stringBuilder.Append("</table>");
}

stringBuilder.Append("<div id='menuBox' class='menuBox'>");

using (SqlConnection stud1 = ClassConn.GetStudPortConnection())
{

da.SelectCommand = new SqlCommand("SELECT moduleID,menuDesc,menuPath FROM Menu WHERE moduleID='" + modID + "'", stud1);
SqlDataReader sc1 = da.SelectCommand.ExecuteReader();

if (sc1.HasRows)
{
while (sc1.Read())
{
stringBuilder.AppendFormat("<div id=menu class=menu style='background-color:pink' >" + "<a class=path id=path href=" + sc1["menuPath"].ToString() + ">" + sc1["menuDesc"].ToString() + "</a>" + "</div>");
}
}

}
stringBuilder.Append("</div>");
stringBuilder.Append("</div>");
}

if (stringBuilder.Length > 0)
{
columnsContainer.Controls.Add(new Literal { Text = stringBuilder.ToString() });

columnsContainer.Visible = true;
}

}
 
jquery code:
 
$('div.grid').filter(function () {
var lis = $(this).find('#menu');
return lis.length === lis.filter(':empty').length;
}).hide();
 

Answers (2)