473,756 Members | 6,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ,DataControlRow Type.DataRow,
DataControlRowS tate.Normal);
TableCell myCell = new TableCell();
TextBox myTextbox = new TextBox();
myTextbox.Text = "hello world";
myCell.Controls .Add(myTextbox) ;
myGVR.Cells.Add (myCell);
myRowArrayList. Add(myGVR);
GridViewRowColl ection myCollection = new
GridViewRowColl ection(myRowArr ayList);
//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.a dd method. How is a row added to a gridview or how is the
GridViewRowcoll ectin attached to the Gridview?
--
Regards,
Gary Blakely
Jul 25 '06 #1
7 5381
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******@newsg roups.nospamwro te in message
news:ez******** ******@TK2MSFTN GP05.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 ,DataControlRow Type.DataRow,
DataControlRowS tate.Normal);
TableCell myCell = new TableCell();
TextBox myTextbox = new TextBox();
myTextbox.Text = "hello world";
myCell.Controls .Add(myTextbox) ;
myGVR.Cells.Add (myCell);
myRowArrayList. Add(myGVR);
GridViewRowColl ection myCollection = new
GridViewRowColl ection(myRowArr ayList);
//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.a dd method. How is a row added to a gridview or how is the
GridViewRowcoll ectin 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, regularexpressi on
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.comwr ote in message
news:6b******** ******@TK2MSFTN GXA01.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, regularexpressi on
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**********@n ewsgroups.nospa mwrote in message
news:%2******** ********@TK2MSF TNGP04.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******@newsg roups.nospamwro te in message
news:ez******** ******@TK2MSFTN GP05.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,DataControlRo wType.DataRow, DataControlRowS tate.Normal);
TableCell myCell = new TableCell();
TextBox myTextbox = new TextBox();
myTextbox.Text = "hello world";
myCell.Controls .Add(myTextbox) ;
myGVR.Cells.Add (myCell);
myRowArrayList. Add(myGVR);
GridViewRowColl ection myCollection = new
GridViewRowCol lection(myRowAr rayList);
//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.a dd method. How is a row added to a gridview or how is
the GridViewRowcoll ectin 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******@newsg roups.nospamwro te in message
news:OW******** ******@TK2MSFTN GP04.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, regularexpressi on
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**********@n ewsgroups.nospa mwrote in
message news:%2******** ********@TK2MSF TNGP04.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******@newsg roups.nospamwro te in message
news:ez******* *******@TK2MSFT NGP05.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,DataControlR owType.DataRow, DataControlRowS tate.Normal);
TableCell myCell = new TableCell();
TextBox myTextbox = new TextBox();
myTextbox.Text = "hello world";
myCell.Controls .Add(myTextbox) ;
myGVR.Cells.Add (myCell);
myRowArrayList. Add(myGVR);
GridViewRowColl ection myCollection = new
GridViewRowCo llection(myRowA rrayList);
//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.a dd method. How is a row added to a gridview or how is
the GridViewRowcoll ectin 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**********@n ewsgroups.nospa mwrote in message
news:e6******** ******@TK2MSFTN GP02.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******@newsg roups.nospamwro te in message
news:OW******** ******@TK2MSFTN GP04.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, regularexpressi on
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**********@n ewsgroups.nospa mwrote in
message news:%2******** ********@TK2MSF TNGP04.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******@newsg roups.nospamwro te in message
news:ez****** ********@TK2MSF TNGP05.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,DataControl RowType.DataRow ,
DataControlR owState.Normal) ;
TableCell myCell = new TableCell();
TextBox myTextbox = new TextBox();
myTextbox.Text = "hello world";
myCell.Controls .Add(myTextbox) ;
myGVR.Cells.Add (myCell);
myRowArrayList. Add(myGVR);
GridViewRowColl ection myCollection = new
GridViewRowC ollection(myRow ArrayList);
//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.a dd method. How is a row added to a gridview or how
is the GridViewRowcoll ectin 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.publi c.dotnet.framew ork.aspnet.buil dingcontrols.

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
1082
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 column isn't accessible anymore I needed to use datakeys to store my key to the record(s) to take actions on. If I use the standard gridview without dynamically creating anything the datakeys are loaded succesfully. If I change any properties...
1
1488
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 that first blank row. Is this possible using vb.net codebehind? Thanks.
0
2399
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 View I want the form populated from there profile on the sql server. The code to save the profile works fine. But when the user logs back in they data doesn't load back to the form. The multiview is located inside the LoginView's Logged-In View ....
1
3172
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 SelectCommand of the SDS so it runs when the page is first loaded. Is there a way to stop it from loading and let it load programatically? My first guess is to remove the select command from the SDS and populate it when I want it to load, then DataBind the...
4
2164
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 reflected in the gridview control.i also used "gridview1.Databind()" after delete query. what should i do now? regards, a.prabhu
6
5067
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 into a dataset, and bind the dataset to a gridview. I'm not sure if it's neccesary to save the XML file to disk, but I wanted to make sure it was well formed. It is. No exceptions are caught during the loading and binding process, but my gridview...
2
5363
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 when a Calendar is clicked. ( a date is part of the stored procedure ) How can i just show a new page or a pop-up that says "please wait" until the stored procedure has run and gotten all the data and the page is completely loaded? In all the...
0
1262
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 code(xyz.aspx).Where i need to add the aspx page to my original page.(I tried adding to my HTML page but it returns with an error(We’re sorry, the application is currently unavailable. If you need any assistance, please contact ...)instead of loading data. I...
3
4032
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() { $addHandler($get('ctl00_ContentPlaceHolder1_LinkButtonQuickReport'), 'click', function() { $('#working').show(); }); }); to hide...
0
9117
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9679
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9676
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8542
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4955
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3141
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2508
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.