如何引用控件?使用DropDownList作为示例。我想引用“ddlName”(现有下拉列表的名称),就像在VFP中使用宏一样。我最终想用它来传递参数。提前谢谢!
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();
答案 0 :(得分:1)
LoginView1是页面名称
DropDownList ddl = (DropDownList)LoginView1.FindControl("ddlName");
ddl.DataSource = connDr; ?
ddl.DataValueField = DataPara; ?
ddl.DataTextField = DataPara; ?
ddl.DataBind();