Solved

Proper way to Display a empty row in a gridview

Posted on 2006-06-16
4
720 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
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:kGenius
Comment Utility
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
Comment Utility
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 250 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now