如何在列表视图之外的下拉列表中更改选定索引时标签和文本框不可见 [英] How do I make labels and textboxes invisible on selected index changed of dropdown which is outside the listview

查看:72
本文介绍了如何在列表视图之外的下拉列表中更改选定索引时标签和文本框不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我有下拉列表和ListView Control.On所选索引更改了下拉列表

我想做一些listview的标签和文本框不可见。



下拉列表不在列表视图中,当我在其上使用FindControl时它会给我null。





谢谢



Hello,

I have dropdownlist and a ListView Control.On the selected Index Changed of the dropdown
I want to make some labels and textboxes of listview invisible.

The dropdown is not in the listview and when I am using the FindControl on it it is giving me null.


Thanks

 <asp:DropDownList ID="ddlselect" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlselect_SelectedIndexChanged">
     <asp:ListItem Value="0" Text="A"></asp:ListItem>
     <asp:ListItem Value="1" Text="B"></asp:ListItem>
    </asp:DropDownList>

<asp:ListView ID="ListView1" runat="server"  DataSourceID="ObjectDataSource1">
protected void ddlselect_SelectedIndexChanged(object sender, EventArgs e)
    {
TextBox txt = ListView1.FindControl("VALUETextBox0") as TextBox;
}

推荐答案

遗憾的是,您没有提供更详细的listview标记。但是,根据您的代码,我可以假设此问题与您尝试访问VALUETextBox0的位置无关。问题是你不能简单地通过listview的ItemTemplate中的id控件进行访问。您可以尝试diefine onDatabound事件处理程序。类似于:

It's a shame that you haven't provided more detailed markup of your listview. However from your code I can assume that this issue is not connected with place from wich you are trying to access your "VALUETextBox0". The thing is that you cannot simply access by id controls from ItemTemplate of your listview. You can try to diefine onDatabound event handler. Something like:
<asp:listview id="ListView1" runat="server" datasourceid="ObjectDataSource1" onitemdatabound="lv_Databound" xmlns:asp="#unknown"></asp:listview>

并管理来自事件处理程序的控件的可见性。类似于

and manage visibility of your controls from eventhandler. Something similar to

 protected void lv_Databound(object sender, ListViewItemEventArgs e)
    {
         if (e.Item.ItemType == ListViewItemType.DataItem)
        {
           var t = e.Item.Findcontrol(""VALUETextBox0"") as Textbox;
// manage t visibility here
        }
    }



然后您只需在ddlselect_SelectedIndexChanged中设置一些标志,您可以将其存储在View状态并用于确定控件的可见性,而不仅仅是触发listView Databound事件


Then you just simply set some flag in ddlselect_SelectedIndexChanged that you may store in View state and use to determine visibility of your controls and than just fire listView Databound event


这篇关于如何在列表视图之外的下拉列表中更改选定索引时标签和文本框不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