Czy istnieje sposób, aby wybrać wiersz z repeatera dzieci i włóż ją do rodzica repeater wiersz / pól w ASP.NET C #?

głosy
0

Ok, więc mam to wyzwanie i wciąż się uczę jak rzeczy działają w ASP C #. Mam panelu aktualizacji rodzic i wewnątrz, który jest repeater rodzicem. Wewnątrz jest to panel zmiana dziecko (nie wiem, jak to jest konieczne) i repeater dziecko. Powielacz Dziecko jest dla wyników wyszukiwania. Kiedy użytkownik kliknie w pole tekstowe do wprowadzenia repeatera dominującej, Ajax pojawiają się zdarza, że ​​pozwala im szukać osoby, których potrzebują w naszym systemie AD LDAP w updatepanel dziecka i kiedy podać nazwisko, imię (lub oba) lub e-mail i kliknij przycisk „Szukaj”, to za kod nie jest to praca, uważa wyniki, zapełnia repeater i dostaje z danymi. Mam to wszystko dzieje się w dominującej OnItemCommand i to działa. Oto mój wyzwanie - jak w świecie Biorę dziecko wybrany wiersz przyciskiem onclick i wstawić dane do pozycji dominującej Row?

Oto mój odcinek kod aspx, przepraszam za formatowania:

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

A za kod .cs:

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

Powinienem mieć OnClick = „dosomethinghere” na repeater przycisku dziecięcej „Select”, a następnie podjąć informacje wiersza dzieci i próbować wstrzyknąć go do kontroli rodzicielskich? Jak to osiągnąć?

Próbowałem wszystkiego można myślę do tej pracy, a ja zrobiłem niezliczoną ilość wyszukiwań w Google i tak i poza nią, aby zobaczyć, czy ktoś rozwiązał ten problem. Jestem o pośrednim poziomie kodera i ten jeden ma mnie stumped. Jak mogę dostać wybrany wiersz wynikają z repeatera dziecko do wiersza nadrzędnego?

Dziękuję za pomoc!

Utwórz 03/12/2019 o 00:00
źródło użytkownik
W innych językach...                            


1 odpowiedzi

Czy istnieje sposób, aby wybrać wiersz z repeatera dzieci i włóż ją do rodzica repeater wiersz / pól w ASP.NET C #?

głosy
0

Ok, więc mam to wyzwanie i wciąż się uczę jak rzeczy działają w ASP C #. Mam panelu aktualizacji rodzic i wewnątrz, który jest repeater rodzicem. Wewnątrz jest to panel zmiana dziecko (nie wiem, jak to jest konieczne) i repeater dziecko. Powielacz Dziecko jest dla wyników wyszukiwania. Kiedy użytkownik kliknie w pole tekstowe do wprowadzenia repeatera dominującej, Ajax pojawiają się zdarza, że ​​pozwala im szukać osoby, których potrzebują w naszym systemie AD LDAP w updatepanel dziecka i kiedy podać nazwisko, imię (lub oba) lub e-mail i kliknij przycisk „Szukaj”, to za kod nie jest to praca, uważa wyniki, zapełnia repeater i dostaje z danymi. Mam to wszystko dzieje się w dominującej OnItemCommand i to działa. Oto mój wyzwanie - jak w świecie Biorę dziecko wybrany wiersz przyciskiem onclick i wstawić dane do pozycji dominującej Row?

Oto mój odcinek kod aspx, przepraszam za formatowania:

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

A za kod .cs:

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

Powinienem mieć OnClick = „dosomethinghere” na repeater przycisku dziecięcej „Select”, a następnie podjąć informacje wiersza dzieci i próbować wstrzyknąć go do kontroli rodzicielskich? Jak to osiągnąć?

Próbowałem wszystkiego można myślę do tej pracy, a ja zrobiłem niezliczoną ilość wyszukiwań w Google i tak i poza nią, aby zobaczyć, czy ktoś rozwiązał ten problem. Jestem o pośrednim poziomie kodera i ten jeden ma mnie stumped. Jak mogę dostać wybrany wiersz wynikają z repeatera dziecko do wiersza nadrzędnego?

Dziękuję za pomoc!

Odpowiedział 03/12/2019 o 00:00
źródło użytkownik

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