选择后,自动触发函数,根据所选值获取数据
1 protected void ddlMachineName_SelectedIndexChanged(object sender, EventArgs e) 2 { 3 DropDownList ddlMachineName = sender as DropDownList; 4 string text = ddlMachineName.SelectedValue; 5 MdMachineEntity entity = MdMachine.GetMdMachineByID(text); 6 //找到所在的行 7 int row=((GridViewRow)((DropDownList)sender).NamingContainer).RowIndex; 8 Label lblMachineID = 9 grdResult.Rows[row].FindControl("lblMachineID") as Label;10 lblMachineID.Text = entity.MachineID;11 }
DropDownList添加change事件的时候,需要添加AutoPostBack=true,不然无法自动更新数据.