How do I hide the DataPager if there is only one page of data?
In the DataPager events I have a asp:Button
when clicked it gets records.
Sometimes there will be only one record and I need to hide the pager if there is one record.
It could be done on postback but I don't know what property is for the page count.
There is a blog article on MSDN that covers this topic:
How to hide a DataPager control when there is only one page of data
One way of achieving this is to change the visibility of the control on the DataBound event of the ListView control. For example:
protected void ListView1_DataBound(object sender, EventArgs e) { DataPager1.Visible = (DataPager1.PageSize < DataPager1.TotalRowCount); }
In the example above, the DataPager is not inside the ListView control. If you place the DataPager inside the LayoutTemplate, then you have to tweak the code a little bit to find the control inside ListView. For example:
protected void ListView1_DataBound(object sender, EventArgs e) { DataPager pager = (DataPager) ListView1.FindControl("DataPager1"); pager.Visible = (pager.PageSize < pager.TotalRowCount); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With