Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Loading Gridview in code

Reply
Thread Tools

Loading Gridview in code

 
 
GaryDean
Guest
Posts: n/a
 
      07-25-2006
I'm trying to load a GridView up with data manually, in code. I'm not using
any datasource. Using this code....

ArrayList myRowArrayList;
GridViewRow myGVR = new GridViewRow(0,0,DataControlRowType.DataRow,
DataControlRowState.Normal);
TableCell myCell = new TableCell();
TextBox myTextbox = new TextBox();
myTextbox.Text = "hello world";
myCell.Controls.Add(myTextbox);
myGVR.Cells.Add(myCell);
myRowArrayList.Add(myGVR);
GridViewRowCollection myCollection = new
GridViewRowCollection(myRowArrayList);
//How do I attach this collection to my GridView?

I can't see how to add the new row I created to the GridView. There is no
GridView.rows.add method. How is a row added to a gridview or how is the
GridViewRowcollectin attached to the Gridview?
--
Regards,
Gary Blakely


 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      07-26-2006
Hi Gary,

Perhaps you could explain what your ultimate goal is?

It looks like you're trying to use a gridview to create a table of some sort
without binding to data. Its the data the makes the GridView add rows.

Ken
Microsoft MVP [ASP.NET]

"GaryDean" <> wrote in message
news:...
> I'm trying to load a GridView up with data manually, in code. I'm not
> using any datasource. Using this code....
>
> ArrayList myRowArrayList;
> GridViewRow myGVR = new GridViewRow(0,0,DataControlRowType.DataRow,
> DataControlRowState.Normal);
> TableCell myCell = new TableCell();
> TextBox myTextbox = new TextBox();
> myTextbox.Text = "hello world";
> myCell.Controls.Add(myTextbox);
> myGVR.Cells.Add(myCell);
> myRowArrayList.Add(myGVR);
> GridViewRowCollection myCollection = new
> GridViewRowCollection(myRowArrayList);
> //How do I attach this collection to my GridView?
>
> I can't see how to add the new row I created to the GridView. There is no
> GridView.rows.add method. How is a row added to a gridview or how is the
> GridViewRowcollectin attached to the Gridview?
> --
> Regards,
> Gary Blakely
>
>



 
Reply With Quote
 
 
 
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      07-26-2006
Hi Gary,

Thank you for your post.

I believe this post is a further step during your adventure of learning
GridView,

Based on my understanding, both DataGrid and GridView are designed to work
with DataBinding scenario.

Can I ask why you want to manually load data into the GridView?

Also, could you please telling me how did you load data into DataGrid as
you described in your another post about DataGrid vs GridView?



