asp.net技术小结(第一条)
(1)cs:
public string SayHello()//返回类型是string {
return "大家好"+DateTime.Now.ToString();
}
protected void ShowType()//返回类型是void
{
Response.Write(this.GetType() + "<br/>");
Response.Write(this.GetType().Assembly.Location + "<br/>");
Response.Write(this.GetType().BaseType + "<br/>");
Response.Write(this.GetType().BaseType.Assembly.Location + "<br/>");
}
?
前台调用方法:?
? <%=SayHello() %>
<% ShowType(); %>
(2)在前台html中写c#代码??
<%
for(int i=0;i<10;i++)
{
Response.Write(i+"</br>");
}
%>
(3)button弹出确认对话框
OnClientClick="return confirm(‘确定提交吗?‘)"
(4)dropdownlist绑定方法
前台:
<asp:DropDownList ID="ddlProvince" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlProvince_SelectedIndexChanged">
<asp:ListItem Value="hb">河北</asp:ListItem>
<asp:ListItem Value="sd">山东</asp:ListItem>
<asp:ListItem Value="hn">河南</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlCity" runat="server">
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=localhost;Initial Catalog=wang;Persist Security Info=True;User ID=sa;Password=24680";
conn.Open();
string cmd = "select * from test";
//建立数据适配器、Table表 然后填充
SqlDataAdapter da = new SqlDataAdapter(cmd, conn);
DataTable dt = new DataTable();
da.Fill(dt);
ddl.DataSource = dt;
// DataSet ds = new DataSet();
// da.Fill(ds);
// ddl.DataSource = ds.Tables[0];
ddl.DataTextField = "UserName";
ddl.DataValueField = "UserAge";
ddl.DataBind();
conn.Close();
ddl.Dispose();
当事件改变时:
if (ddlProvince.SelectedValue == "hb")
{
ddlCity.Items.Clear();
ddlCity.Items.Add("石家庄");
ddlCity.Items.Add("唐山");
ddlCity.Items.Add("保定");
}
?
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。