On the last page if If i have 1 or 2 items the header and the pager stretch too much.. it all autosizes..
My gridview height is not set, But I set the row property to 30pixels..still doesnt prevent the autosizing..
I was searching for a solution over the net..and the closest solution that i found was that:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(this.GridView1.Rows.Count<this.GridView1.PageSize)//I need here to grab the last page..// do something like e.Row.... and last page.
{
foreach (GridViewRow tt in GridView1.Rows)
{ tt.Height = Unit.Pixel(30); }
}
}
It isnt correct.... what i need to happen, is when the user clicks the last page the height should be modified to to 30 pixels.
Any other ideas on how to prevent autosizing on the last page are welcome!!
To find out if you're on the last page of a paged grid and then change row heights, use the following (tested) code:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (GridView1.PageIndex == GridView1.PageCount - 1)
{
e.Row.Height = Unit.Pixel(30);
}
}
Related
Basically everytime I load or reload the page it treats every row in my gridview as if it has been clicked, thus calling the function in the codebehind related to it once for every row which at the time is set to 13 rows max. Thanks for any help.
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Attaching one onclick event for the entire row, so that it will
// fire SelectedIndexChanged, while we click anywhere on the row.
e.Row.Attributes["onclick"] =
ClientScript.GetPostBackClientHyperlink(this.GridView2, "Select$" + e.Row.RowIndex);
}
Console.WriteLine("");
}
I have a GridView and using DataSet to Bind that. And Gridview Height set to autoHeight;
Suppose I have 3 rows in My GridView, After bind I want to fetch the row height of each row.
I know that I can set the RowHeight dynamically by
GridView1.RowStyle.Height = 40;
But I want somthing like my be
int height=GridView1.Rows[0].Height;
I can manage my logic of the above code using for or any.....
If you don't want to use a foreach loop, then you can use a RowDataBound event to find the height of each row.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
ViewState["rowHeightList"] = new List<decimal>();
}
}
if (e.Row.RowType == DataControlRowType.DataRow) {
decimal currentRowHeight = Convert.ToDecimal(e.Row.Height);
List<decimal> rowHeightList = (List<decimal>)ViewState["rowHeightList"];
rowHeightList.Add(currentRowHeight);
ViewState["rowHeightList"] = rowHeightList;
}
I am trying to get gvProducts row count.
I have tried the below code but it give insufficient result.
protected void gvProducts_RowCommand(object sender, GridViewCommandEventArgs e)
{
string commandName = e.CommandName.ToString().Trim();
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
if (row.Controls.Count == 1)
{
//my code
}
}
You want total rows in Gridview? Use Count property:
gvProducts.Rows.Count
Update:
To find the rows count of nested gridview, you can use the RowDataBound event of parent gridview:-
protected void gvProductsParent_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView gvProducts = (GridView)e.Row.FindControl("gvProducts ");
int count = gvProducts.Rows.Count;
}
}
Please note this event will fire for each row present in your parent gridview this the count will change according to each row.
I have buttons in one Column called Type. When the user clicks on the button it should be disabled. This works fine in the first page but it doesnt on the second,third,fourth pages.
I have 10 rows in my page and e.CommandArgument gets the row number.
I believe the buttons are populated in the gridview from 0 to 9 and e.CommandArgument is 1-10. Thats why I have (e.CommandArgument) - 1 and it works find in the first page.
The things that in the second page the next buttons are again 0-9 but my e.CommandArgument is 11-20. Any ideas?
protected void GridViewType_RowCommand(object sender, GridViewCommandEventArgs e)
{
Button btnVote = (Button)GridViewType.Rows[Convert.ToInt32(e.CommandArgument) - 1].FindControl("btnVote");
btnV ote.Enabled = false;
}
try the following
protected void GridViewType_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = (GridViewRow)(e.CommandSource);
Button btnVote = (Button)row.FindControl("btnVote");
btnVote.Enabled = false;
}
kindly check this :
want to Find Control in gridview on RowCommand event
I have a Gridview that auto generates columns...
The problem is, the data type are all imageurl.
when the gridview populates, the url is in label format.
I could define them as templatefield which works, but the requirement is to auto generate.
I read on MSDN of this, but i dont know how to proceed from there
private void BUChecker_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
}
You can alter this on its TemplateFields. See GridView controls'.
see this for your reference.
I think you use RowDataBound as follows In case you don't want to use template field
protected void RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
//find your cell suppose it is Cell 0
string imgUrl=e.Row.Cells[0].Text;
Image img = new Imge();
img.ImageUrl =imgUrl;
e.Row.Cells[0].Controls.Add(img);
}
}