Is er een manier om een ​​rij van een kind repeater en plaats deze in een ouder repeater rij / velden in ASP.NET C #?

stemmen
0

Ok, dus ik heb deze uitdaging en ik ben nog aan het leren hoe dingen werken in ASP C #. Ik heb een ouder-update paneel en binnen dat een ouder repeater. Binnen dat is een kind-update paneel (niet zeker hoe noodzakelijk dat is) en een kind repeater. Het Kind repeater is voor zoekresultaten. Wanneer de gebruiker klikt op het tekstvak voor het invoeren van de ouder repeater, een Ajax pop-up optreedt die hen in staat stelt om te zoeken naar de persoon die ze nodig hebben in ons LDAP AD systeem bij het kind updatepanel en wanneer ze een achternaam, voornaam (of beide) of een e-mail en klik op Zoeken, de code achter doet het werk, vindt de resultaten, vult de repeater en krijgt datagebonden. Ik heb dit allemaal gebeurt in de bovenliggende OnItemCommand en het werkt. Hier is mijn uitdaging - hoe in de wereld tot ik het kind rij via de knop geselecteerd onclick nemen en plaats de gegevens in de bovenliggende rij items?

Hier is mijn aspx code sectie, mijn excuses voor de opmaak:

<table class=project_info>    
                    <tr>
                        <td colspan=3>
                            <dl>
                                <dt>Project Stakeholders<br />
                                    <asp:Label runat=server ID=sh_SHHeader Text=Stakeholder Width=314></asp:Label>
                                    <asp:Label runat=server ID=sh_SHInput Text=Input Level Width=168></asp:Label>
                                </dt>
                                <asp:UpdatePanel runat=server ID=udp_SubProjectsTeamList UpdateMode=Conditional>
                                <ContentTemplate>
                                <asp:Repeater ID=AddStakeholder runat=server OnItemCommand=AddStakeholder_ItemCommand OnItemDataBound=AddStakeholder_ItemDataBound>
                                <ItemTemplate>
                                <dd>
                                    <asp:HiddenField ID=hdn_StakeholderId runat=server />
                                    <asp:HiddenField ID=hdn_StakeholderGUID runat=server />
                                    <asp:TextBox ID=txt_Stakeholder runat=server Width=304 onkeyup=hasPendingChanges() placeholder=Last Name, First Name Text='<%# DataBinder.Eval(Container.DataItem, MSStakeholder) %>'></asp:TextBox>&nbsp;
                                    <ajax:ModalPopupExtender runat=server ID=aj_AddStakeholder PopupControlID=pnl_AddStakeholderChild TargetControlID=txt_Stakeholder CancelControlID=PopCancelButton DropShadow=true Y=50></ajax:ModalPopupExtender>
                                    <asp:DropDownList ID=drp_SHInput runat=server AppendDataBoundItems=true SelectedIndex='<%# Convert.ToInt32(DataBinder.Eval(Container.DataItem,MSInput)) %>' Width=160 onchange=hasPendingChanges()>
                                        <asp:ListItem Text=Select Input Level Value=0 />
                                    </asp:DropDownList>&nbsp;
                                    <asp:Button ID=btnAddAnother runat=server CssClass=k-button k-button-icontext repeaterbutton Font-Size=small Text='<%# DataBinder.Eval(Container.DataItem, Button) %>' CommandName='<%# DataBinder.Eval(Container.DataItem, Button) %>' CausesValidation=false UseSubmitBehavior=false/>&nbsp;
                                    <asp:Button ID=btnReset runat=server CssClass=k-button k-button-icontext repeaterbutton Font-Size=small Font-Bold=false Text='Reset' ToolTip=Reset Entry OnClick=clearSHRow CausesValidation=false UseSubmitBehavior=false/>

                                    <asp:Panel ID=pnl_AddStakeholderChild runat=server >
                                    <div id=mainformdiv class=k-widget k-window shPopup>
                                        <div class=k-window-titlebar k-header>
                                            <span class=k-window-title>Stakeholder Search<asp:Button ID=PopCancelButton runat=server CssClass=k-button k-button-icontext Font-Size=small CausesValidation=false Text=X style=float:right; OnClientClick=this.form.reset();/></span>
                                        </div>
                                        <div class=k-popup-edit-form k-window-content k-content shPopupHead>
                                        <asp:UpdatePanel runat=server ID=udp_StakeholderSearch>
                                            <ContentTemplate>
                                                <div style=text-align:center;>
                                                    <asp:Label ID=lbl_LastName runat=server CssClass=shLabel Text=Last Name:/><asp:TextBox ID=txt_LastName runat=server Width=200/>&nbsp;<asp:Label ID=lbl_FirstName runat=server CssClass=shLabel Text=First Name:/><asp:TextBox ID=txt_FirstName runat=server Width=150/>&nbsp;&nbsp;OR<asp:Label ID=lbl_Email runat=server CssClass=shLabel Text=Email:/><asp:TextBox ID=txt_Email runat=server Width=200/>
                                                    <asp:Button ID=btn_Search  runat=server CssClass=k-button k-button-icontext Text=Search CausesValidation=false CommandName=Search></asp:Button>
                                                </div>
                                                <asp:Repeater ID=rpt_SHSearchResults runat=server>
                                                <HeaderTemplate>
                                                <div class=shPopupResults k-grid k-widget>
                                                    <table>
                                                        <thead class=k-grid-header>
                                                            <tr>
                                                                <th class=k-header rowspan=1>Stakeholder Name</th>
                                                                <th class=k-header rowspan=1>Title</th>
                                                                <th class=k-header rowspan=1>Organization</th>
                                                                <th class=k-header rowspan=1>Email</th>
                                                                <th class=k-header rowspan=1></th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                </HeaderTemplate>
                                                <ItemTemplate>
                                                        <asp:HiddenField ID=samaccountname runat=server Value='<%# Eval(userName) %>'/>
                                                        <asp:HiddenField ID=objectGUID runat=server Value='<%# Eval(userGUID) %>'/>
                                                            <tr class=k-alt>
                                                                <td><asp:Label runat=server ID=name Text='<%# Eval(FullName) %>' /></td>
                                                                <td><asp:Label runat=server ID=title Text='<%# Eval(Title) %>' /></td>
                                                                <td><asp:Label runat=server ID=company Text='<%# Eval(Company) %>' /></td>                                
                                                                <td><asp:Label runat=server ID=email Text='<%# Eval(Email) %>' /></td>
                                                                <td style=text-align: center;width:auto><asp:Button runat=server ID=btn_SHSelect CssClass=k-button k-button-icontext Text=Select CausesValidation=false UseSubmitBehavior=false/></td>
                                                            </tr>                           
                                                </ItemTemplate>
                                                <FooterTemplate>    
                                                        </tbody>
                                                    </table>
                                                </div>
                                                </FooterTemplate>
                                                </asp:Repeater>
                                                <asp:Panel ID=pnl_EmptyList runat=server Visible=false>
                                                <div class=shEmptyResults k-grid k-widget>
                                                    <table>
                                                        <tr class=k-alt>
                                                            <td colspan=5>
                                                                <asp:Label ID=lbl_EmptyList runat=server BorderWidth=0></asp:Label>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </div>
                                                </asp:Panel>
                                                <asp:Panel ID=pnl_Results runat=server Visible=false>
                                                <div class=shPopupHead>
                                                    <span class=k-window-title><asp:Label runat=server ID=resultCount style=float:left; /></span>
                                                </div>                                                
                                                </asp:Panel>
                                            </ContentTemplate>
                                        </asp:UpdatePanel>
                                        <asp:UpdateProgress ID=udp_SearchProgress runat=server AssociatedUpdatePanelID=udp_StakeholderSearch>
                                            <ProgressTemplate>
                                                <div class=shEmptyResults k-grid k-widget>
                                                    <table>
                                                        <tr class=k-alt>
                                                            <td colspan=5 style=background:#fff><img src=env/images/searching.gif />
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </div>
                                            </ProgressTemplate>
                                        </asp:UpdateProgress>
                                        </div>
                                    </div>
                                    </asp:Panel>
                                </dd>
                                </ItemTemplate>
                                </asp:Repeater>
                                </ContentTemplate>
                                </asp:UpdatePanel>
                            </dl>
                        </td>
                    </tr>    
                </table>

