Applying function to specific columns of dataframes in list - r

I have a list of dataframes with common columns that I need to merge, but I need to coerce certain columns to character type first prior to merging. To fix this, I wrote the following:
master_list <- lapply(master_list, function(x) x %>%
                     mutate_at(.vars = vars(master_list$x$'send date',
                                            master_list$x$'send time',
                                            master_list$x$'Monthly',
                                            master_list$x$'InteractionEventDate'),
                               .funs = as.character))
However, when I look at these columns in any one dataframe in my list, the change was not made (e.g. InteractionEventDate is still a double), despite no error being thrown by the above line of code. I based it partially on the answer to this post, which used the now deprecated mutate_each.

Your approach is a bit roundabout here. So maybe first define a function using dplyr logic and then lapply it over the list?
premerge <- function(df){
df %>%
mutate_at(.vars = c("send date","send time", "Monthly","InteractionEventDate"), .funs = as.character)
}
lappyl(master_list,premerge)

Related

Find SendMail Peoplecode

We have custom functionality in PeopleSoft FSCM that generates an email notification with a link to direct users to approve vouchers online. I have found part of the text string variable that compose the email message within the following Record PeopleCode, however I can not seem to find where the actual outbound email object is created and Send method is being called and using the &EMAIL_TEXT variable. I've done Find In searches for the variable but that has not led me to the code that generates the emails. Any suggestions for how to find it is appreciated!
Here is the code snippet with the email body variable:
&EMAIL_TEXT = "Please review and take approval action for the following:" | Char(10) | "Business Unit: " | VCHR_APPRVL.BUSINESS_UNIT.Value | Char(10) | "Voucher ID: " | VCHR_APPRVL.VOUCHER_ID | Char(10) | Char(10) | Char(10);
&EMAIL_TEXT = &EMAIL_TEXT | "The following hyperlink will take you to the voucher approval page:" | Char(10);
&URL = GenerateComponentPortalURL("EMPLOYEE", Node.ERP, MenuName.ENTER_VOUCHER_INFORMATION, "GBL", Component.VCHR_APPROVE, Page.VCHR_APPRVL_WF, "U", VCHR_APPRVL.BUSINESS_UNIT, VCHR_APPRVL.VOUCHER_ID);
&EMAIL_TEXT = &EMAIL_TEXT | &URL | Char(10);
&EMAIL_TEXT = &EMAIL_TEXT | Char(10) | Char(10);
&EMAIL_TEXT = &EMAIL_TEXT | "Questions pertaining to this data should be directed to AccountsPayable_GH#guthrie.org" | Char(10);
&EMAIL_TEXT = &EMAIL_TEXT | Char(10) | Char(10);
&EMAIL_TEXT = &EMAIL_TEXT | "****DO NOT REPLY TO THIS EMAIL AS THIS ACCOUNT IS NOT MONITORED****" | Char(10);
&EMAIL_TEXT = &EMAIL_TEXT | Char(10) | Char(10);
GH_VCHR_APR_WRK.EMAILTEXT.Value = &EMAIL_TEXT;
Here is the entire Record PeopleCode (for context) on the field BUSPROCNAME with the SaveEdit action:
Declare Function virtual_approver PeopleCode APPR_VA0_WRK.FUNCLIB_01 FieldFormula;
Declare Function get_roleuser PeopleCode APPR_VA0_WRK.ROLEUSER FieldChange;
Declare Function get_message_text PeopleCode WF_FUNCLIB_WRK.FUNCLIB_01 FieldFormula;
Component boolean &overrideapprover;
Function get_denial_role();
&SETID = GetSetId(Field.BUSINESS_UNIT, VCHR_APPRVL.BUSINESS_UNIT, Record.BUS_UNIT_OPT_AP, "");
&CURRDATE = %Date;
SQLExec("Select a.rolename from ps_bus_unit_opt_ap a where a.setid = :1 and a.effdt = (Select max(b.effdt) from ps_bus_unit_opt_ap b where b.setid = :2 and b.effdt <= %datein(:3) and b.eff_status = 'A')", &SETID, &SETID, &CURRDATE, APPR_FIELDS_WRK.ROLENAME);
End-Function;
Function get_deptid(&BU, &Voucher_ID, &Dept_Cnt, &DEPTID);
Local SQL &SQL_DEPTID;
&Dept_Cnt = 0;
/* If &VOUCHER_STYLE = "JRNL" Or
&VOUCHER_STYLE = "CORR" Or
&VOUCHER_STYLE = "ADJ" Then
MessageBox(0, "", 0, 0, "Jrnl or Adj or Reversal. So assigning 99999", 0);
&DEPTID = "99999";
&Dept_Cnt = 1;
Else */
SQLExec("SELECT DEPTID FROM PS_GH_VCHAPPR_DEPT WHERE BUSINESS_UNIT = :1 AND VOUCHER_ID = :2", &BU, &Voucher_ID, &DEPTID);
If All(&DEPTID) Then
&Dept_Cnt = 1;
Else
&SQL_DEPTID = CreateSQL("SELECT DISTINCT DEPTID FROM PS_DISTRIB_LINE A, PS_PO_LINE B WHERE A.BUSINESS_UNIT = :1 AND VOUCHER_ID = :2 AND A.BUSINESS_UNIT_PO = B.BUSINESS_UNIT AND A.PO_ID = B.PO_ID AND A.LINE_NBR = B.LINE_NBR AND B.RECV_REQ <> 'Y'", &BU, &Voucher_ID);
While &SQL_DEPTID.Fetch(&DEPTID_Fetch)
&Dept_Cnt = &Dept_Cnt + 1;
&DEPTID = &DEPTID_Fetch;
End-While;
End-If;
rem End-If;
End-Function;
/* ---------------- beginning of mainline --------------------------*/
/* ICE 597971000 - TMG - 06/17/03 */
/* Check if nothing has changed on the approval status */
If Not FieldChanged(VCHR_APPRVL.APPR_STATUS) Then
Error MsgGet(7045, 5, "The approval status has not been changed/updated, page cannot be saved until the approval status has been modified.!");
End-If;
If VCHR_APPRVL.APPR_STATUS = "D" And
VCHR_FS.APPR_INSTANCE = 0 Then
Error MsgGet(7045, 7, "The voucher cannot be Denied until it has been routed.");
End-If;
/* ICE 531713000 - TMG - 12/13/02 */
/* Check if voucher status has changed */
rem SQLExec("SELECT ENTRY_STATUS, CLOSE_STATUS, PROCESS_MAN_CLOSE FROM PS_VOUCHER WHERE BUSINESS_UNIT = :1 AND VOUCHER_ID = :2", VCHR_APPRVL.BUSINESS_UNIT, VCHR_APPRVL.VOUCHER_ID, &ENTRY_STATUS, &CLOSE_STATUS, &PROCESS_MAN_CLOSE);
SQLExec("SELECT ENTRY_STATUS, CLOSE_STATUS, PROCESS_MAN_CLOSE, VOUCHER_STYLE FROM PS_VOUCHER WHERE BUSINESS_UNIT = :1 AND VOUCHER_ID = :2", VCHR_APPRVL.BUSINESS_UNIT, VCHR_APPRVL.VOUCHER_ID, &ENTRY_STATUS, &CLOSE_STATUS, &PROCESS_MAN_CLOSE, &VOUCHER_STYLE);
If &ENTRY_STATUS = "P" And
&CLOSE_STATUS <> "C" And
&PROCESS_MAN_CLOSE <> "Y" Then
/* Check if worklist item has been cancelled */
&INSTANCEID = %WLInstanceId;
If All(&INSTANCEID) Then
SQLExec("SELECT MAX(A.ACTIVITYNAME), MAX(A.EVENTNAME), MAX(A.WORKLISTNAME) FROM PS_VCHR_WL1 A, PSWORKLIST B WHERE A.BUSPROCNAME = B.BUSPROCNAME AND A.ACTIVITYNAME = B.ACTIVITYNAME AND A.EVENTNAME = B.EVENTNAME AND A.WORKLISTNAME = B.WORKLISTNAME AND A.INSTANCEID = B.INSTANCEID AND A.BUSPROCNAME = :1 AND A.BUSINESS_UNIT = :2 AND A.VOUCHER_ID = :3 AND A.INSTANCEID = :4", VCHR_APPRVL.BUSPROCNAME, VCHR_APPRVL.BUSINESS_UNIT, VCHR_APPRVL.VOUCHER_ID, &INSTANCEID, &ACTIVITYNAME, &EVENTNAME, &WORKLISTNAME);
SQLExec("SELECT INSTSTATUS FROM PSWORKLIST WHERE BUSPROCNAME = :1 AND ACTIVITYNAME = :2 AND EVENTNAME = :3 AND WORKLISTNAME = :4 AND INSTANCEID = :5", VCHR_APPRVL.BUSPROCNAME, &ACTIVITYNAME, &EVENTNAME, &WORKLISTNAME, &INSTANCEID, &INSTSTATUS);
If &INSTSTATUS = 3 Then
Error MsgGet(7045, 4, "Voucher approval status cannot be changed because worklist item has been cancelled.")
End-If;
End-If;
Else
Error MsgGet(7045, 3, "Voucher approval status cannot be changed because voucher status has changed.");
End-If;
/* If (APPR_STATUS = "A" And
%MessageAgent = "") Or
(APPR_STATUS = "P" And
%MessageAgent <> "") Then */
If VCHR_APPRVL.APPR_STATUS = "A" And
%CompIntfcName <> "" Or
VCHR_APPRVL.APPR_STATUS = "D" Then
If &overrideapprover = True Then
rem &OPRID = ""; /*custom commented this line and added the next*/
&OPRID = VCHR_FS.OPRID;
Else
&OPRID = %OperatorId;
End-If;
get_roleuser(&OPRID, &EMAILID, &FORMID, &EMPLID, &ROLEUSER);
rem the following four fields are required;
APPR_FIELDS_WRK.BUSPROCNAME = VCHR_APPRVL.BUSPROCNAME;
APPR_FIELDS_WRK.APPR_RULE_SET = VCHR_APPRVL.APPR_RULE_SET;
APPR_FIELDS_WRK.ROLEUSER = &ROLEUSER;
APPR_FIELDS_WRK.APPR_INSTANCE = VCHR_APPRVL.APPR_INSTANCE;
SQLExec("SELECT GH_BUSINESS_UNIT_O FROM PS_GH_VCHAPPR_DEPT WHERE BUSINESS_UNIT = :1 AND VOUCHER_ID = :2", &BU, &Voucher_ID, &GH_BUSINESS_UNIT_O); */
SQLExec("SELECT GH_BUSINESS_UNIT_O FROM PS_GH_VCHAPPR_DEPT WHERE BUSINESS_UNIT = :1 AND VOUCHER_ID = :2", VCHR_APPRVL.BUSINESS_UNIT, VCHR_APPRVL.VOUCHER_ID, &GH_BUSINESS_UNIT_O);
VCHR_APPRVL_WRK.GH_BUSINESS_UNIT_O.Value = &GH_BUSINESS_UNIT_O;
get_deptid(VCHR_APPRVL.BUSINESS_UNIT, VCHR_APPRVL.VOUCHER_ID, &Dept_Cnt, &DEPTID);
&EMAIL_TEXT = "Please review and take approval action for the following:" | Char(10) | "Business Unit: " | VCHR_APPRVL.BUSINESS_UNIT.Value | Char(10) | "Voucher ID: " | VCHR_APPRVL.VOUCHER_ID | Char(10) | Char(10) | Char(10);
&EMAIL_TEXT = &EMAIL_TEXT | "The following hyperlink will take you to the voucher approval page:" | Char(10);
&URL = GenerateComponentPortalURL("EMPLOYEE", Node.ERP, MenuName.ENTER_VOUCHER_INFORMATION, "GBL", Component.VCHR_APPROVE, Page.VCHR_APPRVL_WF, "U", VCHR_APPRVL.BUSINESS_UNIT, VCHR_APPRVL.VOUCHER_ID);
&EMAIL_TEXT = &EMAIL_TEXT | &URL | Char(10);
&EMAIL_TEXT = &EMAIL_TEXT | Char(10) | Char(10);
&EMAIL_TEXT = &EMAIL_TEXT | "Questions pertaining to this data should be directed to AccountsPayable_GH#guthrie.org" | Char(10);
&EMAIL_TEXT = &EMAIL_TEXT | Char(10) | Char(10);
&EMAIL_TEXT = &EMAIL_TEXT | "****DO NOT REPLY TO THIS EMAIL AS THIS ACCOUNT IS NOT MONITORED****" | Char(10);
&EMAIL_TEXT = &EMAIL_TEXT | Char(10) | Char(10);
GH_VCHR_APR_WRK.EMAILTEXT.Value = &EMAIL_TEXT;
If None(&DEPTID) Then
REM VCHR_APPRVL_WRK.DEPTID.Value = "99999";
MessageBox(0, "", 0, 0, "No Deptid. So assigning 99999", 0);
VCHR_APPRVL_WRK.DEPTID.Value = "99999";
Else
VCHR_APPRVL_WRK.DEPTID.Value = &DEPTID;
End-If;
If VCHR_APPRVL.APPR_STATUS = "D" Then
APPR_FIELDS_WRK.APPR_ACTION = "D";
Else
APPR_FIELDS_WRK.APPR_ACTION = "A";
End-If;
If VCHR_APPRVL.APPR_STATUS = "A" Then
VCHR_APPRVL.APPR_STATUS = "P";
End-If;
virtual_approver();
If &overrideapprover = True Then
&overrideapprover = False;
End-If;
VCHR_APPRVL.APPR_CHECK_FLG = "Y";
rem;
VCHR_APPRVL.APPR_STATUS = APPR_FIELDS_WRK.APPR_STATUS;
remark set up the message for e-mail if denied;
If VCHR_APPRVL.APPR_STATUS = "D" Then
&LANGUAGE_CD = PSOPTIONS.LANGUAGE_CD;
&MESSAGE_SET_NBR = 7045;
&MESSAGE_NBR = 2;
&BIND1 = VCHR_FS.BUSINESS_UNIT | "/" | VCHR_FS.VOUCHER_ID;
&BIND2 = APPR_FIELDS_WRK.ROLEUSER;
&BIND3 = VCHR_FS.VENDOR_ID | ", " | VENDOR.NAME1;
&BIND4 = VCHR_FS.INVOICE_ID | " (" | VCHR_FS.INVOICE_DT | ")";
&BIND5 = VCHR_FS.GROSS_AMT | "(" | VCHR_FS.TXN_CURRENCY_CD | ")";
get_message_text(&MESSAGE_SET_NBR, &MESSAGE_NBR, &BIND1, &BIND2, &BIND3, &BIND4, &BIND5, &MESSAGE_TEXT, &DESCRLONG);
UpdateValue(VCHR_APPRVL_MSG.EMAIL_SUBJECT_LONG, 1, &DESCRLONG);
UpdateValue(VCHR_APPRVL_MSG.EMAIL_TEXTLONG, 1, &MESSAGE_TEXT);
remark get the role to send denials to;
get_denial_role();
VCHR_APPRVL_WRK.RTE_CNTL_TYPE1 = "Business Unit";
VCHR_APPRVL_WRK.RTE_CNTL_TYPE2 = "Administrative Area";
VCHR_APPRVL_WRK.WF_ADMIN_AREA = "AP";
VCHR_APPRVL_WRK.ROLENAME = APPR_FIELDS_WRK.ROLENAME;
End-If;
End-If;
The email text is being saved into a work record field, so the sendmail call doesn't have to be in this event. (It isn't in the code you provided)
In the Component Processor Flow, after SaveEdit there's SavePreChange, Workflow and SavePostChange, but since it is saved in a work record, it's also possible that additional user input is required after the Save Processing flow and therefor it could literally be anywhere.

