Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 561
  • Last Modified:

Hide server controls if SQLDatasource empty or NULL

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
derrekdeveloper
Asked:
derrekdeveloper
  • 3
  • 2
3 Solutions
 
CamilliaCommented:
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
 
derrekdeveloperAuthor Commented:
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
 
derrekdeveloperAuthor Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
CamilliaCommented:
What is your code in aspx page?
0
 
CamilliaCommented:
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
 
Alan WarrenCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now