Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I hide a button on page if datagrid empty

Posted on 2007-11-29
6
Medium Priority
?
397 Views
Last Modified: 2013-11-26
I want to not display a button on a page if my datagrid is empty.

I just need to know hw to tell if the gridview is empty.


eg

If gridview1(whats the code to say it empty)

then
button1.visible = false
0
Comment
Question by:Ed
[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
  • 4
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
j-w-thomas earned 750 total points
ID: 20373642
if gridview.Items.count = 0 then
        button1.visible = false
else
        button1.visible = true
end if

John
0
 
LVL 3

Assisted Solution

by:j-w-thomas
j-w-thomas earned 750 total points
ID: 20373656
You can also add on to hide the datagrid column headers as well, just to 'clean' up the page look.

if gridview1.Items.count = 0 then
        button1.visible = false
        gridview1.visible = false
else
        button1.visible = true
        gridview1.visible = true
end if

hth,

John
0
 

Expert Comment

by:Edjones
ID: 20373673

Thanks

does not work on

 Protected Sub GridView1_RowDataBound

what should I use?
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 3

Expert Comment

by:j-w-thomas
ID: 20373704
Is it after the bind to the datagrid?

'/// first the bind ///
gridview1.dataBind()

'/// then the check for rows ///
if gridview1.Items.count = 0 then
        button1.visible = false
        gridview1.visible = false
else
        button1.visible = true
        gridview1.visible = true
end if

If not can you post the entire sub
0
 

Expert Comment

by:Edjones
ID: 20374415
I'm using a separe code file



    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If GridView.Items.count = 0 Then
            Button1.Visible = False
        Else
            Button1.Visible = True
        End If
 
 
    End Sub

Open in new window

0
 
LVL 3

Expert Comment

by:j-w-thomas
ID: 20378787
I thought that you had the entire sub finished except for this part. Is that true? I understand that you are a beginner on this subject, but it defintely needs more than that to work. Also you have it for a row command, is that waht you mean?

Try the code below and add in the correct select statement for your database and the connection string.

This is set up in a very simple format...
Sub BindData(s As Object, e As EventArgs)
 
Dim strSQLStatement As String = "SELECT * FROM TABLE_NAME"
Dim objCmd As OdbcCommand '/// or this needs to be OleDbCommand depending on your database
Dim objRdr As OdbcDataReader '/// or OleDbDataReader
'/// make sure that you have your connection string declared ///
	try		
		objCmd = New OdbcCommand(strSQLStatement,objConn)
		objConn.Open()
		objRdr = objCmd.ExecuteReader()
		dgDataGrid1.DataSource = objRdr
		dgDataGrid1.DataBind()
		objRdr.Close()
		objConn.Close()
		
		if dgDataGrid1.Items.Count = 0 then
			dgDataGrid1.Visible = false
			button1.visible = false
		else
			dgDataGrid1.Visible = true
			button1.visible = true
		end if
 
		if objConn.State = ConnectionState.Open then
			objConn.Close()
		end if
				
		catch objEx As Exception
				
			'/// you can put a custom error type message here ///
 
					
		finally
				
				if objConn.State = ConnectionState.Open then 
					objConn.Close() 
				end if
 
		end try
 
End Sub

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

704 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