English 中文(简体)
ASP.NET DropDownList /RUS 选定缺省选名单
原标题:ASP.NET DropDownList / HTML select list default selection

对我的协会来说。 互联网网页,在I背后的代码中,将各种物品/选择装入DonList,但我并没有通过指定选定的Index设定违约。 尽管我从未对德蒙德勒教士的重心或改变其价值,但I.C.D.Index的复职通知被定为0。

如果在代码后面或标记中未另作具体规定,在一名DonList博士的背后,将使用0的违约值。 如果是,是甄选名单的超文本标准的一部分,或者这只是执行伙伴关系的方法。 NET?

最佳回答

这是超文本<代码>SlectT控制的正常行为。

除非选定财产得到使用,否则将永远从第一个项目开始(指数0)。

在许多情况下,我不希望加入协会。 NET是因为我特别希望用户选择一种选择。

因此,我做的是增列一个空白项目,然后我可以证实。

i.e.

<asp:DropDownList runat="server" DataSourceID="SomeDS" AppendDataBoundItems="true"> // Notice the last property
    <asp:ListItem Text="Please select an option" Value="" />
</asp:DropDownList>

这样,我就能够建立一个有效的机构,对价值微薄的情况进行检查,迫使用户选择。

问题回答

任何人如果想从后面的法典中找到办法,可以通过使用<代码>添加额外清单项目。 插入功能并注明Index of 0, 详见 问题。 确保在您称之为<代码>Data Bind()之后这样做。

myDropDownList.DataSource = DataAccess.GetDropDownItems(); // Psuedo Code
myDropDownList.DataTextField = "Value";
myDropDownList.DataValueField = "Id";
myDropDownList.DataBind();

myDropDownList.Items.Insert(0, new ListItem("Please select", ""));




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签