Ajax实现DataGrid/DataList动态ToolTip
1.建立一aspx页面,html代码2.cs代码
using System.Data.SqlClient;
using System.IO;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.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 = ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection conn = new SqlConnection(connStr);
string sql = "select * from testimage where userid='" + ID + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
string s = @"<table cellspacing='0' cellpadding='4'>";
if(dr.Read())
{
s += "<tr>";
s += "<td>名称:</td>";
s += "<td>" + dr["UserName"] + "</td>";
s += "</tr>";
s += "<tr>";
s += "<td scope='col'>描述:</td>";
s += "<td>" + dr["Description"] + "</td>";
s += "</tr>";
}
s += "</table>";
dr.Close();
conn.Close();
this.Response.Write(s);
this.Response.End();
}
#endregion
save image#region save image
protected void Button2_Click(object sender, EventArgs e)
{
Stream ImageStream;
string Path = FileUpload1.PostedFile.FileName;// 文件名称
int Size = FileUpload1.PostedFile.ContentLength; // 文件大小