Gibt es eine Möglichkeit, eine Reihe von einem Kind Repeater auswählen und in ein übergeordneten Repeater Reihe / Felder in ASP.NET C # einfügen?

stimmen
0

Ok, so habe ich diese Herausforderung, und ich bin immer noch lernen, wie die Dinge in ASP C # arbeiten. Ich habe eine übergeordnete Update-Panel und im Inneren, die ein Elternteil Repeater ist. Innerhalb das ist ein Kind Update-Panel (nicht sicher, wie notwendig das ist) und ein Kind Repeater. Das Kind Repeater ist für die Suchergebnisse. Wenn der Benutzer klickt auf das Textfeld für die Eingabe des übergeordneten Repeater, tritt ein Ajax Pop-up, dass ermöglicht es ihnen, für die Person zu suchen, sie in dem Kind Update in unserem LDAP AD-System benötigen, und wenn sie geben Sie einen Nachnamen, Vornamen (oder beide) oder eine E-Mail und klicken sie auf „suchen“, der Code hinter macht es die Arbeit, findet die Ergebnisse, füllt den Repeater und bekommt Databound. Ich habe das alles in den Eltern geschieht OnItemCommand und es funktioniert. Hier ist meine Herausforderung - wie in der Welt ich das Kind Reihe über die Taste ausgewählt nehmen Onclick und legen Sie die Daten in die übergeordnete Zeile Artikel?

Hier ist meine aspx Codeabschnitt, ich für die Formatierung entschuldigen:

<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>

Und der .cs Code hinter:

    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;
        }
    }

Soll ich einen OnClick = „dosomethinghere“ auf der Kind-Repeater-Taste „Select“ und dann die Kind Zeileninformationen nehmen und versuchen, sie in die übergeordneten Steuerung zu injizieren? Wie würde das erreicht werden?

Ich habe alles versucht, ich mich vorstellen kann, diese Arbeit zu machen, und ich habe unzählige Suche in Google und SO getan und an anderer Stelle zu sehen, ob jemand dieses Problem gelöst hat. Ich bin über einen Zwischen Ebenenkodierer und dieser hat mich ratlos. Wie erhalte ich die ausgewählte Ergebniszeile aus dem untergeordneten Repeater in die übergeordneten Zeile?

Danke für die Hilfe!

Veröffentlicht am 03/12/2019 um 00:00
quelle vom benutzer
In anderen Sprachen...                            


1 antworten

Gibt es eine Möglichkeit, eine Reihe von einem Kind Repeater auswählen und in ein übergeordneten Repeater Reihe / Felder in ASP.NET C # einfügen?

stimmen
0

Ok, so habe ich diese Herausforderung, und ich bin immer noch lernen, wie die Dinge in ASP C # arbeiten. Ich habe eine übergeordnete Update-Panel und im Inneren, die ein Elternteil Repeater ist. Innerhalb das ist ein Kind Update-Panel (nicht sicher, wie notwendig das ist) und ein Kind Repeater. Das Kind Repeater ist für die Suchergebnisse. Wenn der Benutzer klickt auf das Textfeld für die Eingabe des übergeordneten Repeater, tritt ein Ajax Pop-up, dass ermöglicht es ihnen, für die Person zu suchen, sie in dem Kind Update in unserem LDAP AD-System benötigen, und wenn sie geben Sie einen Nachnamen, Vornamen (oder beide) oder eine E-Mail und klicken sie auf „suchen“, der Code hinter macht es die Arbeit, findet die Ergebnisse, füllt den Repeater und bekommt Databound. Ich habe das alles in den Eltern geschieht OnItemCommand und es funktioniert. Hier ist meine Herausforderung - wie in der Welt ich das Kind Reihe über die Taste ausgewählt nehmen Onclick und legen Sie die Daten in die übergeordnete Zeile Artikel?

Hier ist meine aspx Codeabschnitt, ich für die Formatierung entschuldigen:

<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>

Und der .cs Code hinter:

    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;
        }
    }

Soll ich einen OnClick = „dosomethinghere“ auf der Kind-Repeater-Taste „Select“ und dann die Kind Zeileninformationen nehmen und versuchen, sie in die übergeordneten Steuerung zu injizieren? Wie würde das erreicht werden?

Ich habe alles versucht, ich mich vorstellen kann, diese Arbeit zu machen, und ich habe unzählige Suche in Google und SO getan und an anderer Stelle zu sehen, ob jemand dieses Problem gelöst hat. Ich bin über einen Zwischen Ebenenkodierer und dieser hat mich ratlos. Wie erhalte ich die ausgewählte Ergebniszeile aus dem untergeordneten Repeater in die übergeordneten Zeile?

Danke für die Hilfe!

Beantwortet am 03/12/2019 um 00:00
quelle vom benutzer

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