Error in Peoplcode ScrollSelect processing

When I'm trying to open the page I get the error that "Return: 8011 - SQL statment is too long". We have about millions of rows.
On the page we are filling the scroll and the where statement is created something like this
For &i = 1 To &rs.ActiveRowCount
&PARAM1 = &rs(&i).Record.SETID.Value;
&PARAM2 = &rs(&i).Record.VENDOR_ID.Value;
&strWhere = &strWhere | " OR ";
&strWhere = &strWhere | "(SETID = " | "'" |(&PARAM1) | "'" | " AND VENDOR_ID = " | "'" |(&PARAM2) | "'" | ")";
End-for;
Is there a limit while doing a Scroll select?
Take the SQL that populated &rs.
Modify your SQL that uses &strWhere that it joins to the &rs record, which is filtered the same as you populated &rs.
It's a little tricky to explain because you'll need to change more than just your code snippet.
Modify your code so it does something more like this:
&strWhere = ", PS_SOME_RECORD b where b.keyfield_1 = :1 and b.keyfield_2 = :2 ";
&strWhere = &strWhere | "and b.setid = a.setid ";
&strWhere = &strWhere | "and b.vendorid = a.vendorid";
Same same but different:
&strWhere = " inner join PS_SOME_RECORD b on b.setid = a.setid and b.vendor_id = a.vendor_id ";
&strWhere = &strWhere | "and b.keyfield_1 = :1 and b.keyfield_2 = :2";
Basically: use the database instead of trying to build up a 1,000,000 line SQL statement.
Ultimately you want to return from the database (assuming VENDOR table) something not unlike:
select *
from ps_vendor a
inner join ps_your_rs_table b
on b.setid = a.setid
and b.vendor_id = a.vendor_id
where b.some_field = [your filter/predicates]
this is due to the length of the value passed in where condition "IN".
Since the data value passed in IN ("") exceeds the limit, hence it results in this error.

