首页 新闻 赞助 找找看

关于repeater的一个问题

0
悬赏园豆:5 [已关闭问题]

我在加载的时候遍历Repeater中的Items的项,但是老是为空,该怎么办。可能是生命周期的问题,不应该放在Load事件中,但是放在pre_Load事件中也不行,但是放在button事件中的时候就行,有哪位高手能告诉我一下是怎么回事吗?

foreach (RepeaterItem item in this.rpGoodsType.Items)
{

Impossible的主页 Impossible | 初学一级 | 园豆:72
提问于:2010-04-29 11:23
< >
分享
其他回答(1)
0

第一:需要先绑定再遍历。

第二:遍历处理过要更新。

 

参考我批量更新时的代码:

//遍历更新学生信息表
protected void BtnUpdate_Click(object sender, EventArgs e)
{
    int UpdateCount = 0;//更新成功数
    for (int i = 0; i <= RptStudents.Items.Count - 1; i++)
    {
        HyperLink LnkName = (HyperLink)RptStudents.Items[i].FindControl("LnkName");
        TextBox TxtAge = (TextBox)RptStudents.Items[i].FindControl("TxtAge");
        if (LnkName == null)
            continue;
        studentsInfo.EName = LnkName.Text.ToString();
        studentsInfo.Age = Convert.ToInt32(TxtAge.Text.ToString());
        studentsInfo.Adddate = DateTime.Now.ToString();

        RepeaterItem item = LnkName.Parent as RepeaterItem;
        Label LabFId = item.FindControl("LabId") as Label;
        studentsInfo.Id = LabFId.Text.ToString();

        if (LabFId.Text.ToString() != "")
        {
            if (students.Update(studentsInfo) > 0)
                UpdateCount += 1;
        }
    }
    ScriptManager.RegisterStartupScript(UpDPanelStudents, typeof(UpdatePanel), "JsAlert", "alert('更新" + UpdateCount.ToString() + "条记录成功!')", true);
    BindRptStudents("1");//更新完要绑定
}

Astar | 园豆:40805 (高人七级) | 2010-04-29 11:40
0

1.处理前repeater没有DataBind()

2.如果是回发,不能禁用viewState

LittlePeng | 园豆:3445 (老鸟四级) | 2010-04-29 13:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册