Controls里找不到DropDownList

CS_9413 2010-01-10 07:23:28
private void SetReadonly(bool isRead)
{
if (!isRead)
return;
foreach (Control ct in this.divEdit.Controls)
{
if (ct is TextBox)
((TextBox)ct).ReadOnly = true;
else if(ct is DropDownList)
{
DropDownList ddl = ((DropDownList)ct);
if (ddl.CssClass != "visible")
ddl.Visible = false;
}
}
}

为什么没有DropDownList ?????
...全文
191 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
CS_9413 2010-01-11
  • 打赏
  • 举报
回复
看来跟我的vs有关,在公司是可以的
YnSky 2010-01-10
  • 打赏
  • 举报
回复
呵呵。
baiduu 2010-01-10
  • 打赏
  • 举报
回复
mark
lijing3333 2010-01-10
  • 打赏
  • 举报
回复

<form id="form1" runat="server">
<div style="height: 290px" id="aa" runat="server">

  <table class="style1">
<tr>
<td>
 </td>
<td>
 </td>
</tr>
<tr>
<td>
 </td>
<td>
 </td>
</tr>
<tr>
<td>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</td>
<td>
 </td>
</tr>
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td>
 </td>
</tr>
<tr>
<td>
 </td>
<td>
 </td>
</tr>
<tr>
<td>
 </td>
<td>
 </td>
</tr>
<tr>
<td>
 </td>
<td>
 </td>
</tr>
<tr>
<td>
 </td>
<td>
 </td>
</tr>
<tr>
<td>
 </td>
<td>
 </td>
</tr>
<tr>
<td>
 </td>
<td>
 </td>
</tr>
</table>
</div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</form>



protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < aa.Controls.Count; i++)
{
if(aa.Controls[i].ID == "DropDownList1")
{
DropDownList drop = (DropDownList)aa.Controls[i];
drop.Items.Add("123");
}
}
}


可以找到.....
CS_9413 2010-01-10
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 mngzilin 的回复:]
if (ddl.CssClass != "visible")
    ddl.Visible = false;

这几句费解,是不是下面的

if (ddl.Visible=true)
  ddl.Visible = false;


[/Quote]

跟你说的没关系,样式名只是为了区分是否在任何情况下都不隐藏该下拉框,你说的地方代码根本就进不去,因为this.divEdit.Controls里没有包含DropDownList,问题就出在此,没什么this.divEdit.Controls里不包含DropDownList,而TextBox却有
lijing3333 2010-01-10
  • 打赏
  • 举报
回复
我开VS试下
CS_9413 2010-01-10
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 lijing3333 的回复:]
我看跟你的表格有关系。。 既然用div了 干嘛里面还要丢个表格进去呢!!
[/Quote]

莫非你的table从不放在div里
lijing3333 2010-01-10
  • 打赏
  • 举报
回复
我看跟你的表格有关系。。 既然用div了 干嘛里面还要丢个表格进去呢!!
mngzilin 2010-01-10
  • 打赏
  • 举报
回复
if (ddl.CssClass != "visible")
ddl.Visible = false;

这几句费解,是不是下面的

if (ddl.Visible=true)
ddl.Visible = false;

CS_9413 2010-01-10
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 sp1234 的回复:]
哪里有 (ddl.CssClass != "visible")  ?

[/Quote]
跟 (ddl.CssClass != "visible") 没关系,唉,明天去公司看看行不行,不知道会不会跟我的vs有关系,代码是没问题的
wuyq11 2010-01-10
  • 打赏
  • 举报
回复
if(ddl!=null)
{
ddl.Visible =ddl.CssClass != "visible"?false:true;


}
  • 打赏
  • 举报
回复
哪里有 (ddl.CssClass != "visible") ?
CS_9413 2010-01-10
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 mngzilin 的回复:]
前台代码贴上来
[/Quote]
<div id="divEdit" runat="server">
<table class="info" cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
<th>
姓名
</th>
<td>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</td>
<th>
性别
</th>
<td>
<asp:TextBox ID="txtSex" runat="server" ctl="ddlSex"></asp:TextBox>
<asp:DropDownList ID="ddlSex" runat="server" ctl="txtSex">
<asp:ListItem Value="0">男</asp:ListItem>
<asp:ListItem Value="1">女</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<th>
电话
</th>
<td>
<asp:TextBox ID="txtOtherLink" runat="server"></asp:TextBox>
</td>
<th>
入职日期
</th>
<td>
<asp:TextBox ID="txtIndate" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<th>
手机
</th>
<td>
<asp:TextBox ID="txtMobile" runat="server"></asp:TextBox>
</td>
<th>
出身日期
</th>
<td>
<asp:TextBox ID="txtBirthday" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<th>
电子邮箱
</th>
<td>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
</td>
<th>
住址
</th>
<td>
<asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<th>
身份证号码
</th>
<td>
<asp:TextBox ID="txtCradID" runat="server"></asp:TextBox>
</td>
<th>
状态
</th>
<td>
<asp:TextBox ID="txtStatus" runat="server" ctl="ddlStatus"></asp:TextBox>
<asp:DropDownList ID="ddlStatus" runat="server" ctl="txtStatus">
<asp:ListItem Value="0">在职</asp:ListItem>
<asp:ListItem Value="1">退休</asp:ListItem>
<asp:ListItem Value="2">离职</asp:ListItem>
<asp:ListItem Value="3">辞退</asp:ListItem>
<asp:ListItem Value="4">其他</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<th>
家庭住址
</th>
<td colspan="3">
<asp:TextBox ID="txtCradAddress" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<th>
其他信息
</th>
<td colspan="3">
<asp:TextBox ID="txtOtherInfo" runat="server" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<th>
建档人
</th>
<td>
</td>
<th>
建档日期
</th>
<td>
</td>
</tr>
<tr>
<th>
修档人
</th>
<td>
</td>
<th>
修档日期
</th>
<td>
</td>
</tr>
</table>
</div>
  • 打赏
  • 举报
回复
用语言描述一下好吗,divEdit.Controls 在你看来是什么意思呢?
mngzilin 2010-01-10
  • 打赏
  • 举报
回复
前台代码贴上来
abeniaj0427 2010-01-10
  • 打赏
  • 举报
回复
<div id="divEdit" runat="server">
<asp:DropDownList id="ColorList"
AutoPostBack="True"
OnSelectedIndexChanged="Selection_Change"
runat="server">

<asp:ListItem Selected="True" Value="White"> White </asp:ListItem>
<asp:ListItem Value="Silver"> Silver </asp:ListItem>
<asp:ListItem Value="DarkGray"> Dark Gray </asp:ListItem>
<asp:ListItem Value="Khaki"> Khaki </asp:ListItem>
<asp:ListItem Value="DarkKhaki"> Dark Khaki </asp:ListItem>

</asp:DropDownList>
</div>
可以找到
CS_9413 2010-01-10
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wuyq11 的回复:]
DropDownList ddl = ct as DropDownList;
TextBox是否能找到
页面添加到是否是DropDownList
[/Quote]
TextBox能找到
wuyq11 2010-01-10
  • 打赏
  • 举报
回复
DropDownList ddl = ct as DropDownList;
TextBox是否能找到
页面添加到是否是DropDownList
abeniaj0427 2010-01-10
  • 打赏
  • 举报
回复
在我这边是可以找到的。你把前台页面贴出来看看
CS_9413 2010-01-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 at_gaj 的回复:]
它是HTML控件还是SERVER控件?
[/Quote]

DropDownList当然是SERVER
加载更多回复(1)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