allanmark
asked on
DataGridView formatting in ASP.Net
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
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
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
autogeneratecolumns ="false" in the in the gridview tag >
for reference
http://authors.aspalliance.com/aspxtreme/sys/web/ui/webcontrols/gridviewclassautogeneratecolumns.aspx
ASKER
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
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
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/
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/
ASKER
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
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
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>
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>
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
As always, helpful - thankyou!
Click on Edit Column and in the next dialogue you will see a checkbox at left bottom corner .. uncheck that (Enable auto generate columns)