Different result from pcl::MomentOfInertiaEstimation and pcl::CropBox?

I am trying to get an OBB from a point cloud, and I have got a right result using pcl::MomentOfInertiaEstimation method .I want to extract the points from the OBB using CropBox, but I got much less points than original point cloud ,maybe there's something wrong in my rotation vector:v, I'm not quiet sure. Can anyone help me? 
struct BoundingBox{ 
        pcl::PointXYZ min_point_OBB; 
        pcl::PointXYZ max_point_OBB; 
        pcl::PointXYZ position_OBB; 
        Eigen::Matrix3f rotational_matrix_OBB; 
        pcl::PointXYZ center; 
        pcl::PointXYZ x_axis; 
        pcl::PointXYZ y_axis; 
        pcl::PointXYZ z_axis; 
}; 
BoundingBox getOBB(pcl::PointCloud<pcl::PointXYZ>::Ptr  cloud,BoundingBox OBB ) 
{ 
  pcl::MomentOfInertiaEstimation <pcl::PointXYZ> feature_extractor; 
  feature_extractor.setInputCloud (cloud); 
  feature_extractor.compute (); 
  feature_extractor.getOBB (OBB.min_point_OBB, OBB.max_point_OBB, OBB.position_OBB, OBB.rotational_matrix_OBB); 
 return OBB; 
}   
int main(void){ 
BoundingBox OBB; 
OBB=getOBB(Npoints,OBB);                   //Npoints is a part of the whole cloud 
Eigen::Quaternionf quat (OBB.rotational_matrix_OBB); 
Eigen::Vector3f position (OBB.position_OBB.x, OBB.position_OBB.y, OBB.position_OBB.z); 
 pcl::visualization::PCLVisualizer viewer; 
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> points_color_handler (cloud, 255, 255, 255); 
 viewer.addCube (position, quat, OBB.max_point_OBB.x - OBB.min_point_OBB.x, OBB.max_point_OBB.y - OBB.min_point_OBB.y, OBB.max_point_OBB.z - OBB.min_point_OBB.z,"OBB"); 
viewer.setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_REPRESENTATION, pcl::visualization::PCL_VISUALIZER_REPRESENTATION_WIREFRAME,"OBB"); 
////////////////above result is correct//////////////////// 
 Eigen::Vector4f max_point_OBB(OBB.max_point_OBB.x,OBB.max_point_OBB.y,OBB.max_point_OBB.z,1.0); 
