zoukankan      html  css  js  c++  java
  • DropDownList 控件控制Image控件动态显示图像

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;

    public partial class _Default : System.Web.UI.Page
    {
        SqlConnection sqlcon;
        string strCon = "Data Source=(local);Database=db_04;Uid=sa;Pwd=";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                sqlcon = new SqlConnection(strCon);
                sqlcon.Open();
                string sqlstr = "select * from tb_Image";
                SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
                DataSet myds = new DataSet();
                myda.Fill(myds, "tb_Image");
                ddlPhoto.DataSource = myds.Tables["tb_Image"];
                ddlPhoto.DataTextField = "Image";
                ddlPhoto.DataBind();
                imgPhoto.ImageUrl = ddlPhoto.SelectedValue;
                sqlcon.Close();
            }
        }
        protected void ddlPhoto_SelectedIndexChanged(object sender, EventArgs e)
        {
            imgPhoto.ImageUrl = ddlPhoto.SelectedValue;
        }
    }
    SelectedIndexChanged 事件 当列表控件中的选择在向服务器的发送过程中更改时会引发这个事件 记得 DropDownList的AutoPostBack属性要为True

  • 相关阅读:
    JavaScript笔记三两个
    形式参数分别是基本类型和引用类型的调用
    if (strAreaCode.Find("体检")>=0)
    C++编写DLL文件
    error LNK2001: unresolved external symbol __imp__closesocket@4
    accept函数
    socket编程
    MFC控件使用大全
    DLL导出函数
    LINK : fatal error LNK1104: cannot open file的解决方法
  • 原文地址:https://www.cnblogs.com/ivy/p/1214819.html
Copyright © 2011-2022 走看看