For this we need to use newtonsoft.json dll to our project.
This dll can be installed by package manager. Perform following steps to download this package:
1. Go to Tools > Library Package Manager > Manage NuGet Packages for Solution...
Requirement was to get data from database and display in grid.
And on click of any link in a grid, I was asked to open a pop up and display
controls there. On click of submit button in pop up, I had to update data back
in parent gridview. And on final submit, I had to save data in database.
Solution:
I performed following steps to achieve this:
Created a procedure to get
all the required data.
Added a column in procedure
to get all the relational data in an XML.
Created a page and displayed
data in a grid (grid is having a link button to open pop up).
Use JsonConvert.SerializeXmlNode(doc)
to convert XML data to JSON and set as text of a textbox.(in RowDataBound
event)
Set “style=display:none”
attribute of that textbox(to hide that textbox)
On click of linkbutton in
grid, I get data from textbox and created a table from that XML.
Displayed that table in a
div.
Set height, width, margin and
padding of that div using jQuery.
Provided input fields to
manipulate that data and 1 submit button to submit data to parent grid.
On click of Submit, created
XML from input fields and update text of textbox in parent grid. And update ID
in a hidden field so that we do not need to update all unnecessary data.
On click of Save button of
parent grid, executed server side event.
Read XML value from textbox
(depending upon IDs in hidden field).
Created single XML from all
textboxes.
Created another procedure in
database to read that XML and update in tables.
Following is the complete code aspx and aspx.cs code
dr["Data"] = "<root><node><xml_node_id>4</xml_node_id><xml_node_name>xml node name 1</xml_node_name></node><node><xml_node_id>5</xml_node_id><xml_node_name>xml node name 2</xml_node_name></node><node><xml_node_id>6</xml_node_id><xml_node_name>xml node name 3</xml_node_name></node><node><xml_node_id>7</xml_node_id><xml_node_name>xml node name 4</xml_node_name></node><node><xml_node_id>8</xml_node_id><xml_node_name>xml node name 5</xml_node_name></node><node><xml_node_id>9</xml_node_id><xml_node_name>xml node name 6</xml_node_name></node><node><xml_node_id>10</xml_node_id><xml_node_name>xml node name 7</xml_node_name></node><node><xml_node_id>11</xml_node_id><xml_node_name>xml node name 8</xml_node_name></node><node><xml_node_id>12</xml_node_id><xml_node_name>xml node name 9</xml_node_name></node><node><xml_node_id>13</xml_node_id><xml_node_name>xml node name 10</xml_node_name></node><node><xml_node_id>14</xml_node_id><xml_node_name>xml node name 11</xml_node_name></node><node><xml_node_id>15</xml_node_id><xml_node_name>xml node name 12</xml_node_name></node><node><xml_node_id>16</xml_node_id><xml_node_name>xml node name 13</xml_node_name></node><node><xml_node_id>17</xml_node_id><xml_node_name>xml node name 14</xml_node_name></node></root>";