Reputation: 1957
I have a repeater on my page being populated on page load
con.Open();
SqlDataReader postView = cmd.ExecuteReader();
topicView.DataSource = postView;
topicView.DataBind();
And then I have a section to add a post. What I want it to do is when the user presses add, it reloads the page and displays the updated repeater. However it's not doing this
Everyone has said just reload the databind, except that isn't working as the original databind is in the page load, and the new databind is in a protected void button click.
Can anyone tell me how to do this, or do I just need to place ALL the connection, datasource ad databind info in the button click code?
Upvotes: 1
Views: 7255
Reputation: 35582
you can resolve it like this . create a method
private void Bind()
{
con.Open();
SqlDataReader postView = cmd.ExecuteReader();
topicView.DataSource = postView;
topicView.DataBind();
}
now you can use it anywhere on the page where you need to reload the repeater.
Upvotes: 2
Reputation: 3274
you can create a function that can be call everytime Button click event fire
Private void BindRepeater()
{
con.Open();
SqlDataReader postView = cmd.ExecuteReader();
topicView.DataSource = postView;
topicView.DataBind();
}
Protected Button_Click(object as sender , EventArgs e)
{
//call the function to populate the repeater with the updated records
this.BindRepeater();
}
Upvotes: 3