0

I saw similar posts but some weren't clear.

Here is the repeater head:

<asp:Repeater ID="rptGetAll" OnItemCommand="Buttons_OnItemCommand" runat="server" OnLoad="rptGetAll_Load">

I have a button:

 <asp:Button ID="Submit" runat="server" OnClick="Submit_Click" Text="Save" />

and I have the code-behind insert/update data in the database and then I set:

 using (SqlConnection con = new SqlConnection(conString))
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand("administratorUpdate", con))
                {
                    cmd.Parameters.Add("@originalID", SqlDbType.VarChar).Value = hfID.Value;
                    cmd.Parameters.Add("@firstName", SqlDbType.VarChar).Value = MyGlobals.SafeSqlLiteral(txtFirstName.Text, 2);
                    cmd.Parameters.Add("@lastName", SqlDbType.VarChar).Value = MyGlobals.SafeSqlLiteral(txtLastName.Text, 2);
                    cmd.Parameters.Add("@userName", SqlDbType.VarChar).Value = MyGlobals.SafeSqlLiteral(txtUserName.Text, 1);
                    cmd.Parameters.Add("@emailAddress", SqlDbType.VarChar).Value = MyGlobals.SafeSqlLiteral(txtEmailAddress.Text, 2);
                    cmd.Parameters.Add("@password", SqlDbType.VarChar).Value = MyGlobals.SafeSqlLiteral(txtPassword.Text, 1);
                    cmd.Parameters.Add("@isActive", SqlDbType.VarChar).Value = cbIsActive.Checked;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.ExecuteNonQuery();
                }
                con.Close();
            }
            rptGetAll.DataSource = dt;
            rptGetAll.DataBind();

            //Output Success Message
            Label lblErrorMessage = (Label)Master.FindControl("lblErrorMessage");
            new MyGlobals().DisplayUserMessage("success", "Administrator Updated!", lblErrorMessage);
            AdminForm.Visible = false;

But when the page is done the data isn't updated. What am I missing?

UPDATE: This is the Repeater_Load:

 protected void rptGetAll_Load(object sender, EventArgs e)
{
    DataTable dt = new DataTable();
    using (SqlConnection con = new SqlConnection(conString))
    {
        using (SqlCommand cmd = new SqlCommand("administratorGetAll", con))
        {
            using (SqlDataAdapter da = new SqlDataAdapter(cmd))
            {
                da.Fill(dt);
            }
        }
    }
    rptGetAll.DataSource = dt;
    rptGetAll.DataBind();
}
balexander
  • 23,131
  • 14
  • 45
  • 68
  • Can you post the code from rptGetAll_Load and Submit_Click? What are you setting the datasource to before you databind? – Abe Miessler Dec 16 '10 at 01:45
  • @Abe I added the OnLoad event and OnClick – balexander Dec 16 '10 at 01:55
  • That's not really all the onclick is it? – jcolebrand Dec 16 '10 at 02:03
  • I left out pointless stuff. Like a try and isValid – balexander Dec 16 '10 at 02:03
  • Can you elaborate on "the data isn't updated"? When you debug `rptGetAll_Load`, is data coming back - is `dt` populated? Also how are you data binding - inline with `DataBinder.Eval`, or with `ItemDataBound` event? I prefer the latter. Also i don't know why you have a `Load` event for the repeater. That code (binding of the repeater), should be on the button click event. – RPM1984 Dec 16 '10 at 03:07
  • @RPM When I edit or delete or add a row into the database and bind the repeater the info doesn't update until i refresh the page. – balexander Dec 16 '10 at 03:38

2 Answers2

1

You are binding the repeater with previous filled datatable dt. Refill the datatable with the latest data and bind it to repeater on the Save button click.

sam
  • 685
  • 7
  • 17
0

try different approach when adding your parameter values like this

cmd.Parameters.Add("@originalID", SqlDbType.VarChar);
cmd.Parameters["@originalID"].Value = hfID.Value;
hallie
  • 2,760
  • 19
  • 27
  • That causes this error 'An SqlParameter with ParameterName '@emailAddress' is not contained by this SqlParameterCollection.' When applied to other params – balexander Dec 16 '10 at 03:40
  • @Bry4n did you check that all your parameter names are correct? – hallie Dec 16 '10 at 04:49