Skip to content

Converting datagrid content to string.

ruan

Asked Mar 2, 2004, 3:48 AM EST2 answers
Share
LinkedInX
Is it possible to convert data in a datagrid to a string?. I want to send the info in the grid via e-mail, and it has to be in the format that the content appears in the datagrid. Thanx

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    It is somewhat complicated. If the DataGrid is associated with a DataSet use DataSet.WriteXml method to convert the contents into a xml file. Create a XSL file and use it to convert the XML file into HTML. I haven't tried this before. But got to try.......... Thanks, Jagan Mohan
    0
  • 0
    You can use the following code to get to the individual cells of the datagrid and then format the info as you want: foreach(DataGridItem i in myGrid.Items) { if (i.ItemType == ListItemType.Header) { // i is the header row } else if (i.ItemType == ListItemType.Item || i.ItemType == ListItemType.AlternatingItem || i.ItemType == ListItemType.SelectedItem) { //i is one of the data rows // if you want the textbox, for e.g. TextBox t = (TextBox)i.FindControl("TextBoxID"); ..... } else if (i.ItemType == ListItemType.Footer) { // i is the footer row } }
    0