I implemented clickable rows in datagrid using ajax. The problem is, when I click the row in the Results page I redirect to another page to view the data. In that page I have an "update" button that I can update the data in the table in the DB and when I click it, I redirect back to the Results page and then click the same row again to view its details, the data isnt updated and its still old data. The thing is, the data is being updated in the table in the DB, its like the page is saving the old data he brought and using it and I dont know how to tell him to bring new data.
Here is the code to make clickable rows:
protected void pendingGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "return GetDataUsingAJAX(" + e.Row.RowIndex + ",'pending');");
e.Row.Attributes.Add("style", "cursor:hand");
}
}
here is the javascript of Results page:
function GetDataUsingAJAX(row, table) {
obj = new XMLHttpRequest();
if (obj != null) {
obj.onreadystatechange = RedirectToViewDetails;
obj.open("GET", "Results2.aspx?row=" + row + "&table=" + table, true);
obj.send(null);
}
return false;
}
function RedirectToViewDetails() {
if (obj.readyState == 4) {
if (obj.status == 200) {
var retval = obj.responseText.split("&");
window.location = "YellowCardStart.aspx?mode=" + retval[0] + "&cntct=" + retval[1] + "&strtDate=" + retval[2] + "&endDate=" + retval[3] + "&strtTime=" + retval[4] + "&endTime=" + retval[5] + "&tools=" + retval[6] + "&id=" + retval[7] + "&table=" + retval[8] + "&bldng=" + retval[9] + "&loc=" + retval[10] + "&devTool=" + retval[11] + "&cmpny=" + retval[12] + "&phn=" + retval[13] + "&lssApp=" + retval[14] + "&ehsApp=" + retval[15] + "&cmnts=" + retval[16] + "&created=" + retval[17]; }
else {
alert("Error retrieving data!");
}
}
}
And here is the code in page_load of Results:
if (Request.QueryString["row"] != null)
{
Response.Clear();
if (Request.QueryString["table"] != null)
{
DataTable dt = new DataTable();
if (Request.QueryString["table"] == "fa")
{
dt = DataAccessLayer.selectFromTable(Int32.Parse(activeFAGrid.Rows[Int16.Parse(Request.QueryString["row"])].Cells[0].Text), "active");
Response.Write(dt.Rows[0][1].ToString() + "&" + dt.Rows[0][2].ToString() + "&" + dt.Rows[0][3].ToString() + "&" + dt.Rows[0][4].ToString() + "&" + dt.Rows[0][5].ToString() + "&" + dt.Rows[0][6].ToString() + "&" + dt.Rows[0][7].ToString() + "&" + dt.Rows[0][0].ToString() + "&" + "active" + "&" + dt.Rows[0][8].ToString() + "&" + dt.Rows[0][9].ToString() + "&" + dt.Rows[0][10].ToString() + "&" + dt.Rows[0][11].ToString() + "&" + dt.Rows[0][12].ToString() + "&" + dt.Rows[0][13].ToString() + "&" + dt.Rows[0][14].ToString() + "&" + dt.Rows[0][15].ToString() + "&" + dt.Rows[0][16].ToString());
}
Response.End();
}
}
the SelectFromTable function retrieves the data from the DB.
Help will be really appriciated, I am really lost.
Thanks in advance,
Greg
I think you will find that your browser is caching the response from your AJAX call, try using POST instead of GET for your AJAX call.