How to extract data from a GridView control to WorkflowGen process data?
Solution
If you require data from within a GridView control to be stored within a process data in WorkflowGen, you can do this by accessing specific information from the GridView. Keep in mind that GridViews are dynamic, meaning that they can contain zero or multiple rows of data, whereas WorkflowGen process data is static.
The following example will extract a specific data element from a specific row of the GridView and pass the value back to WorkflowGen.
Suppose you have a GridView called GV_USER with 3 columns: ID, Name, and Details, each containing a textbox control with the ID GV_USER_USER_ID, GV_USER_USER_NAME, and GV_USER_USER_DETAILS respectively.
Furthermore, the user has entered 5 rows of data. If you need to extract the Name from the first row of data, do the following:
Create a process data (ex. FIRSTUSERNAME) to store this particular GridView value.
Create an OUT direction action parameter with the proper syntax (GRIDVIEW_ID[x]/ELEMENT_ID). In this example, we would create a parameter with the name GV_USER[1]/GV_USER_USER_NAME.
Set the OUT parameter to receive the value into the process data FIRSTUSERNAME.
Notes
In the GRIDVIEW_ID[x]/ELEMENT_ID format, GRIDVIEW_ID is the .NET ID of the target GridView and x is the row index of the GridView data row. It is not zero base, meaning the first row is 1, not 0. ELEMENT_ID is the .NET ID of the control (textbox in this case) within that row.
In the event that the GridView has no data or the row index that you specify does not exist, WorkflowGen will just set the process data to null.
Hello.
If you need to “transfer” a full Grid View from a main workflow to a subworkflow, you can convert it as text. In my example, I chose to convert a GV with labels in a xml format :
My GridView : S_SAISIR_GV_RATTACHEMENT
Text box exported as data : S_SAISIR_T_XML_RATTACHEMENT.
Function “rattachementToXml” can be launched whenever you want (at save, at submit…)
protected void rattachementToXml() // Convert to xml format
{
string xmlGridView = “”;
xmlGridView += “<?xml version=\"1.0\" encoding=\"utf-8\" ?>”;
xmlGridView += “<_root>”; // delete the _
int rowscount = S_SAISIR_GV_RATTACHEMENT.Rows.Count;
In your subworkflow, you can “decode” the xml data and include it in your gridview
FillRattachement function is called during PageLoad. (perhaps it should be launched during PageLoadComplete event)
protected void FillRattachement()
{
if (S_SAISIR_T_XML_RATTACHEMENT.Text == "")
return;
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml(S_SAISIR_T_XML_RATTACHEMENT.Text);
System.Xml.XmlNodeList rowList = xmlDoc.GetElementsByTagName("row");
foreach (System.Xml.XmlNode row in rowList)
{
System.Xml.XmlNodeList columnList = row.SelectNodes(".//column");
AddLineToRattachement(columnList[0].InnerText,columnList[1].InnerText,columnList[2].InnerText);
}
S_SAISIR_T_XML_RATTACHEMENT.Text = "";
this.SaveFieldsData(this.FormData);
this.SaveFormData(this.FormData);
this.BindFormDataToFields(this.FormData);
}
// Add a line in gridview
protected void AddLineToRattachement(string i_moteur, string i_ata, string i_item_rep)
{
int columnMoteur = 0;
int columnATA = 1;
int columnItemRep = 2;
System.Data.DataRow row = this.FormData.Tables["S_SAISIR_GV_RATTACHEMENT"].NewRow();
row[columnMoteur] = i_moteur;
row[columnATA] = i_ata;
row[columnItemRep] = i_item_rep;
this.FormData.Tables["S_SAISIR_GV_RATTACHEMENT"].Rows.Add(row);
this.FormData.Tables["S_SAISIR_GV_RATTACHEMENT"].AcceptChanges();
}
This code is not perfect : it only takes into account labels in GridView (no code for checkboxes…), it has the column number hard coded… but it can gives ideas
Hope this can help.
Best regards.