C# 通过DropDownlist\u selectedindexchanged事件访问标签,两者都在列表视图中

C# 通过DropDownlist\u selectedindexchanged事件访问标签,两者都在列表视图中,c#,listview,drop-down-menu,C#,Listview,Drop Down Menu,是否可以通过DropDownList\u SelectedIndexChanged事件访问议会标签 <tr id="Tr10" runat="server"> <td width="110px"> دسته :&nbsp; </td> <td> <asp:DropDownList ID="Catego

是否可以通过DropDownList\u SelectedIndexChanged事件访问议会标签

<tr id="Tr10" runat="server">
            <td width="110px">
                دسته :&nbsp;
            </td>
            <td>
                <asp:DropDownList ID="CategoryDropDownList" runat="server" Font-Names="tahoma" Font-Size="13px" onselectedindexchanged="CategoryDropDownList_SelectedIndexChanged" AutoPostBack="true" SelectedValue='<%# Eval("Category") %>'>
                    <asp:ListItem Text="عمومی" Value="عمومی"></asp:ListItem>
                    <asp:ListItem Text="پزشکی" Value="پزشکی"></asp:ListItem>
                    <asp:ListItem Text="مددکاری" Value="مددکاری"></asp:ListItem>
                    <asp:ListItem Text="روان شناسی" Value="روان شناسی"></asp:ListItem>
                </asp:DropDownList>
                <asp:Label ID="CouncilIdLabel" runat="server" Text='<%# Eval("CouncilId") %>' Visible="false" />
            </td>
        </tr>

دسته : 
它位于listview项目模板中


请帮帮我,我需要尽快解决这个问题是的,这是可能的。您必须在listview中找到该控件。使用:

Label coucilIdLabel = (Label)MyListView.FindControl("CouncilIdLabel");

是的,这是可能的。您必须在listview中找到该控件。使用:

Label coucilIdLabel = (Label)MyListView.FindControl("CouncilIdLabel");

您需要对ListViewDataItem本身使用FindControl。i、 e

Label coucilIdLabel = (Label)SomeListView.Items[SomeItemIndex].FindControl("CouncilIdLabel");
或-在selectedIndex changed事件中,这应该可以工作:


您需要对ListViewDataItem本身使用FindControl。i、 e

Label coucilIdLabel = (Label)SomeListView.Items[SomeItemIndex].FindControl("CouncilIdLabel");
或-在selectedIndex changed事件中,这应该可以工作:


那么如何访问文本属性?!我试过了,得到了这个错误“对象引用未设置为对象的实例”。那么如何访问文本属性?!我尝试了这个方法,得到了一个错误“对象引用未设置为对象的实例”。发送方没有“父”成员,所以我使用了这个DropDownList categorhydropdown=(发送方作为DropDownList);var item=categorhydropdown.Parent作为ListViewDataItem;Label coucilIdLabel=(Label)item.FindControl(“CouncilIdLabel”);它给了我这样的信息:对象引用未设置为对象的实例。DropDownList CategorHydropdown=(发送方为DropDownList);控制项=CategorHydropdown.Parent.FindControl(“CouncilIdLabel”);Label coucilIdLabel2=(Label)item.FindControl(“CouncilIdLabel”);我认为这已经解决了问题:-)发送方没有“父”成员,所以我使用了这个DropDownList categorhydropdown=(发送方作为DropDownList);var item=categorhydropdown.Parent作为ListViewDataItem;Label coucilIdLabel=(Label)item.FindControl(“CouncilIdLabel”);它给了我这样的信息:对象引用未设置为对象的实例。DropDownList CategorHydropdown=(发送方为DropDownList);控制项=CategorHydropdown.Parent.FindControl(“CouncilIdLabel”);Label coucilIdLabel2=(Label)item.FindControl(“CouncilIdLabel”);我认为这解决了问题:-)