Frage

I am using asp.net 2008 repeater control. I am trying to refresh the repeater control when a button is clicked, it shows me duplicated values, that means its appending the same values once again. Here is my code

 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();
    }

I want to remove the existing data and refresh the data instead of appending.

War es hilfreich?

Lösung

Not sure where ds (DataSet) in instantiated. Try to instantiate the DataSet/DataTable within the LoadRepeater1() method.

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();
    }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top