具有UpdatePanel的中继器 [英] Repeater with UpdatePanel

查看:78
本文介绍了具有UpdatePanel的中继器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我有一个UpdatePanel,其中有一个Repeater控件,其中嵌套了另一个Repeater控件.在此嵌套的Repeater控件中,我有一个用于添加注释的文本框和一个用于提交注释的按钮.

单击按钮时,将触发UpdatePanel,并且在Repeater2_ItemCommand事件中,我已将TextBox值保存在数据库中,然后称为Repeater2.DataBind().

据我说,Repeater必须从数据库中获取新值并显示它们.但这并不会以这种方式发生.单击按钮"时,正在保存数据,但页面保留为空白.添加评论后,我只有在再次访问页面链接时才能查看数据(因为刷新"也无效).

请告诉我该怎么办!

中继器代码:

Hello everyone!

I have an UpdatePanel which has a Repeater Control in which another Repeater Control is nested. Within this nested Repeater Control,I have a TextBox for adding comments and a Button to Submit it.

On button click, the UpdatePanel is triggered and in the Repeater2_ItemCommand event, I have saved the TextBox value in database and then called Repeater2.DataBind().

According to me, the Repeater must fetch the new values from the DataBase and display them. But it doesn''t happen in that manner. On Button Click, the data is being saved but the page is left blank. I can view the data only when I visit the page link again(as Refresh also doesn''t work) after adding the comment.

Please tell me what to do!

Code for repeater:

protected void Repeater2_ItemCommand(object sender, RepeaterCommandEventArgs e)
    {
        lblMsg.Visible = false;
        TextBox tb = new TextBox();
        id = e.CommandArgument.ToString();
        column1 = ((TextBox)e.Item.FindControl("txtCol1")).Text.Trim();
        column2 = ((TextBox)e.Item.FindControl("txtCol2")).Text.Trim());
        cmd = new SqlCommand("update tab set col1=@col1,col2=@col2 where id=@id", con);
        cmd.Parameters.AddWithValue("@id", id);
        cmd.Parameters.AddWithValue("@col1", column1);
        cmd.Parameters.AddWithValue("@col2", column2);
        int rwcnt = cmd.ExecuteNonQuery();
        Reapeter2.DataBind();
        if (rwcnt <= 0)
            lblMsg.Visible = true;
    }

推荐答案

在使用DataBind之前,您需要将DataSource分配给转发器,而缺少转发器
Before DataBind you need to assign DataSource to the repeater, that is missing
Reapeter2.DataSource =source;



请发送您的代码到后面,以将数据绑定到转发器控件.
Hi,
Please send your code behind for data bind to repeator control.


这篇关于具有UpdatePanel的中继器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