网站首页 > 网络编程教程 > Ajax教程 > Ajax实现DataGrid/DataList动态ToolTip

Ajax实现DataGrid/DataList动态ToolTip

  • 作者:互联网
  • 时间:2009-07-06 16:29:58

1.建立一aspx页面,html代码2.cs代码


using Sy***m.Data.SqlClient;
using Sy***m.IO;
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Pa***IsPostBack)
        {
            BindData();
           
        }
        if (ID != "")
        {
            GetDescriptionByID(ID);
        }
       
    }

    property#region property
    private string ID
    {
        get
        {
            if (Request["ID"] != null && Request["ID"].ToString() != "")
            {
                return Request["ID"];
            }
            else
            {
                return "";
            }
        }
    }
    #endregion

    GetDescriptionByID#region GetDescriptionByID
    private void GetDescriptionByID(string ID)
    {
        string connStr = Co***gurationSettings.AppSettings["ConnectionString"];
        SqlConnection conn = new SqlConnection(connStr);
        string sql = "select * from testimage where userid='" + ID + "'";
        SqlCommand cmd = new SqlCommand(sql, conn);
        co***Open();
        SqlDataReader dr = cm***xecuteReader();

        string s = @"";
        if(dr.Read())
        {
            s += "";
            s += "";
            s += "";
            s += "";
            s += "";
            s += "";
            s += "";
            s += "";
        }
        s += "
名称:" + dr["UserName"] + "
描述:" + dr["Description"] + "
";
        dr.Close();
        co***Close();
        th***Response.Write(s);
        th***Response.End();
    }
    #endregion

    save image#region save image
    protected void Button2_Click(object sender, EventArgs e)
    {
        Stream ImageStream;
        string Path = Fi***pload1.PostedFile.FileName;// 文件名称
        int Size = Fi***pload1.PostedFile.ContentLength; // 文件大小
        string Type = Fi***pload1.PostedFile.ContentType; // 文件类型
        ImageStream = Fi***pload1.PostedFile.InputStream;
        byte[] Content = new byte[Size];
        int Status = Im***Stream.Read(Content, 0, Size);

        SqlConnection conn = new SqlConnection(Co***gurationSettings.AppSettings["ConnectionString"]);
        SqlCommand comm = new SqlCommand("insert into testimage (UserName,Image,Path,Type,Description) values(@UserName,@Image,@Path,@Type,@Description)", conn);

        co***CommandType = Co***ndType.Text;
        co***Parameters.Add("@UserName", Sq***Type.VarChar, 255).Value = tx***erName.Text;
        co***Parameters.Add("@Image", Sq***Type.Image).Value = Content;
        co***Parameters.Add("@Path", Sq***Type.VarChar, 255).Value = Path;
        co***Parameters.Add("@Type", Sq***Type.VarChar, 255).Value = Type;
        co***Parameters.Add("@Description", Sq***Type.VarChar, 2000).Value = th***TextBox1.Text;

        co***Open();
        co***ExecuteNonQuery();
        co***Close();
    }
    #endregion

    BindData#region BindData
    private void BindData()
    {
        string sql = "select * from testimage";
        DataSet ds = GetDataSet(sql);
        th***DataList1.DataSource = ds;
        th***DataList1.DataBind();
    }
    #endregion

    GetDataSet#region GetDataSet
    private DataSet GetDataSet(string sql)
    {
        string constring = System.Configuration.Co***gurationSettings.AppSettings["ConnectionString"];
        SqlDataAdapter sda = new SqlDataAdapter(sql, constring);
        DataSet ds = new DataSet();
        sda.Fill(ds);
        return ds;
    }
    #endregion3.数据库脚本
if exists (select * from db***ysobjects where id = object_id(N'[dbo].[TestImage]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[TestImage]
GO

CREATE TABLE [dbo].[TestImage] (
    [UserID] [int] IDENTITY (1, 1) NOT NULL ,
    [UserName] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL ,
    [Image] [image] NULL ,
    [Path] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL ,
    [Type] [nvarchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [Description] [nvarchar] (2000) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO


 
  WebForm1
 
 
 
 


 

     
 

   
名称:            runat="server">

      描述:

       
               BorderColor="black"
           CellPadding="1"
           CellSpacing="4" HorizontalAlign="Center"
           RepeatColumns="4"
           RepeatLayout="Table"
           runat="server" ShowFooter="true" ShowHeader="true"
           width="100%">
        
            <%# Da***inder.Eval(Co***iner.DataItem, "UserName")%>

            Da***inder.Eval(Co***iner.DataItem, "UserID")%>);" onmouseout="kill();" src='<%# Da***inder.Eval(Co***iner.DataItem, "Path") %>' height='150'/>