Reputation: 24389
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();
}
Upvotes: 0
Views: 6099
Reputation: 685
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.
Upvotes: 1
Reputation: 2845
try different approach when adding your parameter values like this
cmd.Parameters.Add("@originalID", SqlDbType.VarChar);
cmd.Parameters["@originalID"].Value = hfID.Value;
Upvotes: 0