【问题标题】:Asp.net repeater control data duplicated when use multiple times binding使用多次绑定时,Asp.net 中继器控制数据重复
【发布时间】:2011-10-07 09:02:47
【问题描述】:

我正在使用 asp.net 2008 中继器控件。我试图在单击按钮时刷新中继器控件,它向我显示重复的值,这意味着它再次附加相同的值。这是我的代码

 public void LoadRepeater1()
    {
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlServerConnection"].ConnectionString);
        String sql;
        sql = "select * from FeeCollection Where AdminNo='"+lblstano.Text+"'";
        cmd = new SqlCommand(sql, con);
        da = new SqlDataAdapter(sql, con);
        da.Fill(ds, "FeeCollection");
        dt = ds.Tables["FeeCollection"];

        Repeater4.DataSource = dt;
        Repeater4.DataBind();
        con.Close();


    }

 protected void btnMedical_Click(object sender, EventArgs e)
    {
        LoadRepeater1();
    }

我想删除现有数据并刷新数据而不是追加。

【问题讨论】:

    标签: asp.net repeater asprepeater


    【解决方案1】:

    不确定ds (DataSet) 在哪里实例化。尝试在 LoadRepeater1() 方法中实例化 DataSet/DataTable

    public void LoadRepeater1()
        {
            con = new SqlConnection(ConfigurationManager
             .ConnectionStrings["SqlServerConnection"].ConnectionString);
    
            sql = "select * from FeeCollection Where AdminNo=@AdminNo";
            cmd = new SqlCommand(sql, con);
            cmd.Parameters.Add("@AdminNo",System.Data.SqlDbType.VarChar,20).Value=lblstano.Text;
            da = new SqlDataAdapter(cmd);
            DataTable dt=new DataTable();
            da.Fill(dt);
            Repeater4.DataSource = dt;
            Repeater4.DataBind();
        }
    

    【讨论】:

    • 谢谢,我正在使用全局变量作为未清除的数据集。现在我使用了局部变量并且工作正常
    猜你喜欢
    • 2016-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多