对此疯狂。我有一个Telerik RadComboBox下拉列表,我选择一个员工姓名。在它旁边,我有一个常规文本框,用户可以在其中键入员工编号(客户请求此信息)。我已经编写了所有代码来完成这项工作,但我错过了能够通过后面的代码更改Telerik RadComboBox下拉选择的神奇代码行。
我已经详尽地搜索了这个并找到了一个解决方案,它应该能够通过处理下拉框对象来选择一个新人:
rdcEmployeename.Items.FindItemByValue(pID.ToString()).Selected = true;
这实际上什么也没做,没有任何反应......是的,我传递了pID的有效值。我是如此迷失并且对Telerik不熟悉,任何人都可以帮忙解决这个问题吗?
提前致谢。
这是页面背后的整个课程:
public partial class admTimeAllocationPage : BasePage
{
public DataTable timeallocationdatatable;
private static SqlConnection sqlCon = new SqlConnection(ConfigurationManager.AppSettings["connStr"].ToString());
private void Page_Load(object sender, EventArgs e)
{
//string temp = Convert.ToString(Session["loginPersonID"]);
// unlockCheckBox.ForeColor = Color.Red;
// unlockCheckBox.Text = "Unlock Checkbox";
string strSkin = ConfigurationManager.AppSettings["Telerik.Skin"].ToString();
if (!IsPostBack)
{
Pnladd.Visible = false;
Persons GetEmployeeName = new Persons(sqlCon);
DataTable dtpersonname = GetEmployeeName.GetAll_ID_And_NameEmployeesOnly();
rdcEmployeename.DataSource = dtpersonname;
rdcEmployeename.DataTextField = "PreferredName";
rdcEmployeename.DataValueField = "ID";
rdcEmployeename.DataBind();
int PID = Convert.ToInt32(rdcEmployeename.SelectedValue);
DataTable dtEmpnumber = GetEmployeeName.GetAllEmpNumber(PID);
rdcEmpno.DataSource = dtEmpnumber;
rdcEmpno.DataTextField = "employmentNumber";
rdcEmpno.DataValueField = "id";
rdcEmpno.DataBind();
Employees Getdetail = new Employees(sqlCon);
DataTable BindEmpDetails = Getdetail.GetDataFromEmployeeinfo(PID);
Session["Idpass"] = PID;
//RadGrid1.DataSource = BindEmpDetails;
//RadGrid1.MasterTableView.DataSource = BindEmpDetails;
DataTable Codebind = Getdetail.GetCode();
Radcode.DataSource = Codebind;
Radcode.DataTextField = "code";
Radcode.DataBind();
TimeAllocation GetTimeAllocationData = new TimeAllocation(sqlCon);
DataTable BindTimeAllocationData = GetTimeAllocationData.GetCurrentDataFromTimeAllocationTable(PID);
Session["Idpass"] = PID;
RadGrid1.DataSource = BindTimeAllocationData;
RadGrid1.MasterTableView.DataSource = BindTimeAllocationData;
timeallocationdatatable = BindTimeAllocationData;
EmployeeScheduledHours.Text = Convert.ToString(GetTimeAllocationData.GetEmployeeScheduledHours(PID));
EmployeeAllocatedHours.Text = Convert.ToString(GetTimeAllocationData.GetEmployeeAllocatedHours(PID));
UseTimeAllocation.Checked = getCheckBoxValue();
UseTimeAllocation.Enabled = false;
EmployeeNumber.Text = Convert.ToString(EmployeeNumberFromPersonID(PID));
}
}
private int PersonIDFromEmployeeNumber(int employeeNumber)
{
using (SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["connStr"].ToString()))
{
SqlCommand cmdselect = new SqlCommand(
" SELECT TOP 1 ID FROM Persons WHERE CONVERT(int,ADP_PersonID) = " + employeeNumber, connection);
int pID;
try
{
connection.Open();
pID = Convert.ToInt32(cmdselect.ExecuteScalar());
}
catch (Exception err)
{
String strErr = err.Message;
throw;
}
finally
{
connection.Close();
}
return pID;
}
}
private int EmployeeNumberFromPersonID(int personID)
{
using (SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["connStr"].ToString()))
{
SqlCommand cmdselect = new SqlCommand(
" SELECT TOP 1 CONVERT(int,ADP_PersonID) FROM Persons WHERE id = " + personID, connection);
int employeeNumber;
try
{
connection.Open();
employeeNumber = Convert.ToInt32(cmdselect.ExecuteScalar());
}
catch (Exception err)
{
String strErr = err.Message;
throw;
}
finally
{
connection.Close();
}
return employeeNumber;
}
}
protected void btnEmployeeNumberLookup_Click(Object sender, EventArgs e)
{
int employeeNumber=0;
try
{
employeeNumber = Convert.ToInt32(EmployeeNumber.Text);
}
catch (Exception err)
{
EmployeeNumber.Text = "Invalid Entry, Try Again";
}
int pID = PersonIDFromEmployeeNumber(employeeNumber);
unlockCheckBox.ForeColor = Color.Red;
unlockCheckBox.Text = "Unlock Checkbox";
if (pID != 0)
{
//I Want to change the selection HERE!!!!!!
rdcEmployeename.ClearSelection();
rdcEmployeename.SelectedValue = pID.ToString();
}
else
{
EmployeeNumber.Text = "Invalid Entry, Try Again";
}
}
protected void rdcEmployeename_SelectedIndexChanged(object sender, EventArgs e)
{
unlockCheckBox.ForeColor = Color.Red;
unlockCheckBox.Text = "Unlock Checkbox";
int PersonID = Convert.ToInt32(rdcEmployeename.SelectedValue);
Persons GetPersonName = new Persons(sqlCon);
DataTable dtEmpnumber = GetPersonName.GetAllEmpNumber(PersonID);
rdcEmpno.DataSource = dtEmpnumber;
rdcEmpno.DataTextField = "employmentNumber";
rdcEmpno.DataValueField = "id";
rdcEmpno.DataBind();
Session["Idpass"] = PersonID;
Employees Getdetail = new Employees(sqlCon);
DataTable BindEmpDetails = Getdetail.GetDataFromEmployeeinfo(PersonID);
TimeAllocation GetTimeAllocationData = new TimeAllocation(sqlCon);
DataTable BindTimeAllocationData = GetTimeAllocationData.GetCurrentDataFromTimeAllocationTable(PersonID);
timeallocationdatatable = BindTimeAllocationData;
RadGrid1.DataSource = BindTimeAllocationData;
RadGrid1.DataBind();
EmployeeScheduledHours.Text = Convert.ToString(GetTimeAllocationData.GetEmployeeScheduledHours(PersonID));
EmployeeAllocatedHours.Text = Convert.ToString(GetTimeAllocationData.GetEmployeeAllocatedHours(PersonID));
UseTimeAllocation.Checked = getCheckBoxValue();
UseTimeAllocation.Enabled = false;
EmployeeNumber.Text = Convert.ToString(EmployeeNumberFromPersonID(PersonID));
}
}
我是stackoverflow的新手,所以请原谅格式化。我正在尝试使下拉框的选定值从'btnEmployeeNumberLookup_Click'更改。
答案 0 :(得分:0)
尝试将RadComboBox添加到radAjaxManager:
<telerik:RadAjaxManager ID="RadAjaxManager" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="rdcEmployeenameEmployeeNumber">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="EmployeeNumber"></telerik:AjaxUpdatedControl>
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>