Eigen::Vector4f min_point_OBB(OBB.min_point_OBB.x,OBB.min_point_OBB.y,OBB.min_point_OBB.z,1.0); 
pcl::PointCloud<pcl::PointXYZ>::Ptr cloudOut (new pcl::PointCloud<pcl::PointXYZ>); 
pcl::CropBox<pcl::PointXYZ> boxfilter; 
boxfilter.setMax(max_point_OBB);         
boxfilter.setMin(min_point_OBB); 
Eigen::Vector3f v = quat.vec(); 
boxfilter.setTranslation(position); 
boxfilter.setRotation(v); 
boxfilter.setInputCloud(cloud); 
boxfilter.filter (*cloudOut); 
 /////////cloulOut includes much less points than Npoints///////// 
looking for an answer! 
//boxfilter.setTranslation(position);
//boxfilter.setRotation(v);
Eigen::Translation3f translation(position_OBB.x, position_OBB.y, position_OBB.z);
Eigen::Matrix3f rotationMatrixOOB = quat.toRotationMatrix();
Eigen::Affine3f affine3f = translation * rotational_matrix_OBB;
boxfilter.setTransform(affine3f.inverse());

Show items in dropdownlist that is not equal to the selected item in other dropdownlist

Example I have 5 DropDownList with values
red, orange, yellow, green, blue
if DropDownList1 select red
The choices for DropDownList2-5 will be
orange, yellow, green, blue
if DropDownList2 select yellow
The choices for DropDownList3-5 will be
orange, green, blue
Here is the code I found in the internet, this is only for 3 DropDownList but what I need is for 5 DropDownList. I can't expand the code for 5 DropDownList
VB
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Private bFlag As Boolean = True
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
FillddlLocations()
End If
End Sub
'Properties to store selected value in ViewState
Protected Property MemberID1Selection() As String
Get
If ViewState("MemberID1Selection") IsNot Nothing Then
Return ViewState("MemberID1Selection").ToString()
End If
Return ""
End Get
Set(value As String)
ViewState("MemberID1Selection") = value
End Set
End Property
Protected Property MemberID2Selection() As String
Get
If ViewState("MemberID2Selection") IsNot Nothing Then
Return ViewState("MemberID2Selection").ToString()
End If
Return ""
End Get
Set(value As String)
ViewState("MemberID2Selection") = value
End Set
End Property
Protected Property MemberID3Selection() As String
Get
If ViewState("MemberID3Selection") IsNot Nothing Then
Return ViewState("MemberID3Selection").ToString()
End If
Return ""
End Get
Set(value As String)
ViewState("MemberID3Selection") = value
End Set
End Property
Protected Sub FillddlLocations()
FillDropdown(companyID1)
FillDropdown(companyID2)
FillDropdown(companyID3)
companyID1.Visible = True
companyID2.Visible = True
companyID3.Visible = True
End Sub
Protected Sub FillDropdown(ddl As DropDownList)
Using connAdd = New SqlConnection("Data Source = MENDOZAABBY-PC\SQLEXPRESS; Initial Catalog = ThesisDatabase; Integrated Security= True")
connAdd.Open()
Dim sql = "SELECT CompanyName FROM Company Where College = 'CCS'"
Using cmdAdd = New SqlDataAdapter(sql, connAdd)
Dim ds2 As New DataSet()
cmdAdd.Fill(ds2)
ddl.Items.Clear()
ddl.DataSource = ds2
ddl.DataTextField = "CompanyName"
ddl.DataValueField = "CompanyName"
ddl.DataBind()
ddl.Items.Insert(0, New ListItem("Please select a Company", ""))
ddl.SelectedIndex = 0
End Using
End Using
End Sub
Protected Sub IndexChanged(ddlChanged As DropDownList, ddlToFilter1 As DropDownList, ddlToFilter2 As DropDownList)
Dim removeValue1 As String = If(ddlChanged Is companyID1, MemberID1Selection, (If(ddlChanged Is companyID2, MemberID2Selection, MemberID3Selection)))
Dim selValue2 As String = If(ddlChanged Is companyID1, MemberID2Selection, (If(ddlChanged Is companyID2, MemberID1Selection, MemberID1Selection)))
Dim selValue3 As String = If(ddlChanged Is companyID1, MemberID3Selection, (If(ddlChanged Is companyID2, MemberID3Selection, MemberID2Selection)))
bFlag = False
'Prevent fireing the code again while changing the index
If removeValue1 <> "" Then
Dim item1 As ListItem = ddlToFilter1.Items.FindByValue(removeValue1)
ddlToFilter1.Items.Remove(item1)
Dim item2 As ListItem = ddlToFilter2.Items.FindByValue(removeValue1)
ddlToFilter2.Items.Remove(item2)
End If
If selValue3 <> "" Then
Dim item3 As ListItem = ddlToFilter1.Items.FindByValue(selValue3)
ddlToFilter1.Items.Remove(item3)
End If
If selValue2 <> "" Then
Dim item4 As ListItem = ddlToFilter2.Items.FindByValue(selValue2)
ddlToFilter2.Items.Remove(item4)
End If
bFlag = False
ddlToFilter1.SelectedIndex = ddlToFilter1.Items.IndexOf(ddlToFilter1.Items.FindByValue(selValue2))
ddlToFilter2.SelectedIndex = ddlToFilter2.Items.IndexOf(ddlToFilter2.Items.FindByValue(selValue3))
End Sub
Protected Sub ddlpid1_SelectedIndexChanged(sender As Object, e As EventArgs)
MemberID1Selection = companyID1.SelectedValue
If bFlag Then
FillDropdown(companyID2)
FillDropdown(companyID3)
IndexChanged(companyID1, companyID2, companyID3)
End If
End Sub
Protected Sub ddlpid2_SelectedIndexChanged(sender As Object, e As EventArgs)
MemberID2Selection = companyID2.SelectedValue
If bFlag Then
FillDropdown(companyID1)
FillDropdown(companyID3)
IndexChanged(companyID2, companyID1, companyID3)
End If
End Sub
Protected Sub ddlpid3_SelectedIndexChanged(sender As Object, e As EventArgs)
MemberID3Selection = companyID3.SelectedValue
If bFlag Then
FillDropdown(companyID1)
FillDropdown(companyID2)
IndexChanged(companyID3, companyID1, companyID2)
End If
End Sub
End Class
ASPX
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="companyID1" AutoPostBack="true" runat="server" Visible="false" OnSelectedIndexChanged="ddlpid1_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="companyID2" AutoPostBack="true" runat="server" Visible="false" OnSelectedIndexChanged="ddlpid2_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="companyID3" AutoPostBack="true" runat="server" Visible="false" OnSelectedIndexChanged="ddlpid3_SelectedIndexChanged" >
</asp:DropDownList>
</div>
</form>
</body>
</html>
Let Me give you an idea, which will work. Create a matrix object. It could be an array.
Items -> | red | orange | yellow | green |
Controls | | | | |
| | | | | |
V | | | | |
_________|______|________|________|_______|
combo1 |true | false | true |true |
_________|______|________|________|_______|
combo2 |true | false | true |true |
_________|______|________|________|_______|
combo3 |true | false | true |true |
_________|______|________|________|_______|
combo4 |true | true | true |true |
_________|______|________|________|_______|
Update:
According to this matrix your interface will have combo4 items - All, other combos will only have red, yellow and green.
when combo3 is clicked next and, for example, yellow selected you will fill the cell "combo3/yellow" with "true" and other remaining cells under yellow - "false".
Items -> | red | orange | yellow | green |
Controls | | | | |
| | | | | |
V | | | | |
_________|______|________|________|_______|
combo1 |true | false | false |true |
_________|______|________|________|_______|
combo2 |true | false | false |true |
_________|______|________|________|_______|
combo3 |true | false | true |true |
_________|______|________|________|_______|
combo4 |true | true | false |true |
_________|______|________|________|_______|
got the idea?
Now, develop logic that will set those "cells" to false as you click your combos.
In the beginning, all colors will be available to all controls - "true". Then you click one (any) combo. You reserve that control/color cell. Then you build your UI based on this matrix. With each click you have postback and your controls will be re-populated with available colors.
The best part - you will be able to have any number of controls or items for them. Once you run out of items or out of controls, you can't fill controls :o)

