Copy Code code as follows:
private string toadd = "├". <br><br>private void Getarticlecategory (String pid)
{
SqlConnection conn = new SqlConnection ("server=.; database=test;uid=sa;pwd=; ");
String sql = "Select Articlesgroup_id,groupname from Articlesgroup where articlesgroup_parent_id= @pid order by GroupName" ;
SqlCommand cmd = new SqlCommand (SQL, conn);
SqlParameter Pid = new SqlParameter ("@pid", SqlDbType.Int);
Pid.value = pid;
Cmd. Parameters.Add (Pid);
Conn. Open ();
SqlDataReader SDR = cmd. ExecuteReader ();
while (SDR. Read ())
{
This. DROPDOWNLIST1.ITEMS.ADD (New ListItem (Toadd + "" + sdr[1). ToString (), sdr[0]. ToString ()));
Toadd + = "─┴";
This. Getarticlecategory (Sdr[0]. ToString ());
Toadd = Toadd. Substring (0, Toadd. LENGTH-2);
}
Sdr. Close ();
Conn. Close ();
}
Called in the Page_Load.
Program code
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
THIS.KEYWORD.ATTRIBUTES.ADD ("onfocus", "if (this.value== ' key key ') {this.value= '};");
if (! Page.IsPostBack)
{
This. Getarticlecategory ("0");
}
This. DropDownList1.Items.Insert (0, New ListItem ("Search All", "all"));
}