En de .cs code achter:

    protected void AddStakeholder_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        int Total = AddStakeholder.Items.Count; //get total items in repeater

        if (e.CommandName ==  + )
        {
            Total = Total + 1; //increase 1 because of add

            AddSHColumns();

            foreach (RepeaterItem item in AddStakeholder.Items)
            {
                //getting the values of user entered fields
                string txt_Stakeholder = ((TextBox)item.FindControl(txt_Stakeholder)).Text;
                int drp_SHInput = ((DropDownList)item.FindControl(drp_SHInput)).SelectedIndex;
                Button btnAdd = ((Button)item.FindControl(btnAddAnother));

                //now change button text to remove, and save user entered values in table
                tbSHolder.Rows.Add(txt_Stakeholder, drp_SHInput,  - );
            }

            //Add dummy row, because we need to increase
            tbSHolder.Rows.Add(, 0,  + );

            BindWithSHRepeater();
        }
        else if (e.CommandName ==  - )
        {
            Total = Total - 1;
            tbSHolder.Columns.Add(MSStakeholder);
            tbSHolder.Columns.Add(MSInput);
            tbSHolder.Columns.Add(Button);

            foreach (RepeaterItem item in AddStakeholder.Items)
            {
                Button btnAdd = ((Button)item.FindControl(btnAddAnother));
                if (btnAdd != e.CommandSource) //the current row on which user click will removed
                {
                    string txt_Stakeholder = ((TextBox)item.FindControl(txt_Stakeholder)).Text;
                    int drp_SHInput = ((DropDownList)item.FindControl(drp_SHInput)).SelectedIndex;

                    if (btnAdd.Text ==  - )
                    {
                        tbSHolder.Rows.Add(txt_Stakeholder, drp_SHInput,  - );
                    }
                    else
                    {
                        tbSHolder.Rows.Add(txt_Stakeholder, drp_SHInput,  + );
                    }
                }
            }
            BindWithSHRepeater();
        }
        else if (e.CommandName == Search)
        {
            string last_name = ((TextBox)e.Item.FindControl(txt_LastName)).Text;
            string first_name = ((TextBox)e.Item.FindControl(txt_FirstName)).Text;
            string email = ((TextBox)e.Item.FindControl(txt_Email)).Text;
            TextBox test = ((TextBox)e.Item.FindControl(txt_Email));

            string searchFilter = ;

            if (!string.IsNullOrWhiteSpace(last_name) && string.IsNullOrWhiteSpace(first_name) && string.IsNullOrWhiteSpace(email))
            {
                searchFilter = (&(objectCategory=person)(objectClass=user)(company=*)(sn= + last_name + )(!(UserAccountControl:1.2.840.113556.1.4.803:=2)));
            }
            else if (!string.IsNullOrWhiteSpace(last_name) && !string.IsNullOrWhiteSpace(first_name) && string.IsNullOrWhiteSpace(email))
            {
                searchFilter = (&(objectCategory=person)(objectClass=user)(company=*)(sn= + last_name + )(givenName= + first_name + )(!(UserAccountControl:1.2.840.113556.1.4.803:=2)));
            }
            else if (!string.IsNullOrWhiteSpace(email))
            {
                searchFilter = (&(objectCategory=person)(objectClass=user)(company=*)(userPrincipalName= + email + )(!(UserAccountControl:1.2.840.113556.1.4.803:=2)));
            }
            //output.Text = (&(objectCategory=person)(objectClass=user) + searchFilter + );
            DirectoryEntry domain = new DirectoryEntry(my company's LDAP server information);
            DirectorySearcher dsLookFor = new DirectorySearcher(domain)
            {
                SearchScope = SearchScope.Subtree,
                Filter = searchFilter
            };
            //dsLookFor.Filter = searchFilter;
            dsLookFor.PropertiesToLoad.Add(sAMAccountName);
            dsLookFor.PropertiesToLoad.Add(objectGUID);
            dsLookFor.PropertiesToLoad.Add(name);
            dsLookFor.PropertiesToLoad.Add(title);
            dsLookFor.PropertiesToLoad.Add(company);
            dsLookFor.PropertiesToLoad.Add(userPrincipalName);
            dsLookFor.Sort.Direction = System.DirectoryServices.SortDirection.Ascending;
            dsLookFor.Sort.PropertyName = name;

            SearchResultCollection result = dsLookFor.FindAll();
            int totalCount = result.Count;
            var users = result.Cast<SearchResult>().Select(sr => sr.GetDirectoryEntry()).Select(de => new
            {
                userName = de.Properties[sAMAccountName].Value != null ? protectSpecialChar((string)de.Properties[sAMAccountName].Value) : ,
                userGUID = de.Properties[objectGUID].Value != null ? new Guid((byte[])de.Properties[objectGUID].Value).ToString() : ,
                FullName = de.Properties[name].Value != null ? protectSpecialChar((string)de.Properties[name].Value) : ,
                Title = de.Properties[title].Value != null ? protectSpecialChar((string)de.Properties[title].Value) : ,
                Company = de.Properties[company].Value != null ? protectSpecialChar((string)de.Properties[company].Value) : ,
                Email = de.Properties[userPrincipalName].Value != null ? protectSpecialChar((string)de.Properties[userPrincipalName].Value) : ,
            }).ToList();

            if (totalCount == 0)
            {
                ((Panel)e.Item.FindControl(pnl_EmptyList)).Visible = true;
                ((Label)e.Item.FindControl(lbl_EmptyList)).Text = No results to display. Please check your entries and try again.;
            }
            else
            {
                rpt_SHSearchResults.DataSource = users;
                rpt_SHSearchResults.DataBind();
                rpt_SHSearchResults.Visible = true;
                ((Panel)e.Item.FindControl(pnl_Results)).Visible = true;
                ((Label)e.Item.FindControl(resultCount)).Text = Result count:  + totalCount;
            }
        }
    }
    protected void AddStakeholder_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HiddenField hdn_StakeholderId = e.Item.FindControl(hdn_StakeholderId) as HiddenField;
            HiddenField hdn_StakeholderGUID = e.Item.FindControl(hdn_StakeholderGUID) as HiddenField;
            TextBox txt_Stakeholder = e.Item.FindControl(txt_Stakeholder) as TextBox;
            DropDownList drp_SHInput = e.Item.FindControl(drp_SHInput) as DropDownList;
            DataSet shInputSet = new DataSet();

            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[ndcol_dashboard].ConnectionString))
            {
                con.Open();

                //Contractor List dropdown
                SqlDataAdapter shInput = new SqlDataAdapter(SELECT StakeholderInputId,InputName FROM StakeholderInput, con);
                shInput.Fill(shInputSet);
                drp_SHInput.DataSource = shInputSet;
                drp_SHInput.DataTextField = InputName;
                drp_SHInput.DataValueField = StakeholderInputId;
                drp_SHInput.DataBind();

                con.Close();
            }
            Repeater shSearchResults = e.Item.FindControl(rpt_SHSearchResults) as Repeater;
            HiddenField userName = shSearchResults.FindControl(samaccountname) as HiddenField;
            HiddenField userGUID = shSearchResults.FindControl(objectGUID) as HiddenField;
            Label name = shSearchResults.FindControl(name) as Label;
            Label title = shSearchResults.FindControl(title) as Label;
            Label company = shSearchResults.FindControl(company) as Label;
            Label email = shSearchResults.FindControl(email) as Label;
        }
    }

