Downdroplist binds the tree structure and changes the second string.

Source: Internet
Author: User

Question 1

Assume that there is a string "aspkxiexhxlaspxxjmxaspmxj ";
How to replace the second ASP with the * number?
The string length is not fixed and will change.

String STR = "aspkxiexhxlaspxxjmxaspmxj ";
Int I = 0;
STR = RegEx. Replace (STR, "asp", new matchevaluator (delegate (match) {return I ++ = 1? "*": Match. value ;}));
Console. writeline (STR );

Dropdownlist dynamically binds database tables to implement directory tree

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 = "success ";
}
For (INT I = 2; I <= blank; I ++)
{
S = S + "|" + "" + "-";
}
STR = S + "success ";
}

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 ();

}

Baidu and Google

I did this.
A new page is created.
In the front-end code:
<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 = "Baidu search" runat = "server" width = "72px" Height = "24"> </ASP: button>
</TD>
</Tr>
</Form>
</Body>
The background code, that is, the Click Event of the button, is:
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 ");
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.