Solved

Hide server controls if SQLDatasource empty or NULL

Posted on 2014-03-12
6
524 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

635 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