Moet ik een OnClick = dosomethinghere op het kind repeater knop Select en neem dan het kind rij informatie en proberen om het te injecteren in de ouder controles? Hoe zou dat worden bereikt?

Ik heb alles wat ik kan bedenken om dit werk te maken geprobeerd, en ik heb talloze zoekopdrachten in Google en SO en elders gedaan om te zien of iemand anders dit probleem heeft opgelost. Ik ben over een gemiddeld niveau coder en deze heeft me stumped. Hoe krijg ik de geselecteerde resultaat rij van het kind repeater in de bovenliggende rij?

Bedankt voor de hulp!

De vraag is gesteld op 03/12/2019 om 00:00
bron van user
In andere talen...                            


1 antwoorden

Is er een manier om een ​​rij van een kind repeater en plaats deze in een ouder repeater rij / velden in ASP.NET C #?

stemmen
0

Ok, dus ik heb deze uitdaging en ik ben nog aan het leren hoe dingen werken in ASP C #. Ik heb een ouder-update paneel en binnen dat een ouder repeater. Binnen dat is een kind-update paneel (niet zeker hoe noodzakelijk dat is) en een kind repeater. Het Kind repeater is voor zoekresultaten. Wanneer de gebruiker klikt op het tekstvak voor het invoeren van de ouder repeater, een Ajax pop-up optreedt die hen in staat stelt om te zoeken naar de persoon die ze nodig hebben in ons LDAP AD systeem bij het kind updatepanel en wanneer ze een achternaam, voornaam (of beide) of een e-mail en klik op "Zoeken", de code achter doet het werk, vindt de resultaten, vult de repeater en krijgt datagebonden. Ik heb dit allemaal gebeurt in de bovenliggende OnItemCommand en het werkt. Hier is mijn uitdaging - hoe in de wereld tot ik het kind rij via de knop geselecteerd onclick nemen en plaats de gegevens in de bovenliggende rij items?

