日期:2014-05-18  浏览次数:20360 次

求高手-------帮我改下语句
classid   classname   fatherid     scblevel
1                 蔬菜类       -1                   01
2                 白菜             1                   0101
3                 大白菜         2                   010101
4                 小白菜         2                   010102
5                   茄子           1                   0102
6                   大茄子       5                   010201
7                   小茄子       5                   010202
8               上等小茄子   7                   01020201
表是这个样子的。
要用listbox显示。
绑定语句如下:
  string   sql   =   "select   *   from   scb_subject   order   by   scblevel ";
                SqlCommand   MyComm   =   new   SqlCommand(sql,   MyConn);
                MyComm.CommandText   =   sql;
                SqlDataAdapter   da   =   new   SqlDataAdapter(sql,   MyConn);
                DataSet   ds   =   new   DataSet();
                da.Fill(ds, "class ");
                ListBox1.DataSource=ds;                
                ListBox1.DataTextField= "classname ";
                ListBox1.DataValueField= "classID ";
                ListBox1.DataBind();
现在我想利用判断scblevel的字符长度判断。
如果字符长度为4那么在分支的前面添加-
如果字符长度为6那么在分支添加2个-
效果:
蔬菜类
蔬菜
-白菜
--大白菜
--小白菜
-茄子
--大茄子
--小茄子
---上等小茄子
怎么加?

这里想写成循环。
应该用while来写。但是我不知道这里应该怎么写。
求高手。帮添一下。

------解决方案--------------------
try:

string sql = "select classid,(Case when LEN(scblevel)=4 then '- '+classname
when LEN(scblevel)=6 then '-- '+classname end) as classname, fatherid, scblevel from scb_subject order by scblevel ";
------解决方案--------------------
后台写个方法
a(string a)
{
for(i=0;i <a.length;i+=2)
{
a = "- " + a;
}
return a;
}
绑定时这样 <%# a(Eval( "scblevel ").toString()) %>
------解决方案--------------------
try

SELECT
classid, (CASE LEN(scblevel) WHEN 4 THEN '- '