downdroplist绑定树形结构,把第二个字符串改变

问题1

假设有个字符串"aspkxiexhxlaspxxjmxaspmxj";
如何把第二次的asp替换成*号?
字符串长度不是固定的,是会变化的


            string str = "aspkxiexhxlaspxxjmxaspmxj";
            int i = 0;
            str = Regex.Replace(str, "asp", new MatchEvaluator(delegate(Match match) { return i++ == 1 ? "*" : match.Value; }));
            Console.WriteLine(str);

DropDownList动态绑定数据库表,实现目录树


static DataColumn column = new DataColumn();
    static DataTable table = new DataTable();

      static DataRow MyRow;
 public static DataTable GetCategoryTree(WebInfoBase info)
    {
       DataTable dt = info.List(_DefaultDB, "", "[ID],[Title],[ParentID],[ChildNum],[Depth],[OrderNo]", "&version=", "[ID] ASC");
     
       if (table.Rows.Count > 0)
       {
           table.Columns.Clear();
           table.Rows.Clear();
       }
       CreateDataTable();
       GetTree(dt, "0", 0);
       return table;
    }
      public static void GetTree(DataTable dt, string pid, int blank)
      {
          string str = " ";
          DataView dv = new DataView(dt);
          dv.RowFilter = "ParentID = " + pid;
          if (blank > 0)
          {
              string s = "";
              if (blank == 1)
              {
                  str = "├";
              }
              for (int i = 2; i <= blank; i++)
              {
                  s = s + "  |  "+" "+" - ";
              }
              str = s + "├";
          }
         
          foreach (DataRowView drv in dv)
          {
              string id = drv["ID"].ToString();
              string Title = drv["Title"].ToString();
              string OrderNo = drv["OrderNo"].ToString();
              string ParentID = drv["ParentID"].ToString();
              string Depth = drv["Depth"].ToString();
              string ChildNum = drv["ChildNum"].ToString();
             
              MyRow = table.NewRow();
              MyRow["ID"] = int.Parse(id);
              MyRow["Title"] = str + Title;
              MyRow["OrderNo"] = int.Parse(OrderNo);
              MyRow["ParentID"] = int.Parse(ParentID);
              MyRow["Depth"] = int.Parse(Depth);
              MyRow["ChildNum"] = int.Parse(ChildNum);
              table.Rows.Add(MyRow);

              int n = int.Parse(Depth);
              //if (n <= 1)
              //{
                  n++;
              //}
              GetTree(dt, id, n);
          }
      }
         public static void CreateDataTable()
      {
          table.Columns.Clear();
          column = new DataColumn();
          column.DataType = System.Type.GetType("System.Int32");
          column.ColumnName = "ID";
          table.Columns.Add(column);

          column = new DataColumn();
          column.DataType = System.Type.GetType("System.Int32");
          column.ColumnName = "ParentID";
          table.Columns.Add(column);

          column = new DataColumn();
          column.DataType = Type.GetType("System.String");
          column.ColumnName = "Title";
          table.Columns.Add(column);

          column = new DataColumn();
          column.DataType = Type.GetType("System.Int32");
          column.ColumnName = "ChildNum";
          table.Columns.Add(column);

          column = new DataColumn();
          column.DataType = Type.GetType("System.Int32");
          column.ColumnName = "Depth";
          table.Columns.Add(column);

          column = new DataColumn();
          column.DataType = Type.GetType("System.Int32");
          column.ColumnName = "OrderNo";
          table.Columns.Add(column);
          //table.Columns.Clear();

      }


百度和谷歌的

我是这样做的 
  建了个新页面 
  在前台代码中: 
  <body  MS_POSITIONING="GridLayout"> 
        <form  id="Form1"  method="post"  runat="server"  target="result"> 
            <FONT  face="宋体"> </FONT> 
                <TBODY> 
    <tr> 
        <td> 
                          <asp:TextBox  ID="text1"  Runat="server"  Width="95px"  Height="22"> </asp:TextBox> 
        <asp:Button  ID="btn"  Text="百度搜索"  Runat="server"  Width="72px"  Height="24"> </asp:Button> 
        </td> 
                      </tr> 
                </form> 
  </body> 
  后台的代码即Button的Click事件为: 
  private  void  btn_Click(object  sender,  System.EventArgs  e) 
  { 
          Response.ContentEncoding  =  System.Text.Encoding.GetEncoding("GB2312");
          Response.Redirect("http://www.baidu.com/s?wd="+text1.Text+"&cl=3"); 
  } 
  

转载于:https://www.cnblogs.com/z2002m/archive/2009/04/20/1439685.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值