0

实际上,我正在尝试在转发器行中绑定值,并且它也被绑定在一行中,并且我给了它们添加按钮以向转发器添加额外的行,以便它们可以灵活地工作。但我的问题是在填充之后第一行当我按下当我按下添加按钮时,转发器中的所有值都会消失,并且会添加额外的一行。我希望该行中的选定值应该不会消失,并且应该添加一个额外的行。这是我将空行绑定到中继器的代码。

{
 lstaddrow.Add(new IR_INVESTIGATION());
 rptinvest.DataSource = lstaddrow;
 rptinvest.DataBind();
}

这是我的空行代码。

 List<IR_INVESTIGATION> lstEntered = new List<IR_INVESTIGATION>();
    using (EHSIMSDataContext db = new EHSIMSDataContext())
    {
        foreach (RepeaterItem itm in rptinvest.Items)
        {
            DropDownList ddlemployee = itm.FindControl("ddlemployee") as DropDownList;
            DropDownList ddlrole = itm.FindControl("ddlrole") as  DropDownList;
            TextBox email = itm.FindControl("email") as TextBox;
            TextBox depart = itm.FindControl("depart") as TextBox;
            TextBox pos = itm.FindControl("pos") as TextBox;
            IR_INVESTIGATION abKeyword = new IR_INVESTIGATION();
            lstEntered.Add(abKeyword);

        }

    }
    return lstEntered;

这是我的代码按钮单击。

        lstaddrow = addrows();
        rptinvest.DataSource = lstaddrow;
        rptinvest.DataBind();
    }
4

1 回答 1

1

由于这些行,您的转发器项目正在消失,然后出现一个项目:

lstaddrow.Add(new IR_INVESTIGATION());
rptinvest.DataSource = lstaddrow;
rptinvest.DataBind();

这是创建一个项目列表,然后将转发器绑定到它。

相反,您希望将新IR_INVESTIGATION对象添加到输入项目列表 ( lstEntered) 中,并且仅lstEntered通过调用以下逻辑将转发器控件绑定到 :

public List<IR_INVESTIGATION> AddRowToRepeater()
{
    List<IR_INVESTIGATION> lstEntered = new List<IR_INVESTIGATION>();
    using (EHSIMSDataContext db = new EHSIMSDataContext())
    {
        foreach (RepeaterItem itm in rptinvest.Items)
        {
            DropDownList ddlemployee = itm.FindControl("ddlemployee") as DropDownList;
            DropDownList ddlrole = itm.FindControl("ddlrole") as  DropDownList;
            TextBox email = itm.FindControl("email") as TextBox;
            TextBox depart = itm.FindControl("depart") as TextBox;
            TextBox pos = itm.FindControl("pos") as TextBox;
            IR_INVESTIGATION abKeyword = new IR_INVESTIGATION();
            lstEntered.Add(abKeyword);
        }
    }

    return lstEntered;
}

现在您可以将中继器与新行绑定,如下所示:

rptinvest.DataSource = AddRowToRepeater();
rptinvest.DataBind();
于 2013-09-02T07:33:30.493 回答