Regards,
Walter Wang (, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
GaryDean
Guest
Posts: n/a
 
      07-26-2006
Walter, thanks for responding.

I'll try to answer you both... (by posting to each response)

I expected to get a "Why do you want to do that" answer on this issue
because maybe it's impossible to do what I want to do.

I have had repeated needs on several recent jobs to provide the user with a
run time variable matrix of dataentry fields. I know that older
conventional web developers would render out an html table from their code
so the user could enter the data but this has lots of weaknesses.

I thought that a DataGrid or a GridView would be a good tool to use as I
could put it in a DIV where it could be scrolled, I could vary the matrix at
run time (4x6, 1000 x 1000, etc), and add textboxes, regularexpression
validators, etc as desired. I could even create a component using this
technique to make it easier for the developer to use. I figured it must be
possible to manually load data into a GridView since databinding somehow
does it. I see however that the Rows property is read-only.

So, that's WHY I want to do it.

BTW, I never really did this with a DataGrid either. I wrote a General
Purpose Table Maintenance Utility where I got the data in by loading up a
dataset, bound it, and then walked through the grid after the data was
changed. Maybe I'll have to take that approach here too?

Is it impossible to do what I am trying to do? Is there some beter way?

--
Regards,
Gary Blakely
"Walter Wang [MSFT]" <> wrote in message
news:...
> Hi Gary,
>
> Thank you for your post.
>
> I believe this post is a further step during your adventure of learning
> GridView,
>
> Based on my understanding, both DataGrid and GridView are designed to work
> with DataBinding scenario.
>
> Can I ask why you want to manually load data into the GridView?
>
> Also, could you please telling me how did you load data into DataGrid as
> you described in your another post about DataGrid vs GridView?
>
>
>
> Regards,
> Walter Wang (, remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>



 
Reply With Quote
 
GaryDean
Guest
Posts: n/a
 
      07-26-2006
Ken, thanks for responding.

I'll try to answer you both... (by posting to each response)

I expected to get a "Why do you want to do that" answer on this issue
because maybe it's impossible to do what I want to do.

I have had repeated needs on several recent jobs to provide the user with a
run time variable matrix of dataentry fields. I know that older
conventional web developers would render out an html table from their code
so the user could enter the data but this has lots of weaknesses.

I thought that a DataGrid or a GridView would be a good tool to use as I
could put it in a DIV where it could be scrolled, I could vary the matrix at
run time (4x6, 1000 x 1000, etc), and add textboxes, regularexpression
validators, etc as desired. I could even create a component using this
technique to make it easier for the developer to use. I figured it must be
possible to manually load data into a GridView since databinding somehow
does it. I see however that the Rows property is read-only.

So, that's WHY I want to do it.

BTW, I never really did this with a DataGrid either. I wrote a General
Purpose Table Maintenance Utility where I got the data in by loading up a
dataset, bound it, and then walked through the grid after the data was
changed. Maybe I'll have to take that approach here too?

Is it impossible to do what I am trying to do? Is there some beter way?

--
Regards,
Gary Blakely


--
Regards,
Gary Blakely
Dean Blakely & Associates
www.deanblakely.com
"Ken Cox [Microsoft MVP]" <> wrote in message
news:%...
> Hi Gary,
>
> Perhaps you could explain what your ultimate goal is?
>
> It looks like you're trying to use a gridview to create a table of some
> sort without binding to data. Its the data the makes the GridView add
> rows.
>
> Ken
> Microsoft MVP [ASP.NET]
>
> "GaryDean" <> wrote in message
> news:...
>> I'm trying to load a GridView up with data manually, in code. I'm not
>> using any datasource. Using this code....
>>
>> ArrayList myRowArrayList;
>> GridViewRow myGVR = new
>> GridViewRow(0,0,DataControlRowType.DataRow, DataControlRowState.Normal);
>> TableCell myCell = new TableCell();
>> TextBox myTextbox = new TextBox();
>> myTextbox.Text = "hello world";
>> myCell.Controls.Add(myTextbox);
>> myGVR.Cells.Add(myCell);
>> myRowArrayList.Add(myGVR);
>> GridViewRowCollection myCollection = new
>> GridViewRowCollection(myRowArrayList);
>> //How do I attach this collection to my GridView?
>>
>> I can't see how to add the new row I created to the GridView. There is
>> no GridView.rows.add method. How is a row added to a gridview or how is
>> the GridViewRowcollectin attached to the Gridview?
>> --
>> Regards,
>> Gary Blakely
>>
>>

>
>



 
Reply With Quote
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      07-26-2006
Hi Gary,

I'm not sure I've really grasped what you're after yet but my impression is
that breaking into the GridView for this task is going to be difficult.

What about using a repeater and adding your dynamic controls to its controls
collection? Or, create one user control that packages all of the individual
controls (textbox and validator) and add as many user controls as you need?


Ken
Microsoft MVP [ASP.NET]

"GaryDean" <> wrote in message
news:OWnY1$...
> Ken, thanks for responding.
>
> I'll try to answer you both... (by posting to each response)
>
> I expected to get a "Why do you want to do that" answer on this issue
> because maybe it's impossible to do what I want to do.
>
> I have had repeated needs on several recent jobs to provide the user with
> a run time variable matrix of dataentry fields. I know that older
> conventional web developers would render out an html table from their code
> so the user could enter the data but this has lots of weaknesses.
>
> I thought that a DataGrid or a GridView would be a good tool to use as I
> could put it in a DIV where it could be scrolled, I could vary the matrix
> at run time (4x6, 1000 x 1000, etc), and add textboxes, regularexpression
> validators, etc as desired. I could even create a component using this
> technique to make it easier for the developer to use. I figured it must
> be possible to manually load data into a GridView since databinding
> somehow does it. I see however that the Rows property is read-only.
>
> So, that's WHY I want to do it.
>
> BTW, I never really did this with a DataGrid either. I wrote a General
> Purpose Table Maintenance Utility where I got the data in by loading up a
> dataset, bound it, and then walked through the grid after the data was
> changed. Maybe I'll have to take that approach here too?
>
> Is it impossible to do what I am trying to do? Is there some beter way?
>
> --
> Regards,
> Gary Blakely
>
>
> --
> Regards,
> Gary Blakely
> Dean Blakely & Associates
> www.deanblakely.com
> "Ken Cox [Microsoft MVP]" <> wrote in
> message news:%...
>> Hi Gary,
>>
>> Perhaps you could explain what your ultimate goal is?
>>
>> It looks like you're trying to use a gridview to create a table of some
>> sort without binding to data. Its the data the makes the GridView add
>> rows.
>>
>> Ken
>> Microsoft MVP [ASP.NET]
>>
>> "GaryDean" <> wrote in message
>> news:...
>>> I'm trying to load a GridView up with data manually, in code. I'm not
>>> using any datasource. Using this code....
>>>
>>> ArrayList myRowArrayList;
>>> GridViewRow myGVR = new
>>> GridViewRow(0,0,DataControlRowType.DataRow, DataControlRowState.Normal);
>>> TableCell myCell = new TableCell();
>>> TextBox myTextbox = new TextBox();
>>> myTextbox.Text = "hello world";
>>> myCell.Controls.Add(myTextbox);
>>> myGVR.Cells.Add(myCell);
>>> myRowArrayList.Add(myGVR);
>>> GridViewRowCollection myCollection = new
>>> GridViewRowCollection(myRowArrayList);
>>> //How do I attach this collection to my GridView?
>>>
>>> I can't see how to add the new row I created to the GridView. There is
>>> no GridView.rows.add method. How is a row added to a gridview or how is
>>> the GridViewRowcollectin attached to the Gridview?
>>> --
>>> Regards,
>>> Gary Blakely
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
GaryDean
Guest
Posts: n/a
 
      07-26-2006
Ken,
I guess this is a dead end. Looks like the DataGrid and the GridView just
don't have the methods to load data by code. It would be cool if they did.
I can load the GridView with Template textboxes, load a dataset in code,
bind to the dataset, then walk through the grid after the user has changed
fields.

Thanks for your help.

--
Regards,
Gary Blakely
"Ken Cox [Microsoft MVP]" <> wrote in message
news:...
> Hi Gary,
>
> I'm not sure I've really grasped what you're after yet but my impression
> is that breaking into the GridView for this task is going to be difficult.
>
> What about using a repeater and adding your dynamic controls to its
> controls collection? Or, create one user control that packages all of the
> individual controls (textbox and validator) and add as many user controls
> as you need?
>
>
> Ken
> Microsoft MVP [ASP.NET]
>
> "GaryDean" <> wrote in message
> news:OWnY1$...
>> Ken, thanks for responding.
>>
>> I'll try to answer you both... (by posting to each response)
>>
>> I expected to get a "Why do you want to do that" answer on this issue
>> because maybe it's impossible to do what I want to do.
>>
>> I have had repeated needs on several recent jobs to provide the user with
>> a run time variable matrix of dataentry fields. I know that older
>> conventional web developers would render out an html table from their
>> code so the user could enter the data but this has lots of weaknesses.
>>
>> I thought that a DataGrid or a GridView would be a good tool to use as I
>> could put it in a DIV where it could be scrolled, I could vary the matrix
>> at run time (4x6, 1000 x 1000, etc), and add textboxes, regularexpression
>> validators, etc as desired. I could even create a component using this
>> technique to make it easier for the developer to use. I figured it must
>> be possible to manually load data into a GridView since databinding
>> somehow does it. I see however that the Rows property is read-only.
>>
>> So, that's WHY I want to do it.
>>
>> BTW, I never really did this with a DataGrid either. I wrote a General
>> Purpose Table Maintenance Utility where I got the data in by loading up a
>> dataset, bound it, and then walked through the grid after the data was
>> changed. Maybe I'll have to take that approach here too?
>>
>> Is it impossible to do what I am trying to do? Is there some beter way?
>>
>> --
>> Regards,
>> Gary Blakely
>>
>>
>> --
>> Regards,
>> Gary Blakely
>> Dean Blakely & Associates
>> www.deanblakely.com
>> "Ken Cox [Microsoft MVP]" <> wrote in
>> message news:%...
>>> Hi Gary,
>>>
>>> Perhaps you could explain what your ultimate goal is?
>>>
>>> It looks like you're trying to use a gridview to create a table of some
>>> sort without binding to data. Its the data the makes the GridView add
>>> rows.
>>>
>>> Ken
>>> Microsoft MVP [ASP.NET]
>>>
>>> "GaryDean" <> wrote in message
>>> news:...
>>>> I'm trying to load a GridView up with data manually, in code. I'm not
>>>> using any datasource. Using this code....
>>>>
>>>> ArrayList myRowArrayList;
>>>> GridViewRow myGVR = new
>>>> GridViewRow(0,0,DataControlRowType.DataRow,
>>>> DataControlRowState.Normal);
>>>> TableCell myCell = new TableCell();
>>>> TextBox myTextbox = new TextBox();
>>>> myTextbox.Text = "hello world";
>>>> myCell.Controls.Add(myTextbox);
>>>> myGVR.Cells.Add(myCell);
>>>> myRowArrayList.Add(myGVR);
>>>> GridViewRowCollection myCollection = new
>>>> GridViewRowCollection(myRowArrayList);
>>>> //How do I attach this collection to my GridView?
>>>>
>>>> I can't see how to add the new row I created to the GridView. There is
>>>> no GridView.rows.add method. How is a row added to a gridview or how
>>>> is the GridViewRowcollectin attached to the Gridview?
>>>> --
>>>> Regards,
>>>> Gary Blakely
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      07-27-2006
Hi Gary,

Thank you for your detailed explanation.

I guess your original intention to use GridView is that it can help you
generate dynamic matrix.

Since the DataGrid and GridView are all designed to be used with
DataBinding, for such scenario, I recommend you to create a custom control
to do that as Ken also suggested.

If you need to discuss on how to create such control, you're welcome to
open a new thread in group
microsoft.public.dotnet.framework.aspnet.buildingc ontrols.



Regards,
Walter Wang (, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
rhkulju rhkulju is offline
Junior Member
Join Date: Sep 2008
Posts: 1
 
      09-08-2008
"Since the DataGrid and GridView are all designed to be used with
DataBinding, for such scenario, I recommend you to create a custom control
to do that as Ken also suggested."

What!!!?!?!?!? Uhhhh... Microsoft didn't hire Anders Hejlsberg to have this same old historical nonsense that was considered Microsoft Development to continue.... and thankfully he put a stop to it.

Of course you can manually populate the GridView..... why wouldn't you???... I've done it.

You need to Create your Cells manually do an call the AddRange method on the Rows you manually create to add the Cells.

You then need to do an AddRange on the DataGridView to add the Rows.

Manually adding things is a basic necessity in all Computer Science applications... thats why you can do it.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
order of iframe loading with document loading ofir Javascript 0 12-03-2007 12:06 PM
loading image -> detect when image is done loading edfialk Javascript 0 05-10-2007 07:28 PM
[OT] Is loading the second Java application faster than loading the first? David Segall Java 2 01-02-2007 04:41 PM
GridView Hierarchical View - Gridview in Gridview =?Utf-8?B?bWdvbnphbGVzMw==?= ASP .Net 1 05-09-2006 06:48 PM
Image loading using javascript. Handling timeouts and parrallel loading under IE zborisau@gmail.com Javascript 4 08-28-2005 02:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57