Hello Everyone,
I am facing one problem with Gridview. Kindly solve this issue. i.e I am calling javascript functions from gridview RowDataBound event for column highlighting & sum.
it's working fine for now.
Now the problem is i need to sort the gridview based on selected column(highlighted column)
Please suggest me how to sort the gridview eventhough javascript functions are calling.
here i am attaching my gridview code & javascript code.
gridview code :
protected void gv_temp_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int column = 0;
int row = e.Row.RowIndex + 1;
foreach (TableCell cell in e.Row.Cells)
{
if (column > 0)
{
cell.Attributes.Add("onmousedown", "mousedowncell(" + row + "," + column + ");");
cell.Attributes.Add("onclick", "mouseclickcell(" + row + "," + column + ");");
cell.Attributes.Add("onmouseup", "mouseupcell(" + row + "," + column + ");");
cell.Attributes.Add("onmouseover", "mouseovercell(" + row + "," + column + ");");
}
else
{
cell.Attributes.Add("onclick", "mouseclickrow(" + row + ");");
}
column++;
}
e.Row.Cells[0].Visible = true;
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl_columname = (Label)e.Row.FindControl("lbl_columname");
int row1 = e.Row.RowIndex + 1;
if (lbl_columname != null)
{
lbl_columname.Text = "R" + row1;
lbl_columname.ForeColor = System.Drawing.Color.White;
}
}
if (e.Row.RowType == DataControlRowType.Header)
{
int column = 0;
foreach (TableCell cell in e.Row.Cells)
{
if (column > 0)
{
cell.Text = "C" + column + "<hr>" + cell.Text;
cell.Attributes.Add("onclick", "mouseclickcolumn(" + column + ");");
}
else
{
cell.Attributes.Add("onclick", "mouseclickSelectAll();");
}
column++;
}
}
}
javascript code :
function mouseclickcolumn(c) {
reset();
clear_values();
clearbg();
var grid = document.getElementById("<%= gv_temp.ClientID %>");
var gridlentgh = grid.rows.length;
for (j = 1; j < grid.rows.length; j++) {
grid.rows[j].cells[c].style.backgroundColor = "YELLOW";
}
rowstart = 1;
rowend = grid.rows.length - 1;
columnstart = c;
columnend = c;
for (i = 0; i < grid.rows.length; i++) {
if (grid.rows[i].cells[c].innerHTML == "" || grid.rows[i].cells[c].innerHTML == " " || grid.rows[i].cells[c].innerHTML == null) {
lastcellRow = i - 1;
break;
}
}
lastcellColumn = c;
caculate();
display_values();
reset();
};
Thanks in Advance
Satish Chandragiri