读书人

GridView里面的图片,文字,效果很不好处

发布时间: 2012-06-02 14:16:14 作者: rapoo

GridView里面的图片,文字,效果很不好处理啊.
GridView里面的一些Field, 想加上一些效果,好像很麻烦啊.
比如,单独一张图片, 进行一些效果处理,是很容易的. 不管是点击放大, 鼠标放大镜, 都很容易实现.
但是Field里面就不同了, 感觉麻烦, 找不到相关的资料.

图片, 怎样点击放大?


HTML code
    <asp:GridView ID="GridView1" runat="server"     DataKeyNames="PhotoID"     AllowPaging="True"     AutoGenerateColumns="False"     OnRowDeleting="GridView1_RowDeleting"     OnRowDataBound="GridView1_RowDataBound"     OnPageIndexChanging="GridView1_PageIndexChanging">            <Columns><asp:ImageField DataImageUrlField="PhotoPath" HeaderText="缩略图">            </Columns>     </asp:GridView>



C# code
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)        {            if (e.Row.RowType == DataControlRowType.DataRow)            {                Image x = e.Row.Cells[2].Controls[0] as Image;                SetimageSize(x, 20);                //高亮显示指定行                e.Row.Attributes.Add("onMouseOver", "Color=this.style.backgroundColor;this.style.backgroundColor='#336699';C=this.style.Color;this.style.Color='#ff0000'");                e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=Color;");                //e.Row.Attributes.Add("onMouseOver", "C=this.style.Color;this.style.Color='#336699'");                //e.Row.Attributes.Add("onMouseOver", "Color=this.style.fontColor;this.style.fontColor='#000000'");                //删除指定行数据时,弹出询问对话框                ((LinkButton)(e.Row.Cells[3].Controls[0])).Attributes.Add("onclick", "return confirm('是否删除当前行数据!')");            }        }        public void SetimageSize(System.Web.UI.WebControls.Image Image, int MaxW)        {            SqlDataAdapter da = new SqlDataAdapter("select * from Photo where PhotoUser ='" + Session["UserName"].ToString() + "' order by PhotoID desc", cn);            DataSet ds = new DataSet();            da.Fill(ds);            string photoPath = ds.Tables[0].Rows[0][3].ToString();               //System.IO.File.Exists            if (!File.Exists(Server.MapPath(photoPath)))            {                        }            else            {                System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath(photoPath));                if (img.Width > MaxW)                {                    int Nw = Convert.ToInt32((float)img.Width - ((float)img.Width - (float)150));                    int Nh = Convert.ToInt32((float)img.Height / ((float)img.Width / (float)Nw));                    Image.Width = Nw;                }            }            //System.Drawing.Image img = System.Drawing.Image.FromFile(Page.Server.MapPath(Image.Src.Replace("..", "")));        }


[解决办法]
用模板吧。

[解决办法]
把Field用Control替换掉
Control的样式,随你怎么写都行!

读书人网 >asp.net

热点推荐