Get datagrid item text

M

martin

Hi,

I am iterating through the dataitems in a datagrid and producing and xml
document,
If a particular cell in the datagrid has a textbox control or a datagrid
control in it then I have no problem retrieveing it value by casting with
CTYPE

however when the datagrid cell contains no control, but does contain text,
then I am having great trouble accessing its value.

can anybody please help me out.
I have provided the code I am stuc on below.

cheers

martin.

Dim di As DataGridItem
For Each di In dgOtherMemberships.Items
counter = counter + 1
If di.ItemType = ListItemType.AlternatingItem Or di.ItemType =
ListItemType.Item Then
elem = doc.CreateElement("Item")
elem.SetAttribute("PKID", --WHAT GOES HERE TO RETRIEVE THE
TEXT OF A DATGRID CELL) <----------Having trouble with this cast...???
elem.SetAttribute("membership",
CType(di.FindControl("Member"), CheckBox).Checked)
elem.SetAttribute("Accredited",
CType(di.FindControl("Accredited"), CheckBox).Checked)
elem.SetAttribute("membershipCode",
CType(di.FindControl("MembershipCode"), TextBox).Text)
rootElem.AppendChild(elem)
End If
Next
 
C

Craig Deelsnyder

martin said:
Hi,

I am iterating through the dataitems in a datagrid and producing and xml
document,
If a particular cell in the datagrid has a textbox control or a datagrid
control in it then I have no problem retrieveing it value by casting with
CTYPE

however when the datagrid cell contains no control, but does contain text,
then I am having great trouble accessing its value.

can anybody please help me out.
I have provided the code I am stuc on below.

cheers

martin.

Dim di As DataGridItem
For Each di In dgOtherMemberships.Items
counter = counter + 1
If di.ItemType = ListItemType.AlternatingItem Or di.ItemType =
ListItemType.Item Then
elem = doc.CreateElement("Item")
elem.SetAttribute("PKID", --WHAT GOES HERE TO RETRIEVE THE
TEXT OF A DATGRID CELL) <----------Having trouble with this cast...???
elem.SetAttribute("membership",
CType(di.FindControl("Member"), CheckBox).Checked)
elem.SetAttribute("Accredited",
CType(di.FindControl("Accredited"), CheckBox).Checked)
elem.SetAttribute("membershipCode",
CType(di.FindControl("MembershipCode"), TextBox).Text)
rootElem.AppendChild(elem)
End If
Next

di.Cells[0].Text would give you the text of the first column in the
grid, etc. Fill in the appropriate index.

BTW, if you were using a TemplateColumn for this 'text column', then you
could have used a LiteralControl in this column instead of plain text,
and you could then do something similar to what you do for the controls
(.FindControl...).
 
M

martin

Thank you craig,

maybe you could tell me if it is possible to bind the changed datagrid
values back to a datatable in dataset (or the like) in a single
statement, ---just like a bind from the dataset to the datagrid in a single
statement, only the other way around.

what I am doing at the moments is iterating through my datagrid producing a
custon xml file that I am passing to the database, so that all updates can
be done in a single call to the db.

cheers

martin.


Craig Deelsnyder said:
martin said:
Hi,

I am iterating through the dataitems in a datagrid and producing and xml
document,
If a particular cell in the datagrid has a textbox control or a datagrid
control in it then I have no problem retrieveing it value by casting with
CTYPE

however when the datagrid cell contains no control, but does contain text,
then I am having great trouble accessing its value.

can anybody please help me out.
I have provided the code I am stuc on below.

cheers

martin.

Dim di As DataGridItem
For Each di In dgOtherMemberships.Items
counter = counter + 1
If di.ItemType = ListItemType.AlternatingItem Or di.ItemType =
ListItemType.Item Then
elem = doc.CreateElement("Item")
elem.SetAttribute("PKID", --WHAT GOES HERE TO RETRIEVE THE
TEXT OF A DATGRID CELL) <----------Having trouble with this cast...???
elem.SetAttribute("membership",
CType(di.FindControl("Member"), CheckBox).Checked)
elem.SetAttribute("Accredited",
CType(di.FindControl("Accredited"), CheckBox).Checked)
elem.SetAttribute("membershipCode",
CType(di.FindControl("MembershipCode"), TextBox).Text)
rootElem.AppendChild(elem)
End If
Next

di.Cells[0].Text would give you the text of the first column in the
grid, etc. Fill in the appropriate index.

BTW, if you were using a TemplateColumn for this 'text column', then you
could have used a LiteralControl in this column instead of plain text,
and you could then do something similar to what you do for the controls
(.FindControl...).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top