Reputation: 49
I have a gridview and i want to disable the last 5 rows of it how can i do it??below code is not working
protected void gview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Enabled = e.Row.RowIndex <= 5; //for disabling last 4 rows
}
}
Upvotes: 0
Views: 1608
Reputation: 16708
protected void gview_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridView grid = sender as GridView;
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Enabled = grid.Rows.Count - e.Row.RowIndex > 4;
}
}
EDITED: Assuming your DataSource
is DataTable
, you can do something like this:
protected void gview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Enabled = dataTable.Rows.Count - e.Row.RowIndex > 4;
}
}
Upvotes: 1
Reputation: 123
i am assuming you are bnding dataset as datascurce to the gridview, so In RowDataBound bound add following code:
public static int count=0;
protected void grdview1_RowDataBound()
{
for(int i=0;i< ds.table[0].rows.count;i++)
{
count++;
if(count>(ds.table[0].rows.count-5))
{
e.Row.Enabled = false;
}
}
}
Upvotes: 0