How to render a data table with multiple rowspan columns with ListView

I need to display data from a database in a html table. I am currently using a ListView control.
I want the final HTML table to render something like the following, where some rows have a rowspan attribute greater than one. The reason for this is that some fields have several rows of information, but correspond to the same logical entry.
For example:
|---------|---------|----------|----------|
| data | data |data | data |
| | |----------| |
| | |data | |
| | |----------| |
| | |data | |
|---------|---------|----------|----------|
| data | data |data | data |
| | |----------| |
| | |data | |
| | |----------| |
| | |data | |
|---------|---------|----------|----------|
| data | data |data | data |
| | |----------| |
| | |data | |
| | |----------| |
| | |data | |
| | |----------| |
| | |data | |
| | |----------| |
| | |data | |
|---------|---------|----------|----------|
What is the easiest way to accomplish this in ASP.net?
Not too elegant solution for ListView. The main idea is to use Repeater inside the ListView and bind all the sub-data(I mean data from the third column in your example) except the first record to it.
<asp:ListView runat="server" ID="lstData">
<LayoutTemplate>
<table>
<asp:PlaceHolder runat="server" ID="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td <%# GetRowspan((int)Eval("Data.Length")) %>>
<%# Eval("FirstName") %>
</td>
<td <%# GetRowspan((int)Eval("Data.Length")) %>>
<%# Eval("LastName") %>
</td>
<td>
<%# GetFirst((IEnumerable<string>)Eval("Data")) %>
</td>
<td <%# GetRowspan((int)Eval("Data.Length")) %>>
<%# Eval("Country") %>
</td>
</tr>
<asp:Repeater runat="server"
DataSource=<%# GetRest((IEnumerable<string>)Eval("Data")) %>>
<ItemTemplate>
<tr>
<td>
<%# Container.DataItem %>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:ListView>
and code behind:
public override void DataBind()
{
var item1 = new { FirstName = "John", LastName = "Doe",
Data = new[] { "first", "second", "third" }, Country = "US" };
var item2 = new { FirstName = "Jane", LastName = "Doe",
Data = new string[] { }, Country = "CA" };
var item3 = new { FirstName = "Joe", LastName = "Public",
Data = new[] { "first", "second", "third", "fourth" }, Country = "US" };
lstData.DataSource = new[] { item1, item2, item3 };
lstData.DataBind();
}
protected string GetRowspan(int length)
{
if (length == 0)
return string.Empty;
else
return string.Format("rowspan='{0}'", length);
}
protected string GetFirst(IEnumerable<string> data)
{
return data.FirstOrDefault();
}
protected IEnumerable<string> GetRest(IEnumerable<string> data)
{
if (data.Any())
return data.Skip(1);
else
return Enumerable.Empty<string>();
}
this outputs data in the format you want.
But if the usage of ListView is not necessary you could take a look onto GridView. There is more elegant way to do this by using it - ASP.NET GridView RowSpan using RowCreated Event - How to add Table Dynamic RowSpan with GridView article.
protected override void RenderContents(HtmlTextWriter output)
{
var builder = new StringBuilder();
builder.Append("<table>");
for(int i=0;i<dt1.rows.count;i++)
{
builder.Append("<tr>");
builder.Append("<td>");
builder.Append(dt1.rows[i].ToString());
builder.Append("</td>");
builder.Append("<td>");
builder.Append(dt1.rows[i].ToString());
builder.Append("</td>");
builder.Append("</td>");
builder.Append("<table>");
builder.Append("<tr>");
for(int j=0;i<dt2.rows.count;j++)
{
builder.Append("<td>");builder.Append(dt2.rows[j].ToString());
builder.Append("</td>");
}
builder.Append("</tr>");
builder.Append("</table>");
builder.Append("</tr>");
}
builder.Append("</table>");
output.Write(builder.ToString());
}
assume that dt1 as table1 and dt2 as inner table ...
so approach will help u out ...

Resources