I have an listview and some codebehind with “OnItemCommand” commands doing some operation on my web-application. I want to add a entry out of the ListView to an MySql Database by clicking on an icon in that ListView.
The Listview is not that small and sometimes you have to scroll down to find the right entry. If I click one of those button the page makes a reload an scrolls to the top of the page. But I want the page to stay on the position. I don´t want to scroll down after every click to find where I was before.
Anyone some ideas how to do this?
Here is my codebehind of the ListView_OnItemCommand:
protected void addTextModuleList_OnItemCommand(object sender, ListViewCommandEventArgs e)
{
// read the ticket ID from e
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
if (String.Equals(e.CommandName, "insertTextModule"))
{
//connect to database
MySqlConnection con = new MySqlConnection();
con.ConnectionString = Helper.CONNECTION_STRING;
MySqlCommand cmd = null;
// insert new entrys for customer
cmd = new MySqlCommand();
con.Open();
cmd.Parameters.AddWithValue("@customer", Session["currentCustomerId"]);
int id = Convert.ToInt16(addTextModuleList.DataKeys[dataItem.DisplayIndex].Value.ToString());
cmd.Parameters.AddWithValue("@textModule", id);
cmd.Parameters.AddWithValue("@confirmationId", Session["currentConfirmationId"].ToString());
cmd.CommandText = "INSERT INTO linktextmodule (customer, textModule, confirmationID) " + "VALUES(@customer, @textModule, @confirmationId)";
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
//change the cssClass of the linkButton
LinkButton addTextModuleButton = e.Item.FindControl("addTextModuleButton") as LinkButton;
addTextModuleButton.CssClass = "insertTextModuleButton";
}
}
You can use this two methods to maintain the page position on postback
In the page declaration
Or in the web.config file.