Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Proper way to Display a empty row in a gridview

Posted on 2006-06-16
4
Medium Priority
?
729 Views
Last Modified: 2012-05-05
I am using gridviews in my application and they have bound columns and the datasource is a objectdatasource.  When no records are returned I would like the gridview to display an empty row (with column headers etc.).  From what I can tell the only way to accomplish this, without using an image within a EmptyDataTemplate or the worthless EmptyDataText property, is to create an arraylist and toss an empty oject into it and use that for the datasource. After the grid is bound I then have to blank out some cells because they have some default text in them (dates, boolens etc..).   Then I get my empty row.

Is there an easier way to accomplish what I am looking for?  Or I am I stuck just doing it like this?  The reason why I would like to change it is because there is no way to force the objectdatasource to give me a record count (that I can find anyway) before it is bound.  So I have to bind the objectdatasource to the grid then check the grid's Row.Count property and then if it is zero bind it again to my empty arraylist.  Kinda wasteful.  

Any Ideas?
0
Comment
Question by:dprimeus
[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
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:kGenius
ID: 16926083
Is your objectdatasource an arraylist?
You can probably check before returning the arraylist if it is not null or length > 0. Else return an arraylist of your object with one item having the default empty values (nulls or empty strings, ...)

ie
if (myArrayList.Count > 0 || myArrayList != null) {
  return myArrayList;
} else {
  _myObj=new YourObject("", "", null, null);
  myArrayList.Add(myObj);
  return myArrayList;
}

hope this 'll help
kGenius
0
 
LVL 1

Author Comment

by:dprimeus
ID: 16926832
The ObjectDataSource class points to a class and that class has a procedure that returns all of the records from a table.  I was going to just have the class return an arraylist with an empty object when there are no records to return like you suggest (that was my first thought as well) but I do not want my classes returning an arraylist that has a count of 1 but does not actually have anything in it.  I think that could bite me later when I use the class for something else.  I would then have to determin if it only returns one row if that row is an empty row or a real row.  I think that could cause me more problems in the future in other places that class is used.

Nice thinking though.

I could create a special Grid procedure in my classes for returning the results for grids.  And have it call the normal method for return them then have it put the empty object in the arraylist.  That way I could still use the "normal" procedure for everything else.  Makes the class kinda clunky but that would be better than binding all the grids twice.

So I would have two:
Customer.GetCustomers
Customer.GetCustomersGrid (calls GetCustomers but puts a blank object in there if it is empty)

0
 
LVL 7

Accepted Solution

by:
kGenius earned 750 total points
ID: 16928641
Can't you check in Customer.GetCustomersGrid for an arraylist with value null (or Noting in vb)?
Can you provide the code you have? It can make things more clear, where you want to go to...

kGenius
0
 
LVL 1

Author Comment

by:dprimeus
ID: 16930250
Right that is what I am talking about doing.  I am going to just create another method GetCustomersGrid and it will call GetCustomers and check if the arraylist is empty.  If it is then it will put a empty Customer object in the arraylist.  My ObjectDataSource will just use the GetCustomersGrid method.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

609 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