Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagrid control collection 1

Status
Not open for further replies.

Zarcom

Programmer
May 7, 2002
1,275
CA
Can anyone out there explain the control collection of a datagrid for me. I had thought that if a textbox was the only control in said column then it would have an id of 0. However it's in position 1, 0 is holding a literal. I am a little confused by this and am trying to wrap my head around it.

Another thing is the "Creating a Distributed Application" walkthrough. The web interface has the following code on an update (you can see it in its entirety in the walkthrough)
For i = 1 to AuthorData.authors.Columns.Count
dim t as TextBox = CType(e.Item.Cells(i).Controls, TextBox)
dim row as DataRow = AuthorData.authors(e.Item.DatasetIndex)
row(AuthorData.authors.Columns(i-1).Caption) = t.text
Next


The next part of the walkthrough uses the adapter .Update method to send changes to the database. How the heck did the dataset get those changes? Did that above little snippet of code sneakaly use some pointers without my noticing?

Maybe I am just having a bad. day.
Your input is appreciated.
I am assuming that Paul is going to grab the 1st question he seems to be the leading authority here on datagrids and there nuances. Enough rambling for me, it's your turn now. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
well, the control collection of a datagrid is made up of who-knows-how-many controls... table, tablerows, tablecells, labels, and then to your stuff... the textboxes, etc...

But, for a particular cell in a datagrid item (row), that's where you'll get your 0 based index on the control, so on an update, if you have a text box in cell 0 called "fname", then you'd grab it like this:

ctype(e.item.cells(0).controls(0),textbox)

or something. I actually prefer to use the .findControl method of the cell to get exactly what I'm after, as sometimes, asp.net will sneak something in there on you... or you may have snuck it in w/o your knowing, so:

ctype(e.item.cells(0).findControl("fName"),textbox)

Just remember that nearly EVERYTHING in asp.net is a collection of controls...

page has controls, and those controls have controls, and so on... gives you a very nice hierarchical structure that, once you understand it, is very easy to work with.

Now, although I don't use the .update method of the dataset (I prefer to do my own updating), the second question you have there is grabbing a pointer to the row of the dataset that the .dataSetIndex is pointing to.

AuthorData.authors(e.Item.DatasetIndex)

and assigns that to a row object, which it then promptly updates, which is how I'll assume it knows what to update.

hth! :)
paul
penny1.gif
penny1.gif
 
Hmm so that is a pointer then.

Thanks for the findcontrol method I had forgetten about it. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top