Solved

Hide server controls if SQLDatasource empty or NULL

Posted on 2014-03-12
6
494 Views
Last Modified: 2014-03-29
For a very long time I have tried to figure out how to hide a control like a asp textbox or asp dropdownlist if a sqldatasource is or is not a certain value. I want to do this without using asp.net server controls like gridview, detailview, datalist..etc. I simply want to do something like hide a control if the sqldatasource = 0 or no data return.

The following is as far as I have gotten but I need help. I am not even sure if this is correct.

Protected Sub StepDataShowArticle_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles StepDataShowArticle.Selecting
       
  End Sub

StepDataShowArticle would be the sqldatasource.

I am not very good at coding and if you can help me please provide a full sample. I appreciate the effort but sending me to yet another link will not help me very much. Thank you in advance.
0
Comment
Question by:derrekdeveloper
  • 3
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
Camillia earned 400 total points
Comment Utility
Check if StepDataShowArticle has any data in it. Use "count" property

StepDataShowSArticle.Count == 0

if it's zero, hide the control:  set the visible property to false.

Is this what you're looking for? show more code, if you can.
0
 

Author Comment

by:derrekdeveloper
Comment Utility
That's all the code this hack could come up with Lol! I'm sure it's what I'm looking for but I don't know where or how to write the code correctly. I will google .count==0 to see what I can find.
0
 

Author Comment

by:derrekdeveloper
Comment Utility
Would I do something like this? I'm really not sure of the syntax.

Protected Sub StepDataShowArticle_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles StepDataShowArticle.Selecting
       
If StepDataShowSArticle.Count == 0
    newsarticles.visible = False
  Else news articles.visible = True
End If
 
End Sub
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 7

Expert Comment

by:Camillia
Comment Utility
What is your code in aspx page?
0
 
LVL 7

Assisted Solution

by:Camillia
Camillia earned 400 total points
Comment Utility
And, this is a good site to look at examples. You can actually run their examples and look at the code.

http://quickstarts.asp.net/quickstartv20/default.aspx
0
 
LVL 26

Assisted Solution

by:Alan Warren
Alan Warren earned 100 total points
Comment Utility
Hi derrekdeveloper,
The data controls you mentioned support EmptyDataTemplates, which will automatically be displayed the if the DataSource to which the Form/GridView/DetailsView etc... is bound to returns no records.
<EmptyDataTemplate>No results found matching the criteria. Please try another search.</EmptyDataTemplate>

Open in new window

Respectfully yours,
Alan
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now