<asp:dropdownlist Database Read

Source: Internet
Author: User

. aspx

<asp:dropdownlist id= "DropDownList1" runat= "Server" datavaluefield= "infoid" datatextfield= "Dtitle" >
<asp:ListItem> </asp:ListItem>
</asp:DropDownList>

, C1

Read value

if (! IsPostBack)
{

int id = convert.toint32 (request.querystring["infoid"]);

Dataaccess.da DAC = new Dataaccess.da ();
Dac.con.Open ();
SqlCommand cmd = new SqlCommand ("SELECT * FROM table where id =" + id + "");
Cmd. Connection = Dac.con;
SqlDataReader SDR = cmd. ExecuteReader ();
Sdr. Read ();
Txttitle. Text = sdr["Xtitle"]. ToString ();
Txtzhaiyao. Text = sdr["Abstract"]. ToString ();
Content1. Value = sdr["Bcontent"]. ToString ();

Dropdownlist1.selectedvalue = sdr["did"). ToString ();

Getdatalei ();

}

Public void Getdatalei ()
{

Dataaccess.da DAC = new Dataaccess.da ();
String sql = "SELECT * from Ency_info where encytype=1";
SqlCommand cmd = new SqlCommand (sql, Dac.con);
SqlDataAdapter da = new SqlDataAdapter (cmd);
DataSet ds = new DataSet ();
Da. Fill (DS);
This. Dropdownlist1.datasource = ds. Tables[0]. DefaultView;
This. Dropdownlist1.databind ();
    }

Storage

String strtype = this. DropDownList1.SelectedItem.ToString ();
String strbid = this. DropDownList1.SelectedItem.Value;

selecteditem--refers to the selected DropDownList option, which is ListItem, read-only and not write

selectedvalue--refers to the value of the selected DropDownList, String, read-only
SelectedItem is the selected item, which includes the value and text

<asp:dropdownlist Database Read

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.