. 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