![]() |
|
|
|
#1 |
|
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 GaryDean |
|
|
|
|
#2 |
|
Posts: n/a
|
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 > > |
|
|
|
#3 |
|
Posts: n/a
|
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. |
|
|
|
#4 |
|
Posts: n/a
|
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. > |
|
|
|
#5 |
|
Posts: n/a
|
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 >> >> > > |
|
|
|
#6 |
|
Posts: n/a
|
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 >>> >>> >> >> > > |
|
|
|
#7 |
|
Posts: n/a
|
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 >>>> >>>> >>> >>> >> >> > > |
|
|
|
#8 |
|
Posts: n/a
|
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. |
|
|
|
#9 |
|
Junior Member
Join Date: Sep 2008
Posts: 1
|
"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. |
|
|
|