使用多次绑定时,Asp.net转发器控制数据重复

时间:2011-10-07 09:02:48

标签: asp.net repeater asprepeater

我正在使用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();
    }

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

1 个答案:

答案 0 :(得分: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();
    }