c# - How to display elements only if SQLDataSource has rows -
i'm creating asp.net/c# page user enters id @ top of page, , when press submit, page posts , displays data. right now, data fields displayed @ times - when page loads , no search has taken place. not ideal when navigate menu multiview have made, errors come up. plus it's not practise.
is there way can hide these elements (they detailsviews , gridviews, plus multiview , menu) if sqldatasource blank? if search returned nor esults, or no query has been executed yet.
thanks
you surround these elements placeholder control , set placeholders visibility depending on whether there result display.
haven't used sqldatasource object before meet requirements suggest checking see if page has been posted in pageload method , if not hiding data controls. handle case of no results being returned adding method sqldatasource.selected event:
aspx:
<asp:placeholder id="myplaceholder" runat="server"> ....data controlds </asp:placeholder>
code behind:
protected void page_load(object sender, eventargs e) { if(!ispostback) { myplaceholder.visible = false; } } protected void sqldatasource1_selected(object sender, sqldatasourcestatuseventargs e) { myplaceholder.visible = e.affectedrows > 0; }
Comments
Post a Comment