仍然没有得到解决方案..请任何人帮助我吗?

时间:2011-05-13 10:21:05

标签: asp.net c#-4.0

我hava ddl和textbox ..如果我的文本框值已经存在于ddl中,则意味着我应该在ddl中显示已存在的消息..

我试过比较calidator ..但不工作,,,

<asp:DropDownList ID="ddlmothertongue" AppendDataBoundItems="True" runat="server"
          CssClass="dd_NoWidth" Width="136px" 
          OnSelectedIndexChanged="ddlmothertongue_SelectedIndexChanged"
          AutoPostBack="True" DataSourceID="SqlDataSource1" 
          DataTextField="mothertongue"
          DataValueField="mothertongue">
  <asp:ListItem Value="0" Text="-Select-"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
   ConnectionString="<%$ ConnectionStrings:NewMatrimonyConnectionString %>"
   SelectCommand="SELECT distinct  [mothertongue] FROM [tbl_mothertongue]union all select 'Others'"></asp:SqlDataSource>
   <asp:TextBox ID="txtmothertongue" runat="server" 
       Visible="False" AutoPostBack="True"></asp:TextBox>
<asp:TextBox ID="txtmothertongue" runat="server" Visible="False"
       AutoPostBack="True"></asp:TextBox>

1 个答案:

答案 0 :(得分:4)

由于您实际上并没有提供太多数据,我可以为您提供我所拥有数据的解决方案。

 if (ddl.items.Contains(value)) 
 {
       //show message it already contains item
 }