Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
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");
// ImageButton lbl_columname = (ImageButton)e.Row.FindControl("lbl_columname");

// int column = 0;
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;
//int row = e.Row.RowIndex + 1;
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;
//alert(gridlentgh);
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
Posted
Updated 14-Dec-13 22:44pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900