0

ASP.NET アプリケーションがあり、ListView コントロールを使用しています。この ListView をバインドするには、DataTable オブジェクトを使用し、ListView には次の構造があります。

<asp:listView ...>
 <LayoutTemplate>
 <ItemTemplate>
 <AlternatingItemTemplate>

ItemTemplate と AlternatingItemTemplate で DropDownList を使用します。これは場所を表示する必要があります。これには、XmlDataSource コントロールで XML ファイルを使用します。しかし、コード内の XML ファイルを更新し、アクティブ ユーザー用の特別な要素しかない要素を削除する必要があるという問題があります。これは、ListView の DropDoanList コントロールが XML ファイルのすべての要素を表示しないことを意味します。

したがって、最初に DataTable オブジェクトを作成できると思います。次に、これを ListView にバインドし、この後、ListView でコントロールを見つけます。しかし、私は毎回「null」を取得します:( .このオブジェクトが見つかりません。

ここに私のコードがあります:

ListView.DataSource = tb;
                ListView.DataBind();

                XDocument x = XDocument.Load(Server.MapPath(@"~\App_Data\location.xml"));

                string ActiveUser = GetUsername();

                ArrayList ListOfNPSGroups = GetGroupsInOUByValue();

                ArrayList ActiveUserList = GetGroupmemberList(ListOfNPSGroups);

                x.Root.Descendants()
                                   .Where(d => !ActiveUserList.Contains((string)d.Attribute("group")))
                                   .ToList()
                                   .ForEach(s => s.Remove());

                var data = (from item in x.Elements("plants").Elements("plant")
                            select new { display = item.Attribute("display").Value, id = item.Attribute("id").Value }).ToList();

                DropDownList ListViewDropDownListLocation = (DropDownList)ListView.FindControl("ListViewDropDownListLocation");  // here I get NULL

                ListViewDropDownListLocation.DataSource = data;
                ListViewDropDownListLocation.DataTextField = "display";
                ListViewDropDownListLocation.DataValueField = "id";
                ListViewDropDownListLocation.DataBind();

ここに私の ASPX を示します。

<ItemTemplate>
                    <tr id="Tr1" class="TableClassO" runat="server" onmouseover="this.style.backgroundColor='#87CEFA'"
                    onmouseout="this.style.backgroundColor='#ffffff'" titel="Auswahl">

                        <td>
                            <asp:DropDownList ID="drpDeviceClass"  runat="server" SelectedValue='<%# Eval("DeviceClass") %>' DataTextField="display" DataValueField="id" DataSourceID="xmlDeviceClass" Width="90%" >
                            </asp:DropDownList>
                            <asp:XmlDataSource ID="xmlDeviceClass" runat="server" DataFile="~/App_Data/devices.xml" ></asp:XmlDataSource>
                        </td>

                        <td >
                            <asp:TextBox ID="txtMacAdress" runat="server" Text='<%# Eval("MAC") %>' Width="90%"></asp:TextBox>
                        </td>

                        <td >
                            <asp:DropDownList ID="ListViewDropDownListLocation" SelectedValue='<%# Eval("Location") %>' runat="server" Width="90%"
                             DataTextField="display" DataValueField="id" DataSourceID="ListViewXMLRessourceLocation"></asp:DropDownList>
                             <asp:XmlDataSource ID="ListViewXMLRessourceLocation" runat="server" DataFile="~/App_Data/location.xml" ></asp:XmlDataSource>
                        </td>

                        <td >
                            <asp:TextBox ID="txtFirstname" runat="server" Text='<%# Eval("Vorname") %>' Width="90%"></asp:TextBox>
                        </td>

                        <td >
                            <asp:TextBox ID="txtLastname" runat="server" Text='<%# Eval("Nachname") %>' Width="90%"></asp:TextBox>
                        </td>

                        <td >
                            <asp:TextBox ID="txtDescription" runat="server" Text='<%# Eval("Beschreibung") %>' Width="90%"></asp:TextBox>
                        </td>
                        <td>
                          <asp:ImageButton ID="imgSaveOnly" ImageAlign="Middle" runat="server" CommandName="Save" CommandArgument='<%# Container.DataItemIndex %>'  Width="15" Height="15" ImageUrl="~/App_Themes/Images/Save-icon.png" ToolTip="Eintrag ins Active Directory übernehmen" />
                        </td>
                        <td>
                            <asp:ImageButton ID="imgPowerShell" ImageAlign="Middle" runat="server" CommandName="Powershell" CommandArgument='<%# Container.DataItemIndex %>'  Width="15" Height="15" ImageUrl="~/App_Themes/Images/ps.png" ToolTip="PowerShell Befehl Anzeigen" />
                        </td>

                        <td>
                            <asp:ImageButton ID="imgDelete" runat="server" ImageAlign="Middle" CommandName="Delete" CommandArgument='<%# Container.DataItemIndex %>'  Width="15" Height="15" ImageUrl="~/App_Themes/Images/delete.png" ToolTip="Eintrag Löschen" />
                        </td>

                    </tr>
                </ItemTemplate>

この問題を解決できますか :/ ?

4

1 に答える 1