Hier is mijn aspx code sectie, mijn excuses voor de opmaak:

<table class="project_info">    
                    <tr>
                        <td colspan="3">
                            <dl>
                                <dt>Project Stakeholders<br />
                                    <asp:Label runat="server" ID="sh_SHHeader" Text="Stakeholder" Width="314"></asp:Label>
                                    <asp:Label runat="server" ID="sh_SHInput" Text="Input Level" Width="168"></asp:Label>
                                </dt>
                                <asp:UpdatePanel runat="server" ID="udp_SubProjectsTeamList" UpdateMode="Conditional">
                                <ContentTemplate>
                                <asp:Repeater ID="AddStakeholder" runat="server" OnItemCommand="AddStakeholder_ItemCommand" OnItemDataBound="AddStakeholder_ItemDataBound">
                                <ItemTemplate>
                                <dd>
                                    <asp:HiddenField ID="hdn_StakeholderId" runat="server" />
                                    <asp:HiddenField ID="hdn_StakeholderGUID" runat="server" />
                                    <asp:TextBox ID="txt_Stakeholder" runat="server" Width="304" onkeyup="hasPendingChanges()" placeholder="Last Name, First Name" Text='<%# DataBinder.Eval(Container.DataItem, "MSStakeholder") %>'></asp:TextBox>&nbsp;
                                    <ajax:ModalPopupExtender runat="server" ID="aj_AddStakeholder" PopupControlID="pnl_AddStakeholderChild" TargetControlID="txt_Stakeholder" CancelControlID="PopCancelButton" DropShadow="true" Y="50"></ajax:ModalPopupExtender>
                                    <asp:DropDownList ID="drp_SHInput" runat="server" AppendDataBoundItems="true" SelectedIndex='<%# Convert.ToInt32(DataBinder.Eval(Container.DataItem,"MSInput")) %>' Width="160" onchange="hasPendingChanges()">
                                        <asp:ListItem Text="Select Input Level" Value="0" />
                                    </asp:DropDownList>&nbsp;
                                    <asp:Button ID="btnAddAnother" runat="server" CssClass="k-button k-button-icontext repeaterbutton" Font-Size="small" Text='<%# DataBinder.Eval(Container.DataItem, "Button") %>' CommandName='<%# DataBinder.Eval(Container.DataItem, "Button") %>' CausesValidation="false" UseSubmitBehavior="false"/>&nbsp;
                                    <asp:Button ID="btnReset" runat="server" CssClass="k-button k-button-icontext repeaterbutton" Font-Size="small" Font-Bold="false" Text='Reset' ToolTip="Reset Entry" OnClick="clearSHRow" CausesValidation="false" UseSubmitBehavior="false"/>

                                    <asp:Panel ID="pnl_AddStakeholderChild" runat="server" >
                                    <div id="mainformdiv" class="k-widget k-window shPopup">
                                        <div class="k-window-titlebar k-header">
                                            <span class="k-window-title">Stakeholder Search<asp:Button ID="PopCancelButton" runat="server" CssClass="k-button k-button-icontext" Font-Size="small" CausesValidation="false" Text="X" style="float:right;" OnClientClick="this.form.reset();"/></span>
                                        </div>
                                        <div class="k-popup-edit-form k-window-content k-content shPopupHead">
                                        <asp:UpdatePanel runat="server" ID="udp_StakeholderSearch">
                                            <ContentTemplate>
                                                <div style="text-align:center;">
                                                    <asp:Label ID="lbl_LastName" runat="server" CssClass="shLabel" Text="Last Name:"/><asp:TextBox ID="txt_LastName" runat="server" Width="200"/>&nbsp;<asp:Label ID="lbl_FirstName" runat="server" CssClass="shLabel" Text="First Name:"/><asp:TextBox ID="txt_FirstName" runat="server" Width="150"/>&nbsp;&nbsp;OR<asp:Label ID="lbl_Email" runat="server" CssClass="shLabel" Text="Email:"/><asp:TextBox ID="txt_Email" runat="server" Width="200"/>
                                                    <asp:Button ID="btn_Search"  runat="server" CssClass="k-button k-button-icontext" Text="Search" CausesValidation="false" CommandName="Search"></asp:Button>
                                                </div>
                                                <asp:Repeater ID="rpt_SHSearchResults" runat="server">
                                                <HeaderTemplate>
                                                <div class="shPopupResults k-grid k-widget">
                                                    <table>
                                                        <thead class="k-grid-header">
                                                            <tr>
                                                                <th class="k-header" rowspan="1">Stakeholder Name</th>
                                                                <th class="k-header" rowspan="1">Title</th>
                                                                <th class="k-header" rowspan="1">Organization</th>
                                                                <th class="k-header" rowspan="1">Email</th>
                                                                <th class="k-header" rowspan="1"></th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                </HeaderTemplate>
                                                <ItemTemplate>
                                                        <asp:HiddenField ID="samaccountname" runat="server" Value='<%# Eval("userName") %>'/>
                                                        <asp:HiddenField ID="objectGUID" runat="server" Value='<%# Eval("userGUID") %>'/>
                                                            <tr class="k-alt">
                                                                <td><asp:Label runat="server" ID="name" Text='<%# Eval("FullName") %>' /></td>
                                                                <td><asp:Label runat="server" ID="title" Text='<%# Eval("Title") %>' /></td>
                                                                <td><asp:Label runat="server" ID="company" Text='<%# Eval("Company") %>' /></td>                                
                                                                <td><asp:Label runat="server" ID="email" Text='<%# Eval("Email") %>' /></td>
                                                                <td style="text-align: center;width:auto"><asp:Button runat="server" ID="btn_SHSelect" CssClass="k-button k-button-icontext" Text="Select" CausesValidation="false" UseSubmitBehavior="false"/></td>
                                                            </tr>                           
                                                </ItemTemplate>
                                                <FooterTemplate>    
                                                        </tbody>
                                                    </table>
                                                </div>
                                                </FooterTemplate>
                                                </asp:Repeater>
                                                <asp:Panel ID="pnl_EmptyList" runat="server" Visible="false">
                                                <div class="shEmptyResults k-grid k-widget">
                                                    <table>
                                                        <tr class="k-alt">
                                                            <td colspan="5">
                                                                <asp:Label ID="lbl_EmptyList" runat="server" BorderWidth="0"></asp:Label>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </div>
                                                </asp:Panel>
                                                <asp:Panel ID="pnl_Results" runat="server" Visible="false">
                                                <div class="shPopupHead">
                                                    <span class="k-window-title"><asp:Label runat="server" ID="resultCount" style="float:left;" /></span>
                                                </div>                                                
                                                </asp:Panel>
                                            </ContentTemplate>
                                        </asp:UpdatePanel>
                                        <asp:UpdateProgress ID="udp_SearchProgress" runat="server" AssociatedUpdatePanelID="udp_StakeholderSearch">
                                            <ProgressTemplate>
                                                <div class="shEmptyResults k-grid k-widget">
                                                    <table>
                                                        <tr class="k-alt">
                                                            <td colspan="5" style="background:#fff"><img src="env/images/searching.gif" />
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </div>
                                            </ProgressTemplate>
                                        </asp:UpdateProgress>
                                        </div>
                                    </div>
                                    </asp:Panel>
                                </dd>
                                </ItemTemplate>
                                </asp:Repeater>
                                </ContentTemplate>
                                </asp:UpdatePanel>
                            </dl>
                        </td>
                    </tr>    
                </table>

