在asp.net中静态下拉项 [英] Static Dropdown items in asp.net

查看:87
本文介绍了在asp.net中静态下拉项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了很多,但没有真的帮助了我。我是初学者,请承担任何无知

I searched a lot but nothing realy helped me. I am beginner and please bear any ignorance

我在我的aspx页面的下拉列表。下拉的来源是从sqlsource,我有它在隐藏文件我的code。我想一个静态项目添加到下拉菜单的顶部,我能够与以下行添加

I have a dropdown list in my aspx page. The source of the dropdown is from a sqlsource that I have it in my code behind file. I wanted to add a static item to the top of the dropdown and I was able to add it with below line

reportparameter.Items.Insert(0, "-------SELECT----------");

我怎么设置必填字段校验器对这个下拉从code后面的第一个值。我尝试不同的事情,我得到一个转换错误,每当我提交页面。

how do I set a required field validator on this dropdown with the first value from the code behind. I tried different things and I get an conversion error whenever i submit the page.

推荐答案

我认为 reportparameter 的DropDownList

您可以使用<$c$c>AppendDataBoundItems属性来告诉ASP.NET的数据源应附加静态项目(S)。

You can use the AppendDataBoundItems property to tell ASP.NET that the DataSource should be appended to the "static" item(s).

您可以使用的RequiredFieldValidator 的<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.requiredfieldvalidator.initialvalue.aspx\"><$c$c>InitalValue属性来告诉它,这算作的不selcted 的。在你CASSE你需要将其设置为0。

You can use the RequiredFieldValidator's InitalValue property to tell it that this counts as not selcted. In your casse you need to set it to 0.

<asp:DropDownList id="reportparameter"
                AppendDataBoundItems="True"
                runat="server">
              <asp:ListItem Selected="True" Value="0">-------SELECT----------</asp:ListItem>
           </asp:DropDownList>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" 
       InitialValue="0" 
       ControlToValidate="reportparameter"
       ErrorMessage="Required field!"
       runat="server"/>

这篇关于在asp.net中静态下拉项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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