We help IT Professionals succeed at work.

DataGridView formatting in ASP.Net

allanmark
allanmark asked
on
1,029 Views
Last Modified: 2010-07-27
Greetings all,

I have placed a DataGridView on myPage. It displays with 3 columns - Column0, Column1, Column3; each displaying "abc" in the cells (and messing up my aligning of my control!).

My incoming data will always be of the same format. Through the columns collection I was able to create my own columns along with choice of titles (changing the HeaderText field).

How do I get rid of the Column0, Column1and Column2?  And when I view in browser I don't see my grid - is this because there is no data? Can I display the grid regardless of whether or not there is data or even if the grid is not connected to a datasource?

In advance, thanks!

allanmark
Comment
Watch Question

Munawar HussainPrincipal Software Engineer
CERTIFIED EXPERT

Commented:
Select GridView which you have placed .. it will give you option go to property pages (a small arrowhead at top right corner of gridview appears)

Click on Edit Column and in the next dialogue you will see a checkbox at left bottom corner .. uncheck that (Enable auto generate columns)

Munawar HussainPrincipal Software Engineer
CERTIFIED EXPERT

Commented:
you may do it in ASPX (HTML gridview tag by adding
autogeneratecolumns ="false" in the in the gridview tag >

for reference
http://authors.aspalliance.com/aspxtreme/sys/web/ui/webcontrols/gridviewclassautogeneratecolumns.aspx

Author

Commented:
Fantastic!!  So simple when you know how (or in my case when someone else knows how!!)

If I could come back to this part: "Can I display the grid regardless of whether or not there is data ? (both at runtime and when I "View In Browser"to see how my page really looks).

... Have a bit more to ask, if you don't mind ... have upped the points to cover that (not sure if this is acceptable or if I should close this one and open another).

(1)    Having done as you suggested, I now have just my headings. If I click on the control and drag to
        size  to my specifications, I am left with what appears to be an enlarged heading row and several
        really small rows underneath (with the overall size being what I want). Does this mean that my
        heading row has been resized or is it just the way it displays?

(2)   Do you know of a good tutorial / link to a video -- I think I'll be using this grid a lot and could efinitely do with such.

Many thanks.
   allanmark

Munawar HussainPrincipal Software Engineer
CERTIFIED EXPERT

Commented:
few free videos you may find here
http://www.learnvisualstudio.net/content/videos/vwd2k5ee_08_working_with_the_gridview_and_formview.aspx

for sites .. there are sites having alot of articles about GRIDVIEW
http://www.gridviewguy.com/Articles.aspx

http://www.gridviewgirl.com/GridViewGirl/

alot of good working examples for all .net platform (i have given link specific to asp.net you may brows this site for all other too)

Thanks
http://samples.gotdotnet.com/quickstart/aspplus/

Author

Commented:
Sorry for only ocming back now  -- there's just so much stuff in the sites you posted (hoping to do some more surfing later tonight.

As per my previous post, I tried to find answers to these questions, using the sites that you provided - no luck.

1.      Can I display the grid regardless of whether or not there is data ? (both at runtime and when I
         "View In Browser"to see how my page really looks).
2.      DGW: Having done as you suggested, I now have just my headings. If I click on the control and
         drag to size  to my specifications, I am left with what appears to be an enlarged heading row and
        several really small rows underneath (with the overall size being what I want). Does this mean that
        my heading row has been resized or is it just the way it displays?

Can you suggest anything?

Thanks
  allanmark
Munawar HussainPrincipal Software Engineer
CERTIFIED EXPERT

Commented:
1- what meant by displaying grid without data?
if you have have set headers of columns that means it will display headers and 5 rows in design mode (when you are working on forms in editor ..VS)
but if you run in browser then you will see only headers ..

2-when you drag to make it wide .. definitly available columns will expand to fill the new width of gridview
if you want to make each column of a specific size then
IN ASPX you may add itemStyle of you can set it in GridView designer too

like this
 <asp:BoundField DataField="Salary" DataFormatString={0:d} HeaderText="Salary" >
                    <ItemStyle Width="400px" />
   </asp:BoundField>

Author

Commented:
Thanks for your patience!

1.  Displaying grid without data -- Sorry, poorly explained on my part. What I should have set was that I
     ran the browser to see how my page would look and the grid is not displayed at all - no headings,
     nothing!

    This led me to the 2nd part  which was wondering if, at runtime, there was no data if the grid would  
    still be displayed --- I guess your reply "but if you run in browser then you will see only headers "
    answers that - I should at least seethe headers!


2.  Sorry - again, poorly explained on my part. What I should have said was that I drag the bottom of the
     grid down, to fill up the available page space. The 5 rows (which I now understand  - thankyou!!)
     increased only fractionally in size, whilst the heading row expanded seriously [now,  in design
     mode, I have a  header row of 60mm and the five data rows of 4mm -- approximate estimations
     based on screen appearance]. If this is normal (from what you wrote, I think that it is) - OK - I just
     want to make sure that I haven't made another "Idiot User Error".
 
Once again, thanks for everything.
Principal Software Engineer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
As always, helpful - thankyou!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.