En de .cs code achter:

    protected void AddStakeholder_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        int Total = AddStakeholder.Items.Count; //get total items in repeater

        if (e.CommandName == " + ")
        {
            Total = Total + 1; //increase 1 because of add

            AddSHColumns();

            foreach (RepeaterItem item in AddStakeholder.Items)
            {
                //getting the values of user entered fields
                string txt_Stakeholder = ((TextBox)item.FindControl("txt_Stakeholder")).Text;
                int drp_SHInput = ((DropDownList)item.FindControl("drp_SHInput")).SelectedIndex;
                Button btnAdd = ((Button)item.FindControl("btnAddAnother"));

                //now change button text to remove, and save user entered values in table
                tbSHolder.Rows.Add(txt_Stakeholder, drp_SHInput, " - ");
            }

            //Add dummy row, because we need to increase
            tbSHolder.Rows.Add("", 0, " + ");

            BindWithSHRepeater();
        }
        else if (e.CommandName == " - ")
        {
            Total = Total - 1;
            tbSHolder.Columns.Add("MSStakeholder");
            tbSHolder.Columns.Add("MSInput");
            tbSHolder.Columns.Add("Button");

            foreach (RepeaterItem item in AddStakeholder.Items)
            {
                Button btnAdd = ((Button)item.FindControl("btnAddAnother"));
                if (btnAdd != e.CommandSource) //the current row on which user click will removed
                {
                    string txt_Stakeholder = ((TextBox)item.FindControl("txt_Stakeholder")).Text;
                    int drp_SHInput = ((DropDownList)item.FindControl("drp_SHInput")).SelectedIndex;

                    if (btnAdd.Text == " - ")
                    {
                        tbSHolder.Rows.Add(txt_Stakeholder, drp_SHInput, " - ");
                    }
                    else
                    {
                        tbSHolder.Rows.Add(txt_Stakeholder, drp_SHInput, " + ");
                    }
                }
            }
            BindWithSHRepeater();
        }
        else if (e.CommandName == "Search")
        {
            string last_name = ((TextBox)e.Item.FindControl("txt_LastName")).Text;
            string first_name = ((TextBox)e.Item.FindControl("txt_FirstName")).Text;
            string email = ((TextBox)e.Item.FindControl("txt_Email")).Text;
            TextBox test = ((TextBox)e.Item.FindControl("txt_Email"));

            string searchFilter = "";

            if (!string.IsNullOrWhiteSpace(last_name) && string.IsNullOrWhiteSpace(first_name) && string.IsNullOrWhiteSpace(email))
            {
                searchFilter = "(&(objectCategory=person)(objectClass=user)(company=*)(sn=" + last_name + ")(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))";
            }
            else if (!string.IsNullOrWhiteSpace(last_name) && !string.IsNullOrWhiteSpace(first_name) && string.IsNullOrWhiteSpace(email))
            {
                searchFilter = "(&(objectCategory=person)(objectClass=user)(company=*)(sn=" + last_name + ")(givenName=" + first_name + ")(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))";
            }
            else if (!string.IsNullOrWhiteSpace(email))
            {
                searchFilter = "(&(objectCategory=person)(objectClass=user)(company=*)(userPrincipalName=" + email + ")(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))";
            }
            //output.Text = "(&(objectCategory=person)(objectClass=user)" + searchFilter + ")";
            DirectoryEntry domain = new DirectoryEntry("my company's LDAP server information");
            DirectorySearcher dsLookFor = new DirectorySearcher(domain)
            {
                SearchScope = SearchScope.Subtree,
                Filter = searchFilter
            };
            //dsLookFor.Filter = searchFilter;
            dsLookFor.PropertiesToLoad.Add("sAMAccountName");
            dsLookFor.PropertiesToLoad.Add("objectGUID");
            dsLookFor.PropertiesToLoad.Add("name");
            dsLookFor.PropertiesToLoad.Add("title");
            dsLookFor.PropertiesToLoad.Add("company");
            dsLookFor.PropertiesToLoad.Add("userPrincipalName");
            dsLookFor.Sort.Direction = System.DirectoryServices.SortDirection.Ascending;
            dsLookFor.Sort.PropertyName = "name";

            SearchResultCollection result = dsLookFor.FindAll();
            int totalCount = result.Count;
            var users = result.Cast<SearchResult>().Select(sr => sr.GetDirectoryEntry()).Select(de => new
            {
                userName = de.Properties["sAMAccountName"].Value != null ? protectSpecialChar((string)de.Properties["sAMAccountName"].Value) : "",
                userGUID = de.Properties["objectGUID"].Value != null ? new Guid((byte[])de.Properties["objectGUID"].Value).ToString() : "",
                FullName = de.Properties["name"].Value != null ? protectSpecialChar((string)de.Properties["name"].Value) : "",
                Title = de.Properties["title"].Value != null ? protectSpecialChar((string)de.Properties["title"].Value) : "",
                Company = de.Properties["company"].Value != null ? protectSpecialChar((string)de.Properties["company"].Value) : "",
                Email = de.Properties["userPrincipalName"].Value != null ? protectSpecialChar((string)de.Properties["userPrincipalName"].Value) : "",
            }).ToList();

            if (totalCount == 0)
            {
                ((Panel)e.Item.FindControl("pnl_EmptyList")).Visible = true;
                ((Label)e.Item.FindControl("lbl_EmptyList")).Text = "No results to display. Please check your entries and try again.";
            }
            else
            {
                rpt_SHSearchResults.DataSource = users;
                rpt_SHSearchResults.DataBind();
                rpt_SHSearchResults.Visible = true;
                ((Panel)e.Item.FindControl("pnl_Results")).Visible = true;
                ((Label)e.Item.FindControl("resultCount")).Text = "Result count: " + totalCount;
            }
        }
    }
    protected void AddStakeholder_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HiddenField hdn_StakeholderId = e.Item.FindControl("hdn_StakeholderId") as HiddenField;
            HiddenField hdn_StakeholderGUID = e.Item.FindControl("hdn_StakeholderGUID") as HiddenField;
            TextBox txt_Stakeholder = e.Item.FindControl("txt_Stakeholder") as TextBox;
            DropDownList drp_SHInput = e.Item.FindControl("drp_SHInput") as DropDownList;
            DataSet shInputSet = new DataSet();

            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ndcol_dashboard"].ConnectionString))
            {
                con.Open();

                //Contractor List dropdown
                SqlDataAdapter shInput = new SqlDataAdapter("SELECT StakeholderInputId,InputName FROM StakeholderInput", con);
                shInput.Fill(shInputSet);
                drp_SHInput.DataSource = shInputSet;
                drp_SHInput.DataTextField = "InputName";
                drp_SHInput.DataValueField = "StakeholderInputId";
                drp_SHInput.DataBind();

                con.Close();
            }
            Repeater shSearchResults = e.Item.FindControl("rpt_SHSearchResults") as Repeater;
            HiddenField userName = shSearchResults.FindControl("samaccountname") as HiddenField;
            HiddenField userGUID = shSearchResults.FindControl("objectGUID") as HiddenField;
            Label name = shSearchResults.FindControl("name") as Label;
            Label title = shSearchResults.FindControl("title") as Label;
            Label company = shSearchResults.FindControl("company") as Label;
            Label email = shSearchResults.FindControl("email") as Label;
        }
    }

Moet ik een OnClick = "dosomethinghere" op het kind repeater knop "Select" en neem dan het kind rij informatie en proberen om het te injecteren in de ouder controles? Hoe zou dat worden bereikt?

Ik heb alles wat ik kan bedenken om dit werk te maken geprobeerd, en ik heb talloze zoekopdrachten in Google en SO en elders gedaan om te zien of iemand anders dit probleem heeft opgelost. Ik ben over een gemiddeld niveau coder en deze heeft me stumped. Hoe krijg ik de geselecteerde resultaat rij van het kind repeater in de bovenliggende rij?

Bedankt voor de hulp!

antwoordde op 03/12/2019 om 00:00
bron van user

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more