asp.net DropDownList 项目动态添加
Dotjum 這邊要介紹也是一個很經典的 ASP.NET 老問題,就是怎麼要在下拉選項中,一開始 DataBind() 資料繫結時,
就先出現預設選項 請選擇,其實做這個非常簡單,在很久很久以前 Dotjum 一開始不太懂,就用了奇怪的方法來達成,
因位DataBind後,你先輸入的靜態選項 清單中的項目 會消失,所以很久以前 Dotjum 就弄了一個在資料 DataSet 叫回來之後,
再弄一筆 請選擇的資料上去 不然就是 等 DropDownList DataBind 後,在動態的加一筆資料進去。
Dotjum 還曾經看過,有人為了這個弄了一個 Control 出來,請注意上述這幾種方法,千萬不要在使用了。
因為ASP.NET已經有更簡單的方式了,話不多說,請看說明
Step1. 在 DropDownList 請將 AppendDataBoundItems 設定為 true
Step2. 設定一個項目為預設選項 ex:請選擇 0
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True"
DataMember="DefaultView" DataSourceID="SqlDataSource3" DataTextField="鄉鎮區市名稱"
DataValueField="縣市代號" Width="186px">
<asp:ListItem Value="0">請選擇</asp:ListItem>
</asp:DropDownList>
Step3.再加上一個 RequiredFieldValidator 驗證該 DropDownList 必且設定若初始值 0 (這邊是你可以依照狀況來設定的)
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DropDownList1"
ErrorMessage="請選擇項目" InitialValue="0"></asp:Require
相关文档:
一直以来将数据库中的时间绑定到gridview中后,显示的后面总是会多出一串00:00:00,
原来是绑定的时候没有格式化字符串,只要在绑定时加入如下格式就对了。
<asp:BoundField DataField="FieldName" HeaderText="时间" DataFormatString="{0:d}" HtmlEncode="false"> ......
原地址:
http://msdn.microsoft.com/en-us/library/aa480476.aspx
IIS Authentication
ASP.NET authentication is a two-step process. First, Internet Information Services (IIS) authenticates the user and creates a Windows token to represent the user. IIS determines the authentication mode that it shoul ......
页面文件类似:
<% using (Ajax.BeginForm("AjaxUpdate", 123, new AjaxOptions {
Confirm = "confirm str", LoadingElementId = "idLoading", UpdateTargetId
= "textEntered", OnSuccess = "validateForm" },new{id="idMyForm"}))
&nbs ......
在开发ISO文件管理系统的时候,曾经遇到过要将ASPX直接输出到EXCEL的需求,现将经验所得与大家分享。 其实,利用ASP.NET输出指定内容的WORD、EXCEL、TXT、HTM等类型的文档很容易的。主要分为三步来完成。
一、定义文档类型、字符编码
Response.Clear();
Response.Buffer= true;
Response ......
Asp.net为我们提供了六个验证验证控件及其要起作用必须设置的属性:
(1) RequiredFieldValidator:该控件要求其绑定的输入控件一定要有输入值,不能为空;
属性:ControlToValidate:验证控件要验证的输入控件ID(绑定的输入空间ID)
Text:输入控件输入的内容不 ......