I want to set visibility of a div according to the size of grid which are on the same page; grid is loaded when the page is opened How can I do this ? I wrote following js but took errors.
<asp:GridView ID="grid" runat="server" AutoGenerateColumns="false" ShowHeader="false" ShowFooter="false"
CssClass="table table-bordered table-condensed"
EmptyDataText="Kayıtlı İş Tecrübesi Bilgisi Bulunmamaktadır."
OnRowDataBound="OnGridRowDataBound" OnRowCommand="OnGridRowCommand" OnRowCreated="OnGridRowCreated"
DataKeyNames="KAYITNO"
RowStyle-CssClass="ozgecmis-grid-row" AlternatingRowStyle-CssClass="ozgecmis-grid-row-alternate" SelectedRowStyle-CssClass="ozgecmis-grid-row-selected">
<Columns>
<asp:TemplateField ItemStyle-CssClass="ozgecmis-data-key">
<ItemTemplate>
<asp:Button runat="server" ID="dataKeyButton" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"KAYITNO") %>' Visible="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="ozgecmis-data-command" ItemStyle-VerticalAlign="Middle">
<ItemTemplate>
<a href="#" class="btn btn-small btn-info">Seç</a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="ozgecmis-data-text">
<ItemTemplate>
<%#FormatData(Eval("ISYERIUNVAN"),Eval("GIRISTARIHSTR"),Eval("CIKISTARIHSTR"),Eval("ISTANIMI"),Eval("SEKTOR"),Eval("POZISYON"),Eval("MESLEK"),Eval("MESLEKUZMANLIK")) %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
$( "#grid" ).on( "load", function() {
var gridView = document.getElementById("<%=grid.ClientID %>");
var rows = gridView.getElementsByTagName("tr")
if (rows.length>0){
isTecrubesiBos.Visible = true;
}
} );
2
Answers
Do that check WHEN you load the grid and set its data source.
So, say this:
And now in code, you can do this:
So, we get/see this:
So, since the data source has a row count > 0, then we at that point in time are free to set the visible of the text box in question.
Your
grid
anddiv
both are server side control, they change thereid
when page load. So after page load meansdocument.ready
show yourdiv
viadocument.getElementById("<%= isTecrubesiBos.ClientID %>").style.display = 'block';
.Example:
If any case, need to hide
div
: