Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

GridView Show Header

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ABHIJIT B - 06 Feb 2008 17:51 GMT
Hi,

I am using GridView in my web form and binding DataTable in code
behind file as given below.

gvUsersList.DataSource = dtUserList;
gvUsersList.DataBind();

If no records exists in DataTable GridView should display Coulmn
Header text.
In my case I have enabled following property,

gvUsersList.ShowHeader = true;

It is not working so tried following code which works for DataGrid but
not for GridView

                   dtUserList.Columns.Add(new DataColumn("LoginID",
typeof(string)));
                   dtUserList.Columns.Add(new DataColumn("FirstName",
typeof(string)));
                   dtUserList.Columns.Add(new DataColumn("LastName",
typeof(string)));

                   gvUsersList.DataSource = dtUserList;
                   gvUsersList.DataBind();
                   gvUsersList.ShowHeader = true;

Kindly help me where I am doing mistake or GridView property which
needs to be set.

Regards,
Abhijit B
Larry Bud - 06 Feb 2008 18:08 GMT
> Hi,
>
[quoted text clipped - 26 lines]
> Kindly help me where I am doing mistake or GridView property which
> needs to be set.

Unfortunately, that's how it works.  A GridView won't show the header
unless there is data.

There is an EmptyDataText property which will display in the event
there is no data.

I haven't tried it, but your datasource could add an empty row of data
in case there are no rows.
Mark Moeykens - 06 Feb 2008 19:51 GMT
I tried what Larry Bud wrote with the GridView.EmptyDataText property. It
seems like it only shows just that text with no header.  Probably used if you
want to give the user feedback if no data returned.  It looked like this:

gvUsersList.EmptyDataText = "No Data Returned";
gvUsersList.DataSource = dtUserList;
gvUsersList.DataBind();

and rendered out as:
<table cellspacing="0" rules="all" border="1" id="gvUsersList"
style="border-collapse:collapse;">
   <tr>
       <td>No Data Returned</td>
   </tr>
</table>

So I think you'll need to check for no rows and add an empty row:

if (dtUserList.Rows.Count == 0)
{
   dtUserList.Rows.Add(new object[] { "" });
}

gvUsersList.DataSource = dtUserList;
gvUsersList.DataBind();

So you will see the GridView show up with a blank row as well.

Hope this helps,
Mark Moeykens

> Hi,
>
[quoted text clipped - 29 lines]
> Regards,
> Abhijit B
ABHIJIT B - 08 Feb 2008 20:26 GMT
Hi Larry ,Mark,

Thanks for reply.I agree with Mark by adding dummy row without any
data we can show header text in GridView.The Problem in my code is
that I am using checkbox as Template column.If I addd blank row it
shows other fields blank but checkbox visible.

Kindly need assistance from anyone.Is it possible to solve using AJAX.

Regards,
Abhijit B

On Feb 6, 2:51 pm, Mark Moeykens
<MarkMoeyk...@discussions.microsoft.com> wrote:
> I tried what Larry Bud wrote with the GridView.EmptyDataText property. It
> seems like it only shows just that text with no header.  Probably used if you
[quoted text clipped - 64 lines]
>
> - Show quoted text -
Mark Moeykens - 08 Feb 2008 22:52 GMT
Ok, here's what you can do with the column that contains the checkbox.
Convert it to a template column. Then edit that column and give the checkbox
a meaningful name, say for example, "myCheckbox". Now, you want to make that
checkbox invisible if you added a blank row so you'll have to modify your
code to look something like this:

bool hideCheckBox = false;

if (dtUserList.Rows.Count == 0)
{
   dtUserList.Rows.Add(new object[] { "" });
   hideCheckBox = true;
}

gvUsersList.DataSource = dtUserList;
gvUsersList.DataBind();

((CheckBox)gvUsersList.Rows(0).FindControl("myCheckbox")).Visible =
hideCheckBox;

This could do it.
Mark Moeykens

> Hi Larry ,Mark,
>
[quoted text clipped - 78 lines]
> >
> > - Show quoted text -

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.