实际上我正在尝试绑定转发器行中的值并且它也连续绑定,我给了它们 ADD BUTTON ,用于向转发器添加额外的行,以便它们可以灵活我的问题是填充第一行当我按当我按下添加按钮时,转发器中的所有值都会消失,另外一行是得到补充。 我希望行中的选定值不会消失,并且应添加一行。 这是我的代码 FOR BINDING EMPTY ROW to repeater。
{
lstaddrow.Add(new IR_INVESTIGATION());
rptinvest.DataSource = lstaddrow;
rptinvest.DataBind();
}
这是我的代码 FOR EMPTY ROW。
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;
这是我的代码 BUTTON CLICK。
lstaddrow = addrows();
rptinvest.DataSource = lstaddrow;
rptinvest.DataBind();
}
答案 0 :(得分: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();