How to reference a control? Using a DropDownList as an example. I want to reference "ddlName" (name of existing dropdownlist) just like using macro in VFP. I eventually want to use this to pass parameter. Thank You in advance!
protected void PopulateName() {
string DataPara= "name"; // Parameter1
SqlPara = "SELECT x FROM x"; // Parameter2
newname = "ddlName"; // Parameter3 ?
SqlConnection connData = new SqlConnection();
connData.ConnectionString =
ConfigurationManager.ConnectionStrings["ConnSqlUsr"].ConnectionString;
connData.Open();
SqlCommand connCmd = new SqlCommand(SqlPara, connData);
SqlDataReader connDr = connCmd.ExecuteReader();
newname.DataSource = connDr; ?
newname.DataValueField = DataPara; ?
newname.DataTextField = DataPara; ?
newname.DataBind(); ?
connDr.Close();
connDr.Dispose();
connCmd.Dispose();
LoginView1 is page name
DropDownList ddl = (DropDownList)LoginView1.FindControl("ddlName");
ddl.DataSource = connDr; ?
ddl.DataValueField = DataPara; ?
ddl.DataTextField = DataPara; ?
ddl.DataBind();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.