asp.net drop-down list data binding implementation code

Source: Internet
Author: User
Tags add copy key sql net string tostring
Copy CodeThe code is 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 CodeThe code is 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"));
}


Related Article

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.