On Feb 14, 3:22 pm, "Cindy Lee" <cindy...@hotmail.comwrote:
When I click the button it works and I can see all the rows, but I don't get
the right sort order:
This is on the page load, so the sorting
DataTable statetable = StateDataSet.Tables[0];
GridView2.DataSource = statetable;
GridView2.DataBind();
Here's by button click function
protected void Button1_Click(object sender, EventArgs e)
{
GridView2.AllowPaging = false;
GridView2.DataBind();
Button1.Visible = false;
Button2.Visible = true;
}
Cindy,
Bind to a view to sort your grid items:
StateDataSet.Tables[0].DefaultView.Sort = "FieldNameHere ASC"; //or
DESC
GridView2.DataSource = StateDataSet.Tables[0].DefaultView;
GridView2.DataBind();
Now, to display top 5, you can either do a postback, filter your view
and rebind, or try some javascript to hide the rest
of the grid items:
<script language="javascript" type="text/javascript">
function filterGrid ()
{
var myForm = document.forms["FormNameHere"];
var table = document.getElementById("GridNameHere");
if (table == null)
return;
//hide the rest of grid item except for the top 5 (grid index
starts at 0)
for (var r = 5; r < table.rows.length; r++)
{
table.rows[r].style.display = 'none';
}
}
</script>
HTH,
Quoc Linh