0

I need to bind the values in the repeater control where I have 4 columns, in the 2 drop-down and 2 text boxes.

My requirement is when I select the first drop-down in first column depending on that selection, balance 3 columns should be get Bind in the repeater in the same row.

for eg

In First column DropDown, when I select the EmployeeName, next 3columns(AGE,NO,ADDRESS) in the same row in the repeater should be filled automatically.

 protected void ddlEmployee_SelectedIndexChanged(object sender, EventArgs e)
{
    using (EHSIMSDataContext db = new EHSIMSDataContext(EHSIMSConnectionString.GetConnectionString()))
    {
    (((sender as DropDownList).Parent).FindControl("email") as TextBox).Text =  ;
    (((sender as DropDownList).Parent).FindControl("Depart") as TextBox).Text = "Age";

    }
}

Repeater Control

 protected void rptactions_ItemDataBound(object sender, RepeaterItemEventArgs e)
{

        DropDownList ddlemployee = e.Item.FindControl("ddlemployee") as DropDownList;
      using (EHSIMSDataContext db = new EHSIMSDataContext(EHSIMSConnectionString.GetConnectionString()))
        {
            List<EMPLOYEE> objlistemp = (from ct in db.EMPLOYEEs
                                         orderby ct.FIRSTNAME
                                         select ct).ToList<EMPLOYEE>();
            ddlemployee.Items.Clear();
            ddlemployee.Items.Add(new ListItem("--SELECT--", ""));
            foreach (EMPLOYEE emp in objlistemp)
            {
                ddlemployee.Items.Add(new ListItem(emp.FIRSTNAME, emp.EMPLOYEE_ID.ToString()));
            }


    }
4

1 回答 1

0

这是您提到的场景的一种方法..

protected void ddlEmployee_SelectedIndexChanged(object sender, EventArgs e)
{
    (((sender as DropDownList).Parent).FindControl("txtAge") as TextBox).Text = "Age";
}

同样,您也可以找到其他控件...

注意:在 aspx 文件中,您需要OnSelectedIndex在 Repeater 中将更改的事件添加到此 DropDownList 控件,并且还应将其AutoPostBack属性设置为True

更新:

如果您的模型类如下所示

class Employee
{
     public int ID {get; set};
     public int Age {get; set};
     public string Name {get; set};
     public string Address {get; set};
}

如果您在对象lstEmployees(类型)中有员工列表,则可以使用以下查询List<Employee>检索具有 of 的员工的ID姓名employeeID

lstEmployees.Find(e => e.ID == employeeId).Name

当然,在尝试读取属性之前,您总是需要执行各种空值检查,否则可能会导致NullReferenceException找不到匹配项。

于 2013-07-28T09:53:49.597 回答