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");
}