У меня есть код asp classic о древовидном меню с использованием jquery.И теперь я буду применять в asp.net c #.
это мой код: https://1drv.ms/f/s!AmGb6w2qQcvJg1XFS8M8GRT-0_ST
это код в asp classic: rs.movefirst strMainDesc = ""
response.write "<ul class=aqtree3clickable>" & vbcrlf
while not rs.eof
'Prepare parameter for SettingId and DistrAll
if rs("DistrAll") = true then
strDistrAll = "1"
else
strDistrAll = "0"
end if
strParam = "SettingId=" & rs("SettingId") & "&DistrAll=" & strDistrAll
if instr(rs("ProgramName").value, "?") > 0 then
strParam = "&" & strParam
else
strParam = "?" & strParam
end if
'done preparing parameter
if strMainDesc <> rs("MainDesc").value then
if strMainDesc <> "" then
response.write "</ul></li>" & vbcrlf
end if
'penutup node untuk level 3,
if strPrnDesc<>"" and strPrnDesc <> rs("MenuLevel3").value then
if strPrnDesc <> strMainDesc then 'jika level 3 ada leaf nya, jangan write /u karena sudah ditutup diatas
response.write "</ul>" & vbcrlf
end if
strPrnDesc=""
end if
if rs("MenuLevel3").value <> "" and strPrnDesc <> rs("MenuLevel3").value then 'ada menu bertingkat
'Response.Write "isi instr=" & InStr(rs("MainDesc").value,"|") & "<BR>"
strPrnDesc = rs("MenuLevel3")
'Response.Write "isi=" & strPrnDesc & "<BR>"
response.write "<li class=node><a href=#>" & strPrnDesc & " </a>"& vbcrlf
response.write "<ul>" & vbcrlf
end if
strMainDesc = rs("MainDesc").value
if strPrnDesc <> strMainDesc then
response.write "<li class=node><a href=#>" & strMainDesc & " </a>"& vbcrlf
response.write "<ul>" & vbcrlf
end if
response.write "<li class=leaf><a onclick=""cl()"" target=main href="""
response.write rs("ProgramName").value & strParam
response.write """ title=""" & rs("SubDesc") & """>" & rs("SubDesc") & " </a></li>" & vbcrlf
else
response.write "<li class=leaf><a onclick=""cl()"" target=main href="""
response.write rs("ProgramName").value & strParam
response.write """ title=""" & rs("SubDesc") & """>" & rs("SubDesc") & " </a></li>" & vbcrlf
end if
Это мой опыт в c #:Но результат не тот же, вероятно, мой код не является правильным.
rs = cmd.ExecuteReader();
if (!IsPostBack)
{
Response.Write("<ul id='tes' class='aqtree3clickable' runat='server'> ");
while (rs.Read())
{
if (rs["DistrAll"].ToString() == "1")
{
strDistrAll = "1";
}
else
{
strDistrAll = "0";
}
strParam = "?SettingId=" + rs["SettingId"] + "&DistrAll=" + strDistrAll;
if (strMainDesc != rs["MainDesc"].ToString())
{
if (strMainDesc != "")
{
Response.Write("</ul></li>");
}
if (rs["MenuLevel3"].ToString() != "" && strPrnDesc != rs["MenuLevel3"].ToString())
{
strPrnDesc = rs["MenuLevel3"].ToString();
Response.Write("<li class=node><a href=#>" + strPrnDesc.ToString() + " </a>");
Response.Write("<ul>");
}
strMainDesc = rs["MainDesc"].ToString();
if (strPrnDesc != strMainDesc)
{
Response.Write("<li class=node><a href=#>" + strMainDesc.ToString() + " </a>");
Response.Write("<ul>");
}
Response.Write("<li class=leaf><a onclick='cl()' target=content href='");
Response.Write(rs["ProgramName"].ToString() + strParam + "'");
Response.Write(" title='" + rs["SubDesc"].ToString() + "'>" + rs["SubDesc"] + "3".ToString() + " </a></li>");
}
else
{
Response.Write("<li class=leaf><a onclick='cl()' target=content href=''");
Response.Write(rs["ProgramName"].ToString() + strParam);
Response.Write(" title=''" + rs["SubDesc"].ToString() + "''>" + rs["SubDesc"] + "4".ToString() + " </a></li>");
}
}
Response.Write("</ul></li></ul>");
}
rs.Close();
Спасибо,