IncubusJax
asked on
Gridview in ASP.NET VB and a label - Pretty Noob stuff.
Hi everyone.
I have a stupid question I was hoping someone would help with. I'm tired and just can't think anymore.
I have an website with three drop down lists that are attached to an Access Database.
I have a gridview that holds an SQL Statement to query the database based on the DDL controls.
SO if you select location as Florida in the drop down, the statement reads: "SELECT * FROM table WHERE location = Florida"
Make Sense?
If you hit a button, the page refreshes, the SQL Statement Runs and a gridview of the query results is displayed.
Here's my question.
When that GridView displays I have a hidden label called "lblStatusSearch" that I want to remain blank (and therefore hidden).
BUT when the gridview DOES NOT display (ie the SQL query yields no results I want that label to say "Try Again"
I know the VB code for the label, I'm not quite THAT new (lblStatusSearch.Text = "try again")
I just don't know where to put the IF statement to cause it to appear!
Here's what I got. Let me know if you need more. Thanks
I have a stupid question I was hoping someone would help with. I'm tired and just can't think anymore.
I have an website with three drop down lists that are attached to an Access Database.
I have a gridview that holds an SQL Statement to query the database based on the DDL controls.
SO if you select location as Florida in the drop down, the statement reads: "SELECT * FROM table WHERE location = Florida"
Make Sense?
If you hit a button, the page refreshes, the SQL Statement Runs and a gridview of the query results is displayed.
Here's my question.
When that GridView displays I have a hidden label called "lblStatusSearch" that I want to remain blank (and therefore hidden).
BUT when the gridview DOES NOT display (ie the SQL query yields no results I want that label to say "Try Again"
I know the VB code for the label, I'm not quite THAT new (lblStatusSearch.Text = "try again")
I just don't know where to put the IF statement to cause it to appear!
Here's what I got. Let me know if you need more. Thanks
Imports System.Data.SqlClient
Partial Public Class frmClient
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnReset.Click
Response.Redirect("~/frmClient.aspx")
End Sub
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
End Sub
Protected Sub gvResults_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles gvResults.SelectedIndexChanged
If gvResults.Visible Then
lblStatusSearch.Text = ""
Else
lblStatusSearch.Text = "Try Again"
End If
End Sub
Protected Sub tblUsersGridView_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles tblUsersGridView.Selecting
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i didnt say use the rowdatabound event, i said put that code in the gridview databound event. It always fires when the gridview goes through the binding cycle. I like to place the code here because no matter what caused the bind (manual force, sorting, paging) this event will fire. But I agree with the emptyTemplate, if you can, use that. I based my response assuming the use of the label was part of your requirements.
ASKER
Thanks everyone. Actually, you were all correct and led me to my solution. I ended up just using the empty data text property of the gridview but I tested and considered all.
You guys are great!
Thanks
Mark
You guys are great!
Thanks
Mark