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

replace的问题 有点奇怪
数据库是这样的:[表名:NEWS_SECTIONS]
0 0   首頁
1 0,1   通知
2 0,2   公告
3 0,3   通報
4 0,1,4   內部通知
5 0,1,5   外部通知
6 0,2,6   一般公告
7 0,2,7   重要公告
8 0,1,4,8   人事部通知
9 0,1,4,9   技術部通知
10               0,1,5,10     "要显示的东西 "
id的关系相信一看就清楚吧。此页面有个DropDownlist,我要做的是:循环读取数据,然后把读出来的数据加载到DropDownlist,加载出来的效果是
> 首页
> 首页> 通知
> 首页> 通知> 内部通知
...
> 首页> 通知> 外部通知> “要显示的东西”(注意这里id已经变成2位数)

先看我的方法:
public   void   additmes()  
        {
                string   items_id   =   " ";
                string   name   =   " ";
                //加入第一項
                //獲取所有link字段
                string   allitems   =   "select   LINK   from   NEWS_SECTIONS   order   by   LINK ";
                //獲取數據集
                ds1   =   db.getDataSet(allitems,   "NEWS_SECTIONS ");
                //字段斷行數
                int   num   =   ds1.Tables[ "NEWS_SECTIONS "].Rows.Count;
                //從1取值
                for   (int   i   =   0;   i   <   num;   i++)  
                {
                        //循環賦值
                        items_id   =   ds1.Tables[ "NEWS_SECTIONS "].Rows[i][0].ToString();
                        //得到顯示格式
                        items_id   =   items_id.Replace( ", ",   "> ");
                       
                        string[]   arr   =   items_id.Split( '> ');
                        for   (int   j   =   0;   j   <   arr.Length;   j++)  
                        {
                                //Response.Write(arr[j]+ "       ");
                                string   getname   =   "select   SECTIONS_NAME   from   NEWS_SECTIONS   where   SECTIONS_ID= "   +   arr[j];