Solved

Hide server controls if SQLDatasource empty or NULL

Posted on 2014-03-12
6
509 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
ID: 39925385
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
ID: 39925450
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
ID: 39925455
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 7

Expert Comment

by:Camillia
ID: 39925457
What is your code in aspx page?
0
 
LVL 7

Assisted Solution

by:Camillia
Camillia earned 400 total points
ID: 39925462
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
ID: 39963079
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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