Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have this and it works to resize the rows in the gridview so that if there is an image, the row will be 10 and if there is an image the row height will be 100, but when there is an image, the image stays at 10 even though the row height is 100. How do I get the image to resize to 100 in the RowDataBound method?

The code:
<asp:gridview id="GridView1" runat="server" cssclass="table table-striped table-bordered
table-hover" emptydatatext="There are no data records to display."
="" width="99%" cellpadding="4" ondatabound="GridView1_DataBound" onrowdatabound="GridView1_RowDataBound">
<columns>
<asp:imagefield dataimageurlfield="IMAGEFILEPATH" controlstyle-width="100"
="" controlstyle-height="100" headertext="Image">

<headerstyle cssclass="gridheader" horizontalalign="Center"
="" verticalalign="Middle">



protected void GridView1_RowDataBound(object sender,GridViewRowEventArgs e) {
ResizeRows(e);
}
private void ResizeRows(GridViewRowEventArgs e) {
if (e.Row!=null) {
if (e.Row.RowIndex>0) {

if ((e.Row.Cells[1].Text==" ") || (e.Row.Cells[1].Text=="") || (e.Row.Cells[1].Text=="IMAGEFILEPATH")) {
e.Row.Height=10; // < this works
} else {
e.Row.Height=100; // < this works
}
}
}
}

What I have tried:

I tried:
Image img = e.Row.Cells[1].Controls[0] as Image;
if (img != null) {
img.Height=100;
}
Posted
Updated 19-Sep-19 3:32am

1 solution

You should find image in gridview row
Image image = GridView1.Rows[i].FindControl("image1") as Image;
//OR
Image img = (Image)GridView1.Rows(e.RowIndex).Cells(7).FindControl("image1");
 
Share this answer
 

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