473,804 Members | 3,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hide datagrid when it contains no rows

47 New Member
i want to know is there a way to check wherether is there data inside a datagrid and hide the datagrid when there isn't any.
for example i drag the datagridview from the toolbox and put it on the windows form, then in the coding i put :
"select * from table where balance <50";
it should display only items below 50, but when there isn't any(all items are above 50), i want to hide the datagrid....is there a way to do this?
Nov 21 '07 #1
4 1534
dip_developer
648 Recognized Expert Contributor
i want to know is there a way to check wherether is there data inside a datagrid and hide the datagrid when there isn't any.
for example i drag the datagridview from the toolbox and put it on the windows form, then in the coding i put :
"select * from table where balance <50";
it should display only items below 50, but when there isn't any(all items are above 50), i want to hide the datagrid....is there a way to do this?
what is the problem..? Datagrid has a visible property...make it to False when needed.....

when number of records ==0 make Datagrid.Visibl e=False......af ter that make it to true when needed......
Nov 21 '07 #2
wassssup
47 New Member
thats what i thought so also...but is there a way like to know if it is zero?
how you translate "number of records=0" into C#?
Nov 21 '07 #3
dip_developer
648 Recognized Expert Contributor
thats what i thought so also...but is there a way like to know if it is zero?
how you translate "number of records=0" into C#?
are you using datset or datareader..??? then they have a Count property .......you can have the total number of records by writing
myDataSet.Table s(0).Rows.Count or myDataReader.Re cordsAffected
Expand|Select|Wrap|Line Numbers
  1.  if (myDataSet.Tables(0).Rows.Count = 0) 
  2. {
  3. DataGrid1.Visible=False
  4. }
  5. else
  6. {
  7. DataGrid1.Visible=True
  8. }
  9.  
Nov 21 '07 #4
wassssup
47 New Member
are you using datset or datareader..??? then they have a Count property .......you can have the total number of records by writing
myDataSet.Table s(0).Rows.Count or myDataReader.Re cordsAffected
Expand|Select|Wrap|Line Numbers
  1.  if (myDataSet.Tables(0).Rows.Count = 0) 
  2. {
  3. DataGrid1.Visible=False
  4. }
  5. else
  6. {
  7. DataGrid1.Visible=True
  8. }
  9.  
this is it....thank you very much!!!
Nov 21 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
9930
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell (multi-select without modifier keys). I got that working fine, but I also wanted to keep rows selected after a sort, which I do by storing the row's id in an arraylist. The idea was to do the sort and then go back and re-select the rows with that...
3
2105
by: Newbie | last post by:
I am using a Datagrid to show the contents of a DataTable. But it seems like the Datagrid is not getting the contents of the Datatable when the button ( btnAddAnotherLaborCategory) is clicked. private void Page_Load(object sender, System.EventArgs e) { DataTable dataTable; DataColumn dataColumn; DataRow dataRow; dataTable = new DataTable("ratesTable");
2
17036
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of the columns of the data grid contains a DropDownlist. I managed to create this datagrid control as follows.
1
663
by: Machi | last post by:
Let say i select rows of records with 4 columns from Database and want to display the data in DataGrid (ASP.NEt Server Control) with one column which must be displayed in CheckBox layout. For the column (which contains checkbox), when i click the CheckBox in the Header of DataGrid, all the rows (for column which contains Checkboxes) must be checked. When i uncheck the checkbox in Header of DataGrid, all the rows of that column must be unchecked,...
2
2443
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via the Columns dialog box from the properties of the datagrid, on the left that contains a select button. So now, when you press the button the whole row is highlighted. Now, what I want to do is have the user highlight as many rows as they wish...
1
2370
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .. http://sf-f.org, weblog and search engine for fans and writers of
11
8086
by: jimstruckster | last post by:
I have a table with 10 rows, I want all rows except for the first to be hidden when the page first opens up. If the user puts a value in a text box in the first row then I want the second row to display. If they put a value in the text box in the second row then display the third row etc. etc. etc. to 10 rows. I'm pretty new to javascript, so I'm not to sure where to start. Any help would be great, thanks a lot.
1
2596
by: sp | last post by:
Hello I have a problem with the refresh performance in datagrid – when datagrid is being shown it is so slow that I can see one by one cells is drawn -datagrid contains about 35x40 of cells - they are generated through the odswierz_frekfencje() function (listed below)-
10
2975
by: amiga500 | last post by:
Hello, I have one basic simple question. When I have multiple records in the datagrid as follows: Code Product 1 Product 2 Product 3 11111 A B C 22222 D E F 33333 G H I 44444 J K L
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10571
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10317
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9143
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.