473,385 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Loading Gridview in code

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
Jul 25 '06 #1
7 5358
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" <Ga******@newsgroups.nospamwrote in message
news:ez**************@TK2MSFTNGP05.phx.gbl...
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


Jul 26 '06 #2
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 (wa****@online.microsoft.com, 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.

Jul 26 '06 #3
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]" <wa****@online.microsoft.comwrote in message
news:6b**************@TK2MSFTNGXA01.phx.gbl...
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 (wa****@online.microsoft.com, 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.

Jul 26 '06 #4
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]" <BA**********@newsgroups.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
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" <Ga******@newsgroups.nospamwrote in message
news:ez**************@TK2MSFTNGP05.phx.gbl...
>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



Jul 26 '06 #5
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" <Ga******@newsgroups.nospamwrote in message
news:OW**************@TK2MSFTNGP04.phx.gbl...
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]" <BA**********@newsgroups.nospamwrote in
message news:%2****************@TK2MSFTNGP04.phx.gbl...
>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" <Ga******@newsgroups.nospamwrote in message
news:ez**************@TK2MSFTNGP05.phx.gbl...
>>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




Jul 26 '06 #6
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]" <BA**********@newsgroups.nospamwrote in message
news:e6**************@TK2MSFTNGP02.phx.gbl...
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" <Ga******@newsgroups.nospamwrote in message
news:OW**************@TK2MSFTNGP04.phx.gbl...
>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]" <BA**********@newsgroups.nospamwrote in
message news:%2****************@TK2MSFTNGP04.phx.gbl...
>>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" <Ga******@newsgroups.nospamwrote in message
news:ez**************@TK2MSFTNGP05.phx.gbl...
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




Jul 26 '06 #7
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 (wa****@online.microsoft.com, 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.

Jul 27 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Lingo | last post by:
I'm using beta2. I'm trying to create a gridview dynamically with a passed in SQL statement, everything works paging, sorting, and adding columns dynamically with the code. Because the hidden...
1
by: jobs at webdos | last post by:
Loading gridview in edit mode with a blank row at top of data source? I'd like to have a button that when selected will rebind my gridview to a blank row + the original datasource in edit mode on...
0
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile...
1
by: David Lozzi | last post by:
Howdy, I have a gridview and a sqldatasource. i need to do a little processing before I can let the GridView run and load from the SqlDataSource. I have the query I need already in the...
4
by: Prabhua | last post by:
Hi, can anybody clear my doubt in asp.net using c#. i am deleting record in database using gridview control. the problem here is that record gets deleted in database but the changes is not...
6
by: cmorgan76 | last post by:
This is a 2 part question: Part 1: I am accesing a web service that returns an xml string of user information. I am attempting to load the XML into an XMLDocument, save the document, load it...
2
by: =?Utf-8?B?Z2VvZmZh?= | last post by:
I cannot figure this out and would appreciate any help..... I have a datagrid view that displays the results from a Stored Procedure. it can take awhile to load..... the stored procedure fires...
0
by: teressa | last post by:
Hi, I am new to Grid view Control. I have a page with many icons on it for different purposes. I want to add a Grid View where I want to load data with different columns. Below is my...
3
by: jmeyer5csc | last post by:
i am using jquery to display a working... div to show the user that the query is doing something. to show.... Sys.Application.add_init(function() { ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.