Er det en måte å velge en rad fra et barn repeater og sette det inn i en overordnet repeater rad / felt i ASP.NET C #?

stemmer
0

Ok, så jeg har denne utfordringen, og jeg er fortsatt læring hvordan ting fungerer i ASP C #. Jeg har en overordnet oppdatering panel og innsiden som er en overordnet repeater. Innsiden som er et barn oppdatering panel (ikke sikker på hvor nødvendig det er) og et barn repeater. Barne repeater er for søkeresultatene. Når brukeren klikker på tekstboksen for oppføring av den overordnede repeater, en Ajax pop up oppstår som tillater dem å søke etter den personen de trenger i vår LDAP AD system i barnets Update og når de skriver inn et etternavn, fornavn (eller begge) eller en e-post og trykk Søk, koden bak gjør det arbeid, finner resultatene, fylles repeater og får databound. Jeg har alt dette skjer i den overordnede OnItemCommand og det fungerer. Her er min utfordring - hvordan i all verden å jeg ta barnet rad velges via knappen onclick og sette inn data i de overordnede rad elementer?

Her er min aspx kode delen, jeg beklager formatering:

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

Og .CS koden bak:

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

Bør jeg ha en onclick = dosomethinghere på barnet repeater knappen Select og deretter ta barnet raden og forsøke å injisere det inn i overordnede kontroller? Hvordan ville det bli oppnådd?

Jeg har prøvd alt jeg kan tenke på å gjøre dette arbeidet, og jeg har gjort utallige søk i Google og SO og andre steder for å se om noen andre har løst dette problemet. Jeg er omtrent en middels nivå koder og denne har meg stabbet. Hvordan får jeg valgt resultat rad fra barnet repeater inn i moder rad?

Takk for hjelpen!

Publisert på 03/12/2019 klokken 00:00
kilden bruker
På andre språk...                            


1 svar

Er det en måte å velge en rad fra et barn repeater og sette det inn i en overordnet repeater rad / felt i ASP.NET C #?

stemmer
0

Ok, så jeg har denne utfordringen, og jeg er fortsatt læring hvordan ting fungerer i ASP C #. Jeg har en overordnet oppdatering panel og innsiden som er en overordnet repeater. Innsiden som er et barn oppdatering panel (ikke sikker på hvor nødvendig det er) og et barn repeater. Barne repeater er for søkeresultatene. Når brukeren klikker på tekstboksen for oppføring av den overordnede repeater, en Ajax pop up oppstår som tillater dem å søke etter den personen de trenger i vår LDAP AD system i barnets Update og når de skriver inn et etternavn, fornavn (eller begge) eller en e-post og trykk "Søk", koden bak gjør det arbeid, finner resultatene, fylles repeater og får databound. Jeg har alt dette skjer i den overordnede OnItemCommand og det fungerer. Her er min utfordring - hvordan i all verden å jeg ta barnet rad velges via knappen onclick og sette inn data i de overordnede rad elementer?

Her er min aspx kode delen, jeg beklager formatering:

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

Og .CS koden bak:

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

Bør jeg ha en onclick = "dosomethinghere" på barnet repeater knappen "Select" og deretter ta barnet raden og forsøke å injisere det inn i overordnede kontroller? Hvordan ville det bli oppnådd?

Jeg har prøvd alt jeg kan tenke på å gjøre dette arbeidet, og jeg har gjort utallige søk i Google og SO og andre steder for å se om noen andre har løst dette problemet. Jeg er omtrent en middels nivå koder og denne har meg stabbet. Hvordan får jeg valgt resultat rad fra barnet repeater inn i moder rad?

Takk for hjelpen!

Svarte 03/12/2019 kl. 00:00
kilden bruker

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