<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="http://feeds.qzone.qq.com/rss.xsl" version="1.0"?>
<rss version="2.0" xmlns:qz="http://qzone.qq.com">
<channel>
<title><![CDATA[【廆●仼】]]></title>
<description><![CDATA[IT古人]]></description>
<link>http://344791576.qzone.qq.com</link>
<lastBuildDate>Thu, 26 Nov 2009 03:33:06 GMT</lastBuildDate>
<generator>Qzone</generator>
<language>zh-cn</language>
<copyright>Copyright (C), 2005-2008, Tencent Tech. Co., Ltd.</copyright>
<pubDate>Wed, 29 Apr 2009 08:31:01 GMT</pubDate>

<item>
<title><![CDATA[ASP.NET2.0打通文件图片处理任督二脉【三】]]></title>
<link>http://344791576.qzone.qq.com/blog/1240993861</link>
<description><![CDATA[<br><span style="font-weight:bold"><wbr /></span><wbr /><span style="font-size:13px;line-height:1.8em;"> public string PublicImageWater <br> {<br>  get<br>  {<br>   return ImageWater;<br>  }<br>  set  //设置了水印图片的话说明是要水印图片效果的<br>  {<br>   dealtype = DealType.WaterImage;<br>   ImageWater = value;<br>  }<br> }<br> public string PublicFontString<br> {<br>  get<br>  {<br>   return FontString;<br>  }<br>  set //设置了水印文字的话说明是要水印文字效果的<br>  {<br>   dealtype = DealType.WaterFont;<br>   FontString = value;<br>  }<br> }<br> <br> public void DealImage()<br> {<br>  IsDouble();<br>  switch( dealtype )<br>  {<br>   case DealType.WaterFont: WriteFont(); break;<br>   case DealType.WaterImage: WriteImg(); break;<br>   case DealType.DoubleDo: WriteFontAndImg(); break;<br>  }<br> }<br> private void IsDouble()<br> {<br>  if(ImageWater+&quot;&quot;!=&quot;&quot; &amp;&amp; FontString+&quot;&quot;!=&quot;&quot;)<br>  {<br>            dealtype = DealType.DoubleDo;<br>  }<br> }<br> private void WriteFont()<br> {<br>  //set a working directory<br>  //string WorkingDirectory = @&quot;C:\Watermark_src\WaterPic&quot;;<br>  //define a string of text to use as the Copyright message<br>  //string Copyright = &quot;Copyright ?2002 - AP Photo/David Zalubowski&quot;;<br>  //create a image object containing the photograph to watermark<br>  Image imgPhoto = Image.FromFile(WorkingDirectory + ImageName);<br>  int phWidth = imgPhoto.Width;<br>  int phHeight = imgPhoto.Height;<br>  //create a Bitmap the Size of the original photograph<br>  Bitmap bmPhoto = new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);<br>  bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);<br>  //load the Bitmap into a Graphics object <br>  Graphics grPhoto = Graphics.FromImage(bmPhoto);<br>  //------------------------------------------------------------<br>  //Step #1 - Insert Copyright message<br>  //------------------------------------------------------------<br>  //Set the rendering quality for this Graphics object<br>  grPhoto.SmoothingMode = SmoothingMode.AntiAlias;<br>  //Draws the photo Image object at original size to the graphics object.<br>  grPhoto.DrawImage(<br>   imgPhoto,                               // Photo Image object<br>   new Rectangle(0, 0, phWidth, phHeight), // Rectangle structure<br>   0,                                      // x-coordinate of the portion of the source image to draw. <br>   0,                                      // y-coordinate of the portion of the source image to draw. <br>   phWidth,                                // Width of the portion of the source image to draw. <br>   phHeight,                               // Height of the portion of the source image to draw. <br>   GraphicsUnit.Pixel);                    // Units of measure <br>  //-------------------------------------------------------<br>  //to maximize the size of the Copyright message we will <br>  //test multiple Font sizes to determine the largest posible <br>  //font we can use for the width of the Photograph<br>  //define an array of point sizes you would like to consider as possiblities<br>  //-------------------------------------------------------<br>  int[] sizes = new int[]{16,14,12,10,8,6,4};<br>  Font crFont = null;<br>  SizeF crSize = new SizeF();<br>  //Loop through the defined sizes checking the length of the Copyright string<br>  //If its length in pixles is less then the image width choose this Font size.<br>  for (int i=0 ;i&lt;7; i++)<br>  {<br>   //set a Font object to Arial (i)pt, Bold<br>   //crFont = new Font(&quot;arial&quot;, sizes<span style="font-style:italic"><wbr />, FontStyle.Bold);<br>   crFont = new Font(&quot;arial&quot;,sizes<span style="font-style:italic"><wbr />,FontStyle.Bold);<br>   //Measure the Copyright string in this Font<br>   crSize = grPhoto.MeasureString(FontString, crFont);<br>   if((ushort)crSize.Width &lt; (ushort)phWidth)<br>    break;<br>  }<br>  //Since all photographs will have varying heights, determine a <br>  //position 5% from the bottom of the image<br>  int yPixlesFromBottom = (int)(phHeight *.05);<br>  //Now that we have a point size use the Copyrights string height <br>  //to determine a y-coordinate to draw the string of the photograph<br>  float yPosFromBottom = ((phHeight - yPixlesFromBottom)-(crSize.Height/2));<br>  //Determine its x-coordinate by calculating the center of the width of the image<br>  float xCenterOfImg = (phWidth/2);<br>  //Define the text layout by setting the text alignment to centered<br>  StringFormat StrFormat = new StringFormat();<br>  StrFormat.Alignment = StringAlignment.Center;<br>  //define a Brush which is semi trasparent black (Alpha set to 153)<br>  SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(153, 0, 0, 0));<br>  //Draw the Copyright string<br>  grPhoto.DrawString(FontString,                 //string of text<br>   crFont,                                   //font<br>   semiTransBrush2,                           //Brush<br>   new PointF(xCenterOfImg+1,yPosFromBottom+1),  //Position<br>   StrFormat);<br>  //define a Brush which is semi trasparent white (Alpha set to 153)<br>  SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(153, 255, 255, 255));<br>  //Draw the Copyright string a second time to create a shadow effect<br>  //Make sure to move this text 1 pixel to the right and down 1 pixel<br>  grPhoto.DrawString(FontString,                 //string of text<br>   crFont,                                   //font<br>   semiTransBrush,                           //Brush<br>   new PointF(xCenterOfImg,yPosFromBottom),  //Position<br>   StrFormat);    <br>  <br>  imgPhoto = bmPhoto;<br>  grPhoto.Dispose();<br>  //save new image to file system.<br>  imgPhoto.Save(WorkingDirectory + ImageName + &quot;_finally.jpg&quot;, ImageFormat.Jpeg);<br>  imgPhoto.Dispose();<br>  <br>  //Text alignment<br> }<br><br> private void WriteImg()<br> {<br>  //set a working directory<br>  //string WorkingDirectory = @&quot;C:\Watermark_src\WaterPic&quot;;<br>  //create a image object containing the photograph to watermark<br>  Image imgPhoto = Image.FromFile(WorkingDirectory + ImageName);<br>  int phWidth = imgPhoto.Width;<br>  int phHeight = imgPhoto.Height;<br>  //create a Bitmap the Size of the original photograph<br>  Bitmap bmPhoto = new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);<br>  bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);<br>  //load the Bitmap into a Graphics object <br>  Graphics grPhoto = Graphics.FromImage(bmPhoto);<br>  //create a image object containing the watermark<br>  Image imgWatermark = new Bitmap(WorkingDirectory + ImageWater);<br>  int wmWidth = imgWatermark.Width;<br>  int wmHeight = imgWatermark.Height;<br>  //Set the rendering quality for this Graphics object<br>  grPhoto.SmoothingMode = SmoothingMode.AntiAlias;<br>  //Draws the photo Image object at original size to the graphics object.<br>  grPhoto.DrawImage(<br>   imgPhoto,                               // Photo Image object<br>   new Rectangle(0, 0, phWidth, phHeight), // Rectangle structure<br>   0,                                      // x-coordinate of the portion of the source image to draw. <br>   0,                                      // y-coordinate of the portion of the source image to draw. <br>   phWidth,                                // Width of the portion of the source image to draw. <br>   phHeight,                               // Height of the portion of the source image to draw. <br>   GraphicsUnit.Pixel);                    // Units of measure <br><br>  //------------------------------------------------------------<br>  //Step #2 - Insert Watermark image<br>  //------------------------------------------------------------<br>  //Create a Bitmap based on the previously modified photograph Bitmap<br>  Bitmap bmWatermark = new Bitmap(bmPhoto);<br>  bmWatermark.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);<br>  //Load this Bitmap into a new Graphic Object<br>  Graphics grWatermark = Graphics.FromImage(bmWatermark);<br>  //To achieve a transulcent watermark we will apply (2) color <br>  //manipulations by defineing a ImageAttributes object and <br>  //seting (2) of its properties.<br>  ImageAttributes imageAttributes = new ImageAttributes();<br>  //The first step in manipulating the watermark image is to replace <br>  //the background color with one that is trasparent (Alpha=0, R=0, G=0, B=0)<br>  //to do this we will use a Colormap and use this to define a RemapTable<br>  ColorMap colorMap = new ColorMap();<br>  //My watermark was defined with a background of 100% Green this will<br>  //be the color we search for and replace with transparency<br>  colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);<br>  colorMap.NewColor = Color.FromArgb(0, 0, 0, 0); <br>  ColorMap[] remapTable = {colorMap};<br>  imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);<br>  //The second color manipulation is used to change the opacity of the <br>  //watermark.  This is done by applying a 5x5 matrix that contains the <br>  //coordinates for the RGBA space.  By setting the 3rd row and 3rd column <br>  //to 0.3f we achive a level of opacity<br>  float[][] colorMatrixElements = { <br>           new float[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f},       <br>           new float[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f},        <br>           new float[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f},        <br>           new float[] {0.0f,  0.0f,  0.0f,  0.3f, 0.0f},        <br>           new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}}; <br>  ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);<br>  imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default,<br>   ColorAdjustType.Bitmap);<br>  //For this example we will place the watermark in the upper right<br>  //hand corner of the photograph. offset down 10 pixels and to the <br>  //left 10 pixles<br>  int xPosOfWm = ((phWidth - wmWidth)-10);<br>  int yPosOfWm = 10;<br>  grWatermark.DrawImage(imgWatermark, <br>   new Rectangle(xPosOfWm,yPosOfWm,wmWidth,wmHeight),  //Set the detination Position<br>   0,                  // x-coordinate of the portion of the source image to draw. <br>   0,                  // y-coordinate of the portion of the source image to draw. <br>   wmWidth,            // Watermark Width<br>   wmHeight,      // Watermark Height<br>   GraphicsUnit.Pixel, // Unit of measurment<br>   imageAttributes);   //ImageAttributes Object<br>  //Replace the original photgraphs bitmap with the new Bitmap<br>  imgPhoto = bmWatermark;<br>  grPhoto.Dispose();<br>  grWatermark.Dispose();<br>  //save new image to file system.<br>  imgPhoto.Save(WorkingDirectory + ImageName +&quot;_finally.jpg&quot;, ImageFormat.Jpeg);<br>  imgPhoto.Dispose();<br>  imgWatermark.Dispose();<br> }<br><br> private void WriteFontAndImg()<br> {  <br>  <br>  //create a image object containing the photograph to watermark<br>  Image imgPhoto = Image.FromFile(WorkingDirectory + ImageName);<br>  int phWidth = imgPhoto.Width;<br>  int phHeight = imgPhoto.Height;<br>  //create a Bitmap the Size of the original photograph<br>  Bitmap bmPhoto = new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);<br>  bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);<br>  //load the Bitmap into a Graphics object <br>  Graphics grPhoto = Graphics.FromImage(bmPhoto);<br>  //create a image object containing the watermark<br>  Image imgWatermark = new Bitmap(WorkingDirectory + ImageWater);<br>  int wmWidth = imgWatermark.Width;<br>  int wmHeight = imgWatermark.Height;<br>  //------------------------------------------------------------<br>  //Step #1 - Insert Copyright message<br>  //------------------------------------------------------------<br>  //Set the rendering quality for this Graphics object<br>  grPhoto.SmoothingMode = SmoothingMode.AntiAlias;<br>  //Draws the photo Image object at original size to the graphics object.<br>  grPhoto.DrawImage(<br>   imgPhoto,                               // Photo Image object<br>   new Rectangle(0, 0, phWidth, phHeight), // Rectangle structure<br>   0,                                      // x-coordinate of the portion of the source image to draw. <br>   0,                                      // y-coordinate of the portion of the source image to draw. <br>   phWidth,                                // Width of the portion of the source image to draw. <br>   phHeight,                               // Height of the portion of the source image to draw. <br>   GraphicsUnit.Pixel);                    // Units of measure <br>  //-------------------------------------------------------<br>  //to maximize the size of the Copyright message we will <br>  //test multiple Font sizes to determine the largest posible <br>  //font we can use for the width of the Photograph<br>  //define an array of point sizes you would like to consider as possiblities<br>  //-------------------------------------------------------<br>  int[] sizes = new int[]{16,14,12,10,8,6,4};<br>  Font crFont = null;<br>  SizeF crSize = new SizeF();<br>  //Loop through the defined sizes checking the length of the Copyright string<br>  //If its length in pixles is less then the image width choose this Font size.<br>  for (int i=0 ;i&lt;7; i++)<br>  {<br>   //set a Font object to Arial (i)pt, Bold<br>   crFont = new Font(&quot;arial&quot;, sizes<span style="font-style:italic"><wbr />, FontStyle.Bold);<br>   //Measure the Copyright string in this Font<br>   crSize = grPhoto.MeasureString(FontString, crFont);<br>   if((ushort)crSize.Width &lt; (ushort)phWidth)<br>    break;<br>  }<br>  //Since all photographs will have varying heights, determine a <br>  //position 5% from the bottom of the image<br>  int yPixlesFromBottom = (int)(phHeight *.05);<br>  //Now that we have a point size use the Copyrights string height <br>  //to determine a y-coordinate to draw the string of the photograph<br>  float yPosFromBottom = ((phHeight - yPixlesFromBottom)-(crSize.Height/2));<br>  //Determine its x-coordinate by calculating the center of the width of the image<br>  float xCenterOfImg = (phWidth/2);<br>  //Define the text layout by setting the text alignment to centered<br>  StringFormat StrFormat = new StringFormat();<br>  StrFormat.Alignment = StringAlignment.Center;<br>  //define a Brush which is semi trasparent black (Alpha set to 153)<br>  SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(153, 0, 0, 0));<br>  //Draw the Copyright string<br>  grPhoto.DrawString(FontString,                 //string of text<br>   crFont,                                   //font<br>   semiTransBrush2,                           //Brush<br>   new PointF(xCenterOfImg+1,yPosFromBottom+1),  //Position<br>   StrFormat);<br>  //define a Brush which is semi trasparent white (Alpha set to 153)<br>  SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(153, 255, 255, 255));<br>  //Draw the Copyright string a second time to create a shadow effect<br>  //Make sure to move this text 1 pixel to the right and down 1 pixel<br>  grPhoto.DrawString(FontString,                 //string of text<br>   crFont,                                   //font<br>   semiTransBrush,                           //Brush<br>   new PointF(xCenterOfImg,yPosFromBottom),  //Position<br>   StrFormat);                               //Text alignment<br>   <br>  //------------------------------------------------------------<br>  //Step #2 - Insert Watermark image<br>  //------------------------------------------------------------<br>  //Create a Bitmap based on the previously modified photograph Bitmap<br>  Bitmap bmWatermark = new Bitmap(bmPhoto);<br>  bmWatermark.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);<br>  //Load this Bitmap into a new Graphic Object<br>  Graphics grWatermark = Graphics.FromImage(bmWatermark);<br>  //To achieve a transulcent watermark we will apply (2) color <br>  //manipulations by defineing a ImageAttributes object and <br>  //seting (2) of its properties.<br>  ImageAttributes imageAttributes = new ImageAttributes();<br>  //The first step in manipulating the watermark image is to replace <br>  //the background color with one that is trasparent (Alpha=0, R=0, G=0, B=0)<br>  //to do this we will use a Colormap and use this to define a RemapTable<br>  ColorMap colorMap = new ColorMap();<br>  //My watermark was defined with a background of 100% Green this will<br>  //be the color we search for and replace with transparency<br>  colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);<br>  colorMap.NewColor = Color.FromArgb(0, 0, 0, 0); <br>  ColorMap[] remapTable = {colorMap};<br>  imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);<br>  //The second color manipulation is used to change the opacity of the <br>  //watermark.  This is done by applying a 5x5 matrix that contains the <br>  //coordinates for the RGBA space.  By setting the 3rd row and 3rd column <br>  //to 0.3f we achive a level of opacity<br>  float[][] colorMatrixElements = { <br>           new float[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f},       <br>           new float[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f},        <br>           new float[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f},        <br>           new float[] {0.0f,  0.0f,  0.0f,  0.3f, 0.0f},        <br>           new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}}; <br>  ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);<br>  imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default,<br>   ColorAdjustType.Bitmap);<br>  //For this example we will place the watermark in the upper right<br>  //hand corner of the photograph. offset down 10 pixels and to the <br>  //left 10 pixles<br>  int xPosOfWm = ((phWidth - wmWidth)-10);<br>  int yPosOfWm = 10;<br>  grWatermark.DrawImage(imgWatermark, <br>   new Rectangle(xPosOfWm,yPosOfWm,wmWidth,wmHeight),  //Set the detination Position<br>   0,                  // x-coordinate of the portion of the source image to draw. <br>   0,                  // y-coordinate of the portion of the source image to draw. <br>   wmWidth,            // Watermark Width<br>   wmHeight,      // Watermark Height<br>   GraphicsUnit.Pixel, // Unit of measurment<br>   imageAttributes);   //ImageAttributes Object<br>  //Replace the original photgraphs bitmap with the new Bitmap<br>  imgPhoto = bmWatermark;<br>  grPhoto.Dispose();<br>  grWatermark.Dispose();<br>  //save new image to file system.<br>  imgPhoto.Save(WorkingDirectory + ImageName +&quot;_finally.jpg&quot;, ImageFormat.Jpeg);<br>  imgPhoto.Dispose();<br>  imgWatermark.Dispose();<br>        <br> }<br>}<br><br> //水印图片加水印文字<br>//   ReDrawImg img = new ReDrawImg();<br>//   img .PublicWorkingDirectory = @&quot;C:\Watermark_src\WaterPic\&quot;;<br>//   img .PublicImageName = &quot;watermark_photo.jpg&quot;;<br>//   img .PublicImageWater = &quot;watermark.bmp&quot;;<br>//   img .PublicFontString = &quot;清清月儿&quot;;<br>//   img .DealImage(); <br>  <br>   //水印文字<br>   ReDrawImg img = new ReDrawImg();<br>   img .PublicWorkingDirectory = @&quot;C:\Watermark_src\WaterPic\&quot;;<br>   img .PublicImageName = &quot;watermark_photo.jpg&quot;;   <br>   img .PublicFontString = @&quot;清清月儿&quot;;<br>   img .DealImage();<br> <br>   //水印图片<br>//   ReDrawImg img = new ReDrawImg();<br>//   img .PublicWorkingDirectory = @&quot;C:\Watermark_src\WaterPic\&quot;;<br>//   img .PublicImageName = &quot;watermark_photo.jpg&quot;;<br>//   img .PublicImageWater = &quot;watermark.bmp&quot;;   <br>//   img .DealImage(); <br>  <br> <br><span style="font-weight:bold"><wbr />后台代码：</span><wbr /><br><br>using System;<br>using System.Data;<br>using System.Configuration;<br>using System.Collections;<br>using System.Web;<br>using System.Web.Security;<br>using System.Web.UI;<br>using System.Web.UI.WebControls;<br>using System.Web.UI.WebControls.WebParts;<br>using System.Web.UI.HtmlControls;<br>public partial class _Default : System.Web.UI.Page<br>{<br>    protected void Page_Load(object sender, EventArgs e)<br>    {<br>    }<br>    protected void bt_upload_Click(object sender, EventArgs e)<br>    {<br>        try<br>        {<br>            if (FileUpload1.PostedFile.FileName == &quot;&quot;)<br>            {<br>                this.lb_info.Text = &quot;请选择文件！&quot;;<br>            }<br>            else<br>            {<br>                string filepath = FileUpload1.PostedFile.FileName;<br>                string filename = filepath.Substring(filepath.LastIndexOf(&quot;\\&quot;) + 1);<br>                string serverpath1 = Server.MapPath(&quot;images/&quot;) + filename;<br>                //string serverpath2 = Server.MapPath(&quot;images/&quot;) + System.DateTime.Now.ToString(&quot;yyy-MM-dd-hh-mm-ss&quot;) + Session.SessionID + filename;<br>                FileUpload1.PostedFile.SaveAs(serverpath1);<br>                //ImageThumbnail img = new ImageThumbnail(filepath);<br>                //img.ReducedImage(0.4, serverpath2);<br>                DrawImg img = new DrawImg();<br>                img.PublicWorkingDirectory = Server.MapPath(&quot;images/&quot;);<br>                img.PublicImageName = filename;<br>                img.PublicFontString = &quot;http://blog.csdn.net/21aspnet&quot;;<br>                img.PublicImageWater = &quot;yyy.jpg&quot;;<br>                img.DealImage();<br>                this.lb_info.Text = &quot;上传成功！&quot;;<br>            }<br>        }<br>        catch (Exception error)<br>        {<br>            this.lb_info.Text = &quot;上传发生错误！原因：&quot; + error.ToString();<br>        }<br>    }<br><br>}<br></span><wbr /> <!--v:3.2--> ]]></description>
<category><![CDATA[.Net帮助]]></category>
<author><![CDATA[344791576@qq.com(【廆●仼】)]]></author>
<comments>http://344791576.qzone.qq.com/blog/1240993861#comment</comments>
<qz:effect>134218240</qz:effect>
<pubDate>Wed, 29 Apr 2009 08:31:01 GMT</pubDate>
<guid>http://344791576.qzone.qq.com/blog/1240993861</guid>
</item>

<item>
<title><![CDATA[ASP.NET2.0雷霆之怒盗链者的祝福]]></title>
<link>http://344791576.qzone.qq.com/blog/1240993476</link>
<description><![CDATA[<div style="text-align:center;"></div><span style="font-size:13px;line-height:1.8em;">所谓<span style="color:#ff0000;line-height:1.8em;">盗链</span><wbr />就是指其他网站把我们站点的文件链接帖到他们站上，这样白白占用我们的带宽。访问对于网站盗链行为，是非常不道德的。要实现防盗链，我们就得在IIS处理URL时拦截。<br>效果图：<br><span style="font-weight:bold"><wbr />未加防盗链之前：hm是我的机器名，用<a href="http://hm/myweb/default.aspx" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://hm/myweb/default.aspx</span><wbr /></a><wbr />和<a href="http://localhost/myweb/default" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://localhost/myweb/default</span><wbr /></a><wbr />访问结果一样。<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_d7.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_d7.gif" /></a><wbr />这幅图片是任人宰割的。</span><wbr /><br><span style="font-weight:bold"><wbr />加了防盗链之后虽然还是同一个网站但是<a href="http://hm/myweb/default.aspx" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://hm/myweb/default.aspx</span><wbr /></a><wbr />已经不能访问那副花卉图片，被以下图片替代：<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_d9.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_d9.gif" /></a><wbr /></span><wbr /><br><span style="font-weight:bold"><wbr />加了防盗链之后用localhost还是正常的！<a href="http://localhost/myweb/default" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://localhost/myweb/default</span><wbr /></a><wbr />访问结果一样。<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_d7.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_d7.gif" /></a><wbr /><br><br></span><wbr /><br><span style="font-weight:bold"><wbr />原理：</span><wbr /><br>其实hm是我的机器，但是由于服务器域名是localhost所以即使是同一个网站也不能访问，所以就更别说<br>www.<span style="color:#ff0000;line-height:1.8em;">其他网站域名</span><wbr />.com这样的网站偷取我们的资源。关键就是IIS对所有的请求进行过滤看看是不是本站域名的。<br><span style="font-weight:bold"><wbr />全部代码：</span><wbr /><br><span style="font-weight:bold"><wbr />Web.Config<br></span><wbr />&lt;?xml version=&quot;1.0&quot;?&gt;<br>&lt;!-- <br>    注意: 除了手动编辑此文件以外，您还可以使用 <br>    Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的<br>     “网站”-&gt;“Asp.Net 配置”选项。<br>    设置和注释的完整列表在 <br>    machine.config.comments 中，该文件通常位于 <br>    \Windows\Microsoft.Net\Framework\v2.x\Config 中<br>--&gt;<br>&lt;configuration&gt;<br> &lt;appSettings/&gt;<br> &lt;connectionStrings/&gt;<br> &lt;system.web&gt;<br>   <span style="font-weight:bold"><wbr /><span style="color:#ff0000;line-height:1.8em;"> &lt;httpHandlers&gt;<br>      &lt;add verb=&quot;*&quot; path=&quot;*.jpg&quot; type=&quot;myhandler,App_Code&quot;/&gt;<br>    &lt;/httpHandlers&gt;<br></span><wbr /></span><wbr />    &lt;!-- <br>            设置 compilation debug=&quot;true&quot; 将调试符号插入<br>            已编译的页面中。但由于这会 <br>            影响性能，因此只在开发过程中将此值 <br>            设置为 true。<br>        --&gt;<br>  &lt;compilation debug=&quot;true&quot;/&gt;<br>  &lt;!--<br>            通过 &lt;authentication&gt; 节可以配置 ASP.NET 使用的 <br>            安全身份验证模式，<br>            以标识传入的用户。 <br>        --&gt;<br>  &lt;authentication mode=&quot;Windows&quot;/&gt;<br>  &lt;!--<br>            如果在执行请求的过程中出现未处理的错误，<br>            则通过 &lt;customErrors&gt; 节可以配置相应的处理步骤。具体说来，<br>            开发人员通过该节可以配置<br>            要显示的 html 错误页<br>            以代替错误堆栈跟踪。<br>        &lt;customErrors mode=&quot;RemoteOnly&quot; defaultRedirect=&quot;GenericErrorPage.htm&quot;&gt;<br>            &lt;error statusCode=&quot;403&quot; redirect=&quot;NoAccess.htm&quot; /&gt;<br>            &lt;error statusCode=&quot;404&quot; redirect=&quot;FileNotFound.htm&quot; /&gt;<br>        &lt;/customErrors&gt;<br>        --&gt;<br> &lt;/system.web&gt;<br>&lt;/configuration&gt;<br><br><span style="font-weight:bold"><wbr /> myhandler.cs  新建myhandler.cs 类时系统提示你要放入<span style="color:#ff0000;line-height:1.8em;">App_Code</span><wbr />中<br></span><wbr />using System;<br>using System.Web;<br>/// &lt;summary&gt;<br>/// myhandler 的摘要说明<br>/// &lt;/summary&gt;<br>public class myhandler : IHttpHandler<br>{<br>    public void ProcessRequest(HttpContext context)<br>    {<br>        string FileName = context.Server.MapPath(context.Request.FilePath);<br>        if (context.Request.UrlReferrer.Host == null)<br>        {<br>            context.Response.ContentType = &quot;image/JPEG&quot;;<br>            <span style="color:#ff0000;line-height:1.8em;">context.Response.WriteFile(&quot;~/no.gif&quot;);//被替换图片<br></span><wbr />        }<br>        else<br>        {<br> <span style="color:#ff0000;line-height:1.8em;">           if (context.Request.UrlReferrer.Host.IndexOf(&quot;<span style="font-weight:bold"><wbr />localhost</span><wbr />&quot;) &gt; -1)//这里是你的域名</span><wbr /><br>            {<br>                context.Response.ContentType = &quot;image/JPEG&quot;;<br>                context.Response.WriteFile(FileName);<br>            }<br>            else<br>            {<br>                context.Response.ContentType = &quot;image/JPEG&quot;;<br>                context.Response.WriteFile(&quot;~/no.gif&quot;);<br>            }<br>        }<br>    }<br>    public bool IsReusable<br>    {<br>        get { return true; }<br>    }<br>    public myhandler()<br>    {<br>    }<br>}<br><span style="font-weight:bold"><wbr />Default.aspx<br></span><wbr />&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</span><wbr /></a><wbr />&quot;&gt;<br>&lt;html xmlns=&quot;<a href="http://www.w3.org/1999/xhtml" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://www.w3.org/1999/xhtml</span><wbr /></a><wbr />&quot; &gt;<br>&lt;head runat=&quot;server&quot;&gt;<br>    &lt;title&gt;清清月儿<a href="http://blog.csdn.net/21aspnet%3C/title" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://blog.csdn.net/21aspnet</span><wbr /></a><wbr />&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;<br>    &lt;div&gt;<br>        &lt;img src=&quot;pic130.jpg&quot; /&gt;&lt;/div&gt;<br>    &lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br><span style="font-weight:bold"><wbr />pic130.jpg<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_pic130.jpg" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_pic130.jpg" /></a><wbr /></span><wbr /><br><br><span style="font-weight:bold"><wbr />no.gif<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_no.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_no.gif" /></a><wbr /></span><wbr /><br><span style="font-weight:bold"><wbr />IIS的配置：<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_d10.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_d10.gif" /></a><wbr /><br><br></span><wbr /><span style="font-weight:bold"><wbr />配置应用程序扩展：添加一个.jpg的扩展！<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_d11.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_d11.gif" /></a><wbr /></span><wbr /><br><span style="font-weight:bold"><wbr />注意：在本地的</span><wbr /><span style="color:#ff0000;line-height:1.8em;">context.Request.UrlReferrer.Host就是localhost，<br>我开始以为<a href="http://localhost/A/" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://localhost/A/</span><wbr /></a><wbr />和<a href="http://localhost/B/" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://localhost/B/是不同的</span><wbr /></a><wbr /></span><wbr /><span style="font-size:16px;line-height:1.8em;">context.Request.UrlReferrer.Host，那就是大错特错。</span><wbr /><a href="http://localhost/A/" target="_blank"><span style="color:#cc4c7f;font-size:16px;line-height:1.8em;">http://localhost/A/</span><wbr /></a><wbr /><span style="color:#ff0000;font-size:16px;line-height:1.8em;">和</span><wbr /><a href="http://localhost/B/" target="_blank"><span style="color:#cc4c7f;font-size:16px;line-height:1.8em;">http://localhost/B/</span><wbr /></a><wbr /><span style="font-size:16px;line-height:1.8em;">的context.Request.UrlReferrer.Host都是localhost，所以测试一个用localhost，</span><wbr />所以，本地测试用<span style="font-weight:bold"><wbr />机器名</span><wbr />例如我的是hm测试即可。经过处理后用机器名访问就不行，虽然还是同一个站点，同一个文件，此处请多注意。<br><span style="color:#ff0000;line-height:1.8em;"><span style="font-weight:bold"><wbr />下面是怎么防rar文件不从主站下载：方法和图片类似，不过下载我们强迫他们到我们站点。</span><wbr /></span><wbr /><br>1、  首先创建一个类库项目ClassLibrary1：<br>using System;<br>using System.Web;    // 引用System.Web组件<br> <br> <br> public class MyHandler : IHttpHandler<br> {<br>  public MyHandler()<br>  {<br>  }<br> <br>  #region IHttpHandler 成员<br>  public void ProcessRequest(HttpContext context)<br>  {<br>   // 跳转到WebForm1.aspx，由WebForm1.aspx输出rar文件<br>   HttpResponse response = context.Response;<br>   response.Redirect(&quot;../manage/downloads.aspx&quot;);<br>  }<br> <br>  public bool IsReusable<br>  {<br>   get<br>   {<br>    // TODO:  添加 MyHandler.IsReusable getter 实现<br>    return true;<br>   }<br>  }<br>  #endregion<br> }<br> <br>2、  在配置文件Web.config文件节点里增加如下节点：<br><span style="font-weight:bold"><wbr /><span style="color:#ff0000;line-height:1.8em;"> &lt;httpHandlers&gt;<br>      &lt;add verb=&quot;*&quot; path=&quot;*.rar&quot; type=&quot;myhandler,App_Code&quot;/&gt;<br>    &lt;/httpHandlers&gt;</span><wbr /></span><wbr /><br><br>3、  在WebForm1.aspx里增加一个文本为“下载”的Button，其Click事件如下：<br>注意别忘记了using System.IO;<br>private void Button1_Click(object sender, System.EventArgs e)<br>  {<br>   FileInfo file = new System.IO.FileInfo(Server.MapPath(&quot;1.rar&quot;));<br>   Response.Clear();<br>   Response.AddHeader(&quot;Content-Disposition&quot;, &quot;filename=&quot; + file.Name);<br>   Response.AddHeader(&quot;Content-Length&quot;, file.Length.ToString());<br>   string fileExtension = file.Extension;<br> <br>   // 根据文件后缀指定文件的Mime类型<br>   switch (fileExtension)<br>   {<br>    case &quot;.mp3&quot;:<br>     Response.ContentType = &quot;audio/mpeg3&quot;;<br>     break;<br>    case &quot;mpeg&quot;:<br>     Response.ContentType = &quot;video/mpeg&quot;;<br>     break;<br>    case &quot;jpg&quot;:<br>     Response.ContentType = &quot;image/jpeg&quot;;<br>     break;<br>    case &quot;........等等&quot;:<br>     Response.ContentType = &quot;....&quot;;<br>     break;<br>    default:<br>     Response.ContentType = &quot;application/octet-stream&quot;;<br>     break;<br>   }<br> <br>   Response.WriteFile(file.FullName);<br>   Response.End();<br> <br>  }<br>4、  最后一步就是在IIS里增加一个应用程序扩展。在“默认网站”-&gt;“属性”-&gt;“主目录”-&gt;“配置”。在弹出的“应用程序配置”窗口里按“添加”，在弹出的“添加/编辑应用程序扩展名映射”窗口里“可执行文件”选择C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll，在扩展名里输入“.rar”，然后确定即可。<br>5、  在IE里输入http://localhost/web/1.rar，会立即跳转到<a href="http://localhost/web/WebForm1.aspx" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://localhost/web/WebForm1.aspx</span><wbr /></a><wbr />，然后按WebForm1.aspx的“下载”按钮就可以下载1.rar了。<br></span><wbr /> <!--v:3.2--> ]]></description>
<category><![CDATA[个人日记]]></category>
<author><![CDATA[344791576@qq.com(【廆●仼】)]]></author>
<comments>http://344791576.qzone.qq.com/blog/1240993476#comment</comments>
<qz:effect>134218241</qz:effect>
<pubDate>Wed, 29 Apr 2009 08:24:36 GMT</pubDate>
<guid>http://344791576.qzone.qq.com/blog/1240993476</guid>
</item>

<item>
<title><![CDATA[ASP.NET2.0轻松搞定统计图表]]></title>
<link>http://344791576.qzone.qq.com/blog/1240992832</link>
<description><![CDATA[<span style="font-size:13px;line-height:1.8em;">本文讲述如何绘制<span style="font-weight:bold"><wbr />条形图</span><wbr />，<span style="font-weight:bold"><wbr />折线图</span><wbr />，<span style="font-weight:bold"><wbr />柱形图</span><wbr />，<span style="font-weight:bold"><wbr />面积图</span><wbr />等常见图形。</span><wbr /><br><span style="font-size:13px;line-height:1.8em;"><span style="font-weight:bold"><wbr />效果图</span><wbr />：<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_owc7.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_owc7.gif" /></a><wbr /></span><wbr /><br><span style="font-size:13px;line-height:1.8em;"><span style="font-weight:bold"><wbr />手把手教程：</span><wbr /></span><wbr /><br><span style="font-size:13px;line-height:1.8em;"><span style="font-weight:bold"><wbr />原理：<span style="color:#ff0000;line-height:1.8em;">OWC</span><wbr /></span><wbr />是Office   Web   Compent的缩写，即Microsoft的Office   Web组件，它为在Web中绘制图形提供了灵活的同时也是最基本的机制。在一个intranet环境中，如果可以假设客户机上存在特定的浏览器和一些功能强大的软件（如IE6和Office   2000/XP/2003），那么就有能力利用Office   Web组件提供一个交互式图形开发环境。这种模式下，客户端工作站将在整个任务中分担很大的比重。理论上说<span style="color:#ff0000;line-height:1.8em;"><span style="font-weight:bold"><wbr />Excel</span><wbr /></span><wbr />能做的图都可以通过OWC画。</span><wbr /><br><span style="font-size:13px;line-height:1.8em;">第一步：<br>右键点击网站根目录引用。如图所示：<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_owc1.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_owc1.gif" /></a><wbr /></span><wbr /><br><span style="font-size:13px;line-height:1.8em;">第二步：<br>点击“添加引用”后弹出一个窗口，添加OWC的引用。如图所示：<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_owc2.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_owc2.gif" /></a><wbr /><br>点“确定”。</span><wbr /><br><span style="font-size:13px;line-height:1.8em;">第三步：<br>代码中引用Microsoft.Office.Interop.Owc11。</span><wbr /><br><span style="font-size:13px;line-height:1.8em;">全部代码<br><span style="font-weight:bold"><wbr />后台代码</span><wbr />：<br>using System;<br>using System.Data;<br>using System.Configuration;<br>using System.Web;<br>using System.Web.Security;<br>using System.Web.UI;<br>using System.Web.UI.WebControls;<br>using System.Web.UI.WebControls.WebParts;<br>using System.Web.UI.HtmlControls;</span><wbr /><br><span style="font-size:13px;line-height:1.8em;">using System.Data.SqlClient;   //添加数据操作引用<br>using Microsoft.Office.Interop.Owc11;//添加Office组件引用</span><wbr /><br><span style="font-size:13px;line-height:1.8em;">public partial class OWCdrawing : System.Web.UI.Page<br>{<br>    protected void Page_Load(object sender, EventArgs e)<br>    {</span><wbr /><br><span style="font-size:13px;line-height:1.8em;">        //连接数据库并获取特定字符串<br>        string strSeriesName = &quot;图例1&quot;;<br>        string ConnectString = &quot;Server=(local);DataBase=web;Uid=sa;Pwd=sa&quot;;<br>        string Sql = &quot;SELECT month,Allcount FROM Chart&quot;;<br>        SqlConnection myConn = new SqlConnection(ConnectString);<br>        myConn.Open();<br>        SqlDataAdapter Da = new SqlDataAdapter(Sql, myConn);<br>        DataSet ds = new DataSet();<br>        Da.Fill(ds);</span><wbr /><br><span style="font-size:13px;line-height:1.8em;">        //存放月<br>        string[] MonNum = new string[12];<br>        //存放数据<br>        string[] MonCount = new string[12];<br>        //为数组赋值<br>        for (int i = 0; i &lt; ds.Tables[0].Rows.Count; i++)<br>        {<br>            MonNum<span style="font-style:italic"><wbr /> = ds.Tables[0].Rows<span style="font-style:italic"><wbr />[0].ToString();<br>            MonCount<span style="font-style:italic"><wbr /> = ds.Tables[0].Rows<span style="font-style:italic"><wbr />[1].ToString();<br>        }<br>        //为x轴指定特定字符串，以便显示数据<br>        string strXdata = String.Empty;<br>        foreach (string strData in MonNum)<br>        {<br>            strXdata += strData + &quot;\t&quot;;<br>        }<br>        string strYdata = String.Empty;<br>        //为y轴指定特定的字符串，以便与x轴相对应<br>        foreach (string strValue in MonCount)<br>        {<br>            strYdata += strValue + &quot;\t&quot;;<br>        }</span><wbr /><br><span style="font-size:13px;line-height:1.8em;">        //创建ChartSpace对象来放置图表<br>        ChartSpace laySpace = new ChartSpaceClass();</span><wbr /><br><span style="font-size:13px;line-height:1.8em;">        //在ChartSpace对象中添加图表<br>        ChChart InsertChart = laySpace.Charts.Add(0);</span><wbr /><br><span style="font-size:13px;line-height:1.8em;">        //指定绘制图表的类型。类型可以通过OWC.ChartChartTypeEnum枚举值得到<br>        //InsertChart.Type = ChartChartTypeEnum.chChartTypeLine;//折线图<br>        //InsertChart.Type = ChartChartTypeEnum.chChartTypeArea;//面积图<br>        //InsertChart.Type = ChartChartTypeEnum.chChartTypeBarClustered;//条形图<br>        InsertChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;//柱形图</span><wbr /><br><span style="font-size:13px;line-height:1.8em;"> <br>        //指定图表是否需要图例标注<br>        InsertChart.HasLegend = false;<br>        <br>        InsertChart.HasTitle = true;//为图表添加标题<br>        InsertChart.Title.Caption = &quot;2006年清清月儿每个月花销流水账&quot;;//标题名称<br>        //为x,y轴添加图示说明<br>        InsertChart.Axes[0].HasTitle = true;<br>        InsertChart.Axes[0].Title.Caption = &quot;&quot;;//月份<br>        InsertChart.Axes[1].HasTitle = true;<br>        InsertChart.Axes[1].Scaling.SplitMinimum = 200;<br>        InsertChart.Axes[1].Title.Caption = &quot;数量&quot;;<br>        //添加一个series系列<br>        InsertChart.SeriesCollection.Add(0);<br>        //给定series系列的名字<br>        InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);<br>        //给定分类<br>        InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strXdata);<br>        //给定值<br>        InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strYdata);<br>        //输出文件.<br>        string strAbsolutePath = (Server.MapPath(&quot;.&quot;)) + &quot;[url=file://ShowData.gif/]<span style="color:#cc4c7f;line-height:1.8em;">\\ShowData.gif</span><wbr />[/url]&quot;;<br>        laySpace.ExportPicture(strAbsolutePath, &quot;GIF&quot;, 400, 250);<br>        //创建GIF文件的相对路径.<br>        string strRelativePath = &quot;./ShowData.gif&quot;;<br>        //把图片添加到placeholder中，并在页面上显示<br>        string strImageTag = &quot;&lt;IMG SRC='&quot; + strRelativePath + &quot;'/&gt;&quot;;<br>        this.PlaceHolder1.Controls.Add(new LiteralControl(strImageTag));<br>    }<br>}<br><br><span style="font-weight:bold"><wbr />前台代码</span><wbr />：<br>&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;OWCdrawing.aspx.cs&quot; Inherits=&quot;OWCdrawing&quot; %&gt;<br>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</span><wbr /></a><wbr />&quot;&gt;<br>&lt;html xmlns=&quot;<a href="http://www.w3.org/1999/xhtml" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://www.w3.org/1999/xhtml</span><wbr /></a><wbr />&quot; &gt;<br>&lt;head runat=&quot;server&quot;&gt;<br>    &lt;title&gt;清清月儿<span style="color:#cc4c7f;line-height:1.8em;">http://blog.csdn.net/21aspnet&lt;/title</span><wbr />&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;<br>   &lt;div style=&quot;text-align: left&quot;&gt;<br>        &lt;table style=&quot;width: 600px&quot;&gt;<br>            &lt;tr&gt;<br>                &lt;td colspan=&quot;3&quot; style=&quot;height: 20px&quot;&gt;<br>                    &lt;strong&gt;怎么样在ASP.NET2.0中使用OWC组件画图&lt;/strong&gt;&lt;/td&gt;<br>            &lt;/tr&gt;<br>            &lt;tr&gt;<br>                &lt;td colspan=&quot;3&quot; rowspan=&quot;2&quot; style=&quot;height: 21px&quot;&gt;<br>        &lt;asp:PlaceHolder ID=&quot;PlaceHolder1&quot; runat=&quot;server&quot;&gt;&lt;/asp:PlaceHolder&gt;<br>                &lt;/td&gt;<br>            &lt;/tr&gt;<br>            &lt;tr&gt;<br>            &lt;/tr&gt;<br>        &lt;/table&gt;<br>    <br>    &lt;/div&gt;<br>    &lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br><br><span style="font-weight:bold"><wbr />数据库SQL脚本</span><wbr />：<br>USE [web]<br>GO<br>/****** 对象:  Table [dbo].[Chart]    脚本日期: 03/27/2007 22:26:00 ******/<br>SET ANSI_NULLS ON<br>GO<br>SET QUOTED_IDENTIFIER ON<br>GO<br>CREATE TABLE [dbo].[Chart](<br> [id] [int] IDENTITY(1,1) NOT NULL,<br> [month] [smallint] NULL,<br> [Allcount] [int] NULL<br>) ON [PRIMARY]<br><br>在数据库建好表以后要自己手动假想有12条数据，手动添加，最终结果类似下图：<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_owc9.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_owc9.gif" /></a><wbr /><br>后台程序说明：<br>最关键就是<span style="color:#ff0000;line-height:1.8em;">InsertChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;</span><wbr /><br><span style="color:#ff0000;line-height:1.8em;"><span style="color:#000000;line-height:1.8em;">你可以在</span><wbr />ChartChartTypeEnum</span><wbr />后<span style="font-weight:bold"><wbr /><span style="color:#ff00ff;line-height:1.8em;">点</span><wbr /></span><wbr />出其他方法。如图所示：<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_owc3.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_owc3.gif" /></a><wbr /><br>下面列出的是其他类型图：<br>折线图：<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_owc4.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_owc4.gif" /></a><wbr /><br> <br><br>面积图：<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_owc5.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_owc5.gif" /></a><wbr /><br>条形图：<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_owc6.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_owc6.gif" /></a><wbr /><br><br>OWC什么图形都可以画，还能画立体的，请大家自己尝试。<br>可以参考OWC手册，具体位置：<br><span style="color:#ff0000;line-height:1.8em;"><span style="font-weight:bold"><wbr />C:\Program Files\Common Files\Microsoft Shared\Web Components\11\2052\OWCVBA11.CHM</span><wbr /></span><wbr /> <br></span><wbr /> <!--v:3.2--> ]]></description>
<category><![CDATA[.Net帮助]]></category>
<author><![CDATA[344791576@qq.com(【廆●仼】)]]></author>
<comments>http://344791576.qzone.qq.com/blog/1240992832#comment</comments>
<qz:effect>134218241</qz:effect>
<pubDate>Wed, 29 Apr 2009 08:13:52 GMT</pubDate>
<guid>http://344791576.qzone.qq.com/blog/1240992832</guid>
</item>

<item>
<title><![CDATA[GridView数据导入Excel/Excel数据读入GridView]]></title>
<link>http://344791576.qzone.qq.com/blog/1240992203</link>
<description><![CDATA[<span style="font-weight:bold"><wbr />GridView<span style="font-size:13px;line-height:1.8em;">数据导入Excel/Excel数据读入GridView</span><wbr /></span><wbr /><span style="font-size:13px;line-height:1.8em;"><span style="font-weight:bold"><wbr />效果图：<br></span><wbr /></span><wbr /><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_gv31.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_gv31.gif" /></a><wbr /><br><span style="font-weight:bold"><wbr />解决方案：<br>页面增加一个按钮，单击事件添加如下方法：<br></span><wbr />protected void Button1_Click(object sender, EventArgs e)<br>    {<br>        Export(&quot;application/ms-excel&quot;, &quot;学生成绩报表.xls&quot;);<br>    }<br>    private void Export(string FileType, string FileName)<br>    {<br>        Response.Charset = &quot;GB2312&quot;;<br>        Response.ContentEncoding = System.Text.Encoding.UTF7;<br>        Response.AppendHeader(&quot;Content-Disposition&quot;, &quot;attachment;filename=&quot; + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());<br>        Response.ContentType = FileType;<br>        this.EnableViewState = false;<br>        StringWriter tw = new StringWriter();<br>        HtmlTextWriter hw = new HtmlTextWriter(tw);<br>        GridView1.RenderControl(hw);<br>        Response.Write(tw.ToString());<br>        Response.End();<br>    }<br>//如果没有下面方法会报错<span style="font-weight:bold"><wbr /><span style="color:#ff0000;line-height:1.8em;">类型“GridView”的控件“GridView1”必须放在具有 runat=server 的窗体标记内<br></span><wbr />    </span><wbr /><span style="font-weight:bold"><wbr />public override void VerifyRenderingInServerForm(Control control)<br>    {<br>    }<br>还有由于是文件操作所以要引入名称空间IO和Text</span><wbr /><br><span style="font-weight:bold"><wbr />后台代码：<br></span><wbr />using System;<br>using System.Data;<br>using System.Configuration;<br>using System.Web;<br>using System.Web.Security;<br>using System.Web.UI;<br>using System.Web.UI.WebControls;<br>using System.Web.UI.WebControls.WebParts;<br>using System.Web.UI.HtmlControls;<br>using System.Data.SqlClient;<br>using System.Drawing;<br>using System.IO;<br>using System.Text;<br>public partial class Default7 : System.Web.UI.Page<br>{<br>    SqlConnection sqlcon;<br>    SqlCommand sqlcom;<br>    string strCon = &quot;Data Source=(local);Database=北风贸易;Uid=sa;Pwd=sa&quot;;<br>    protected void Page_Load(object sender, EventArgs e)<br>    {<br>        if (!IsPostBack)<br>        {<br>            bind();<br>        }<br>    }<br>    <br>    public void bind()<br>    {<br>        string sqlstr = &quot;select top 5 * from 飞狐工作室&quot;;<br>        sqlcon = new SqlConnection(strCon);<br>        SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);<br>        DataSet myds = new DataSet();<br>        sqlcon.Open();<br>        myda.Fill(myds, &quot;飞狐工作室&quot;);<br>        GridView1.DataSource = myds;<br>        GridView1.DataKeyNames = new string[] { &quot;身份证号码&quot; };<br>        GridView1.DataBind();<br>        sqlcon.Close();<br>    }<br>    protected void Button1_Click(object sender, EventArgs e)<br>    {<br>        Export(&quot;application/ms-excel&quot;, &quot;学生成绩报表.xls&quot;);<br>    }<br>    private void Export(string FileType, string FileName)<br>    {<br>        Response.Charset = &quot;GB2312&quot;;<br>        Response.ContentEncoding = System.Text.Encoding.UTF7;<br>        Response.AppendHeader(&quot;Content-Disposition&quot;, &quot;attachment;filename=&quot; + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());<br>        Response.ContentType = FileType;<br>        this.EnableViewState = false;<br>        StringWriter tw = new StringWriter();<br>        HtmlTextWriter hw = new HtmlTextWriter(tw);<br>        GridView1.RenderControl(hw);<br>        Response.Write(tw.ToString());<br>        Response.End();<br>    }<br>    public override void VerifyRenderingInServerForm(Control control)<br>    {<br>    }<br>    <br>}<br><span style="font-weight:bold"><wbr />前台</span><wbr />：<br>&lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot;    AutoGenerateColumns=&quot;False&quot; CellPadding=&quot;3&quot;  <br>                         BackColor=&quot;White&quot; BorderColor=&quot;#CCCCCC&quot; BorderStyle=&quot;None&quot; BorderWidth=&quot;1px&quot; Font-Size=&quot;12px&quot;   &gt;<br>                        &lt;FooterStyle BackColor=&quot;White&quot; ForeColor=&quot;#000066&quot; /&gt;<br>                        &lt;Columns&gt;<br>                            &lt;asp:BoundField DataField=&quot;身份证号码&quot; HeaderText=&quot;编号&quot; ReadOnly=&quot;True&quot; /&gt;<br>                            &lt;asp:BoundField DataField=&quot;姓名&quot; HeaderText=&quot;姓名&quot;  /&gt;<br>                            &lt;asp:BoundField DataField=&quot;出生日期&quot; HeaderText=&quot;邮政编码&quot;  /&gt;<br>                            &lt;asp:BoundField DataField=&quot;家庭住址&quot; HeaderText=&quot;家庭住址&quot;  /&gt;<br>                            &lt;asp:BoundField DataField=&quot;邮政编码&quot; HeaderText=&quot;邮政编码&quot; /&gt;<br>                            &lt;asp:BoundField DataField=&quot;起薪&quot; HeaderText=&quot;起薪&quot;  /&gt;<br>                           <br>                        &lt;/Columns&gt;<br>                        &lt;RowStyle ForeColor=&quot;#000066&quot; /&gt;<br>                        &lt;SelectedRowStyle BackColor=&quot;#669999&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;<br>                        &lt;PagerStyle BackColor=&quot;White&quot; ForeColor=&quot;#000066&quot; HorizontalAlign=&quot;Left&quot;  CssClass=&quot;ms-formlabel DataGridFixedHeader&quot;/&gt;<br>                        &lt;HeaderStyle BackColor=&quot;#006699&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;<br>                    &lt;/asp:GridView&gt;<br>        &lt;asp:Button ID=&quot;Button1&quot; runat=&quot;server&quot; OnClick=&quot;Button1_Click&quot; Text=&quot;导出&quot; /&gt;<br><span style="font-weight:bold"><wbr />读取Excel数据的代码</span><wbr />：这个很简单的<br>private DataSet CreateDataSource()<br>    {<br>        string strCon;<br>        strCon = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; + Server.MapPath(&quot;excel.xls&quot;) + &quot;; Extended Properties=Excel 8.0;&quot;;<br>        OleDbConnection olecon = new OleDbConnection(strCon);<br>        OleDbDataAdapter myda = new OleDbDataAdapter(&quot;SELECT * FROM [Sheet1$]&quot;, strCon);<br>        DataSet myds = new DataSet();<br>        myda.Fill(myds);<br>        return myds;<br>    }<br>    protected void Button1_Click(object sender, EventArgs e)<br>    {<br>        GridView1.DataSource = CreateDataSource();<br>        GridView1.DataBind();<br>    }<br> <!--v:3.2--> ]]></description>
<category><![CDATA[.Net帮助]]></category>
<author><![CDATA[344791576@qq.com(【廆●仼】)]]></author>
<comments>http://344791576.qzone.qq.com/blog/1240992203#comment</comments>
<qz:effect>134218241</qz:effect>
<pubDate>Wed, 29 Apr 2009 08:03:23 GMT</pubDate>
<guid>http://344791576.qzone.qq.com/blog/1240992203</guid>
</item>

<item>
<title><![CDATA[GridView加入自动求和求平均值小计]]></title>
<link>http://344791576.qzone.qq.com/blog/1240992140</link>
<description><![CDATA[<span style="font-weight:bold"><wbr /><span style="font-size:13px;line-height:1.8em;">GridView加入自动求和求平均值小计<br></span><wbr /></span><wbr /><span style="font-weight:bold"><wbr /><span style="font-size:13px;line-height:1.8em;">效果图：</span><wbr /></span><wbr /><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_gv30.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_gv30.gif" /></a><wbr /><br>解决方案：    <br><span style="color:#ff0000;line-height:1.8em;">private double sum = 0;//取指定列的数据和，你要根据具体情况对待可能你要处理的是int<br>protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)<br>    {<br>        <br>        if (e.Row.RowIndex &gt;= 0)<br>        {<br>            sum += Convert.ToDouble(e.Row.Cells[6].Text);<br>        }<br>        else if (e.Row.RowType == DataControlRowType.Footer)<br>        {<br>            e.Row.Cells[5].Text = &quot;总薪水为：&quot;;<br>            e.Row.Cells[6].Text = sum.ToString();<br>            e.Row.Cells[3].Text = &quot;平均薪水为：&quot;;<br>            e.Row.Cells[4].Text = ((int)(sum / GridView1.Rows.Count)).ToString();<br>            <br>        }<br>    }</span><wbr /><br><span style="font-weight:bold"><wbr />后台全部代码：<br></span><wbr />using System;<br>using System.Data;<br>using System.Configuration;<br>using System.Web;<br>using System.Web.Security;<br>using System.Web.UI;<br>using System.Web.UI.WebControls;<br>using System.Web.UI.WebControls.WebParts;<br>using System.Web.UI.HtmlControls;<br>using System.Data.SqlClient;<br>using System.Drawing;<br>public partial class Default7 : System.Web.UI.Page<br>{<br>    SqlConnection sqlcon;<br>    SqlCommand sqlcom;<br>    string strCon = &quot;Data Source=(local);Database=北风贸易;Uid=sa;Pwd=sa&quot;;<br>    protected void Page_Load(object sender, EventArgs e)<br>    {<br>        if (!IsPostBack)<br>        {<br>            bind();<br>        }<br>    }<br>    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)<br>    {<br>        GridView1.EditIndex = e.NewEditIndex;<br>        bind();<br>    }<br>    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)<br>    {<br>        sqlcon = new SqlConnection(strCon);<br>        string sqlstr = &quot;update 飞狐工作室 set 姓名='&quot;<br>            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + &quot;',家庭住址='&quot;<br>            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + &quot;' where 身份证号码='&quot;<br>            + GridView1.DataKeys[e.RowIndex].Value.ToString() + &quot;'&quot;;<br>        sqlcom = new SqlCommand(sqlstr, sqlcon);<br>        sqlcon.Open();<br>        sqlcom.ExecuteNonQuery();<br>        sqlcon.Close();<br>        GridView1.EditIndex = -1;<br>        bind();<br>    }<br>    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)<br>    {<br>        GridView1.EditIndex = -1;<br>        bind();<br>    }<br>    public void bind()<br>    {<br>        string sqlstr = &quot;select top 5 * from 飞狐工作室&quot;;<br>        sqlcon = new SqlConnection(strCon);<br>        SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);<br>        DataSet myds = new DataSet();<br>        sqlcon.Open();<br>        myda.Fill(myds, &quot;飞狐工作室&quot;);<br>        GridView1.DataSource = myds;<br>        GridView1.DataKeyNames = new string[] { &quot;身份证号码&quot; };<br>        GridView1.DataBind();<br>        sqlcon.Close();<br>    }<br>    private double sum = 0;//取指定列的数据和<br>    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)<br>    {<br>        <br>        if (e.Row.RowIndex &gt;= 0)<br>        {<br>            sum += Convert.ToDouble(e.Row.Cells[6].Text);<br>        }<br>        else if (e.Row.RowType == DataControlRowType.Footer)<br>        {<br>            e.Row.Cells[5].Text = &quot;总薪水为：&quot;;<br>            e.Row.Cells[6].Text = sum.ToString();<br>            e.Row.Cells[3].Text = &quot;平均薪水为：&quot;;<br>            e.Row.Cells[4].Text = ((int)(sum / GridView1.Rows.Count)).ToString();<br>            <br>        }<br>    }<br>}<br>前台：唯一的花头就是设置<span style="color:#ff0000;line-height:1.8em;">ShowFooter=&quot;True&quot;</span><wbr /> ，否则默认表头为<span style="font-weight:bold"><wbr />隐藏</span><wbr />的！<br>&lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot;    AutoGenerateColumns=&quot;False&quot; CellPadding=&quot;3&quot;  OnRowEditing=&quot;GridView1_RowEditing&quot;<br>                        OnRowUpdating=&quot;GridView1_RowUpdating&quot; OnRowCancelingEdit=&quot;GridView1_RowCancelingEdit&quot; BackColor=&quot;White&quot; BorderColor=&quot;#CCCCCC&quot; BorderStyle=&quot;None&quot; BorderWidth=&quot;1px&quot; Font-Size=&quot;12px&quot; OnRowDataBound=&quot;GridView1_RowDataBound&quot; ShowFooter=&quot;True&quot;  &gt;<br>                        &lt;FooterStyle BackColor=&quot;White&quot; ForeColor=&quot;#000066&quot; /&gt;<br>                        &lt;Columns&gt;<br>                            &lt;asp:CommandField HeaderText=&quot;编辑&quot; ShowEditButton=&quot;True&quot; /&gt;<br>                            &lt;asp:BoundField DataField=&quot;身份证号码&quot; HeaderText=&quot;编号&quot; ReadOnly=&quot;True&quot; /&gt;<br>                            &lt;asp:BoundField DataField=&quot;姓名&quot; HeaderText=&quot;姓名&quot;  /&gt;<br>                            &lt;asp:BoundField DataField=&quot;出生日期&quot; HeaderText=&quot;邮政编码&quot;  /&gt;<br>                            &lt;asp:BoundField DataField=&quot;家庭住址&quot; HeaderText=&quot;家庭住址&quot;  /&gt;<br>                            &lt;asp:BoundField DataField=&quot;邮政编码&quot; HeaderText=&quot;邮政编码&quot; /&gt;<br>                            &lt;asp:BoundField DataField=&quot;起薪&quot; HeaderText=&quot;起薪&quot;  /&gt;<br>                           <br>                        &lt;/Columns&gt;<br>                        &lt;RowStyle ForeColor=&quot;#000066&quot; /&gt;<br>                        &lt;SelectedRowStyle BackColor=&quot;#669999&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;<br>                        &lt;PagerStyle BackColor=&quot;White&quot; ForeColor=&quot;#000066&quot; HorizontalAlign=&quot;Left&quot;  CssClass=&quot;ms-formlabel DataGridFixedHeader&quot;/&gt;<br>                        &lt;HeaderStyle BackColor=&quot;#006699&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;<br>                    &lt;/asp:GridView&gt;<br> <!--v:3.2--> ]]></description>
<category><![CDATA[.Net帮助]]></category>
<author><![CDATA[344791576@qq.com(【廆●仼】)]]></author>
<comments>http://344791576.qzone.qq.com/blog/1240992140#comment</comments>
<qz:effect>134218241</qz:effect>
<pubDate>Wed, 29 Apr 2009 08:02:20 GMT</pubDate>
<guid>http://344791576.qzone.qq.com/blog/1240992140</guid>
</item>

<item>
<title><![CDATA[GridView突出显示某一单元格（例如金额低于多少，分数不及格等）]]></title>
<link>http://344791576.qzone.qq.com/blog/1240992099</link>
<description><![CDATA[<span style="font-weight:bold"><wbr /><span style="font-size:13px;line-height:1.8em;">GridView突出显示某一单元格（例如金额低于多少，分数不及格等）</span><wbr /></span><wbr /><span style="font-weight:bold"><wbr /><span style="font-size:13px;line-height:1.8em;">效果图：<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_gv28.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_gv28.gif" /></a><wbr /><br></span><wbr /></span><wbr /><br><span style="font-size:13px;line-height:1.8em;"><span style="font-weight:bold"><wbr />解决方案：主要是绑定后过滤<br></span><wbr /> GridView1.DataBind();<br>       <span style="color:#ff0000;line-height:1.8em;"> for (int i = 0; i &lt;= GridView1.Rows.Count - 1; i++)<br>        {<br>            DataRowView mydrv = myds.Tables[&quot;飞狐工作室&quot;].DefaultView<span style="font-style:italic"><wbr />;<br>            string score = Convert.ToString(mydrv[&quot;起薪&quot;]);<br>            if (Convert.ToDouble(score) &lt; 34297.00)//大家这里根据具体情况设置可能ToInt32等等<br>            {<br>                GridView1.Rows<span style="font-style:italic"><wbr />.Cells[4].BackColor = System.Drawing.Color.Red;<br>            }<br>        }<br></span><wbr />        sqlcon.Close();</span><wbr /><br><span style="font-size:13px;line-height:1.8em;">全部后台代码：</span><wbr /><br>using System;<br>using System.Data;<br>using System.Configuration;<br>using System.Web;<br>using System.Web.Security;<br>using System.Web.UI;<br>using System.Web.UI.WebControls;<br>using System.Web.UI.WebControls.WebParts;<br>using System.Web.UI.HtmlControls;<br>using System.Data.SqlClient;<br>using System.Drawing;<br>public partial class Default7 : System.Web.UI.Page<br>{<br>    SqlConnection sqlcon;<br>    SqlCommand sqlcom;<br>    string strCon = &quot;Data Source=(local);Database=北风贸易;Uid=sa;Pwd=sa&quot;;<br>    protected void Page_Load(object sender, EventArgs e)<br>    {<br>        if (!IsPostBack)<br>        {<br>            bind();<br>        }<br>    }<br>    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)<br>    {<br>        GridView1.EditIndex = e.NewEditIndex;<br>        bind();<br>    }<br>    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)<br>    {<br>        sqlcon = new SqlConnection(strCon);<br>        string sqlstr = &quot;update 飞狐工作室 set 姓名='&quot;<br>            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + &quot;',家庭住址='&quot;<br>            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + &quot;' where 身份证号码='&quot;<br>            + GridView1.DataKeys[e.RowIndex].Value.ToString() + &quot;'&quot;;<br>        sqlcom = new SqlCommand(sqlstr, sqlcon);<br>        sqlcon.Open();<br>        sqlcom.ExecuteNonQuery();<br>        sqlcon.Close();<br>        GridView1.EditIndex = -1;<br>        bind();<br>    }<br>    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)<br>    {<br>        GridView1.EditIndex = -1;<br>        bind();<br>    }<br>    public void bind()<br>    {<br>        string sqlstr = &quot;select top 10 * from 飞狐工作室&quot;;<br>        sqlcon = new SqlConnection(strCon);<br>        SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);<br>        DataSet myds = new DataSet();<br>        sqlcon.Open();<br>        myda.Fill(myds, &quot;飞狐工作室&quot;);<br>        GridView1.DataSource = myds;<br>        GridView1.DataKeyNames = new string[] { &quot;身份证号码&quot; };<br>        GridView1.DataBind();<br>       <span style="color:#ff0000;line-height:1.8em;"> for (int i = 0; i &lt;= GridView1.Rows.Count - 1; i++)<br>        {<br>            DataRowView mydrv = myds.Tables[&quot;飞狐工作室&quot;].DefaultView<span style="font-style:italic"><wbr />;<br>            string score = Convert.ToString(mydrv[&quot;起薪&quot;]);<br>            if (Convert.ToDouble(score) &lt; 34297.00)<span style="font-size:13px;line-height:1.8em;">//大家这里根据具体情况设置可能ToInt32等等</span><wbr /><br><br>            {<br>                GridView1.Rows<span style="font-style:italic"><wbr />.Cells[4].BackColor = System.Drawing.Color.Red;<br>            }<br>        }<br></span><wbr />        sqlcon.Close();<br>    }<br>}<br><span style="font-weight:bold"><wbr />前台代码：</span><wbr /><br>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</span><wbr /></a><wbr />&quot;&gt;<br>&lt;html xmlns=&quot;<a href="http://www.w3.org/1999/xhtml" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://www.w3.org/1999/xhtml</span><wbr /></a><wbr />&quot; &gt;<br>&lt;head id=&quot;Head1&quot; runat=&quot;server&quot;&gt;<br>    &lt;title&gt;GridView突出显示某一单元格 清清月儿<a href="http://blog.csdn.net/21aspnet" target="_blank"><span style="color:#000000;line-height:1.8em;">http://blog.csdn.net/21aspnet</span><wbr /></a><wbr /> &lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body &gt;<br>    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;<br>    &lt;div  &gt;<br>                   &lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot;    AutoGenerateColumns=&quot;False&quot; CellPadding=&quot;3&quot;  OnRowEditing=&quot;GridView1_RowEditing&quot;<br>                        OnRowUpdating=&quot;GridView1_RowUpdating&quot; OnRowCancelingEdit=&quot;GridView1_RowCancelingEdit&quot; BackColor=&quot;White&quot; BorderColor=&quot;#CCCCCC&quot; BorderStyle=&quot;None&quot; BorderWidth=&quot;1px&quot; Font-Size=&quot;12px&quot;  &gt;<br>                        &lt;FooterStyle BackColor=&quot;White&quot; ForeColor=&quot;#000066&quot; /&gt;<br>                        &lt;Columns&gt;<br>                            &lt;asp:CommandField HeaderText=&quot;编辑&quot; ShowEditButton=&quot;True&quot; /&gt;<br>                            &lt;asp:BoundField DataField=&quot;身份证号码&quot; HeaderText=&quot;编号&quot; ReadOnly=&quot;True&quot; /&gt;<br>                            &lt;asp:BoundField DataField=&quot;姓名&quot; HeaderText=&quot;姓名&quot;  /&gt;<br>                            &lt;asp:BoundField DataField=&quot;出生日期&quot; HeaderText=&quot;邮政编码&quot;  /&gt;<br>                             &lt;asp:BoundField DataField=&quot;起薪&quot; HeaderText=&quot;起薪&quot;  DataFormatString=&quot;{0:C}&quot; HtmlEncode=&quot;false&quot;/&gt;<br>                            &lt;asp:BoundField DataField=&quot;家庭住址&quot; HeaderText=&quot;家庭住址&quot;  /&gt;<br>                            &lt;asp:BoundField DataField=&quot;邮政编码&quot; HeaderText=&quot;邮政编码&quot; /&gt;<br>                           <br>                        &lt;/Columns&gt;<br>                        &lt;RowStyle ForeColor=&quot;#000066&quot; /&gt;<br>                        &lt;SelectedRowStyle BackColor=&quot;#669999&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;<br>                        &lt;PagerStyle BackColor=&quot;White&quot; ForeColor=&quot;#000066&quot; HorizontalAlign=&quot;Left&quot;  CssClass=&quot;ms-formlabel DataGridFixedHeader&quot;/&gt;<br>                        &lt;HeaderStyle BackColor=&quot;#006699&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;<br>                    &lt;/asp:GridView&gt;<br>        &lt;/div&gt;<br>    &lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br> <!--v:3.2--> ]]></description>
<category><![CDATA[.Net帮助]]></category>
<author><![CDATA[344791576@qq.com(【廆●仼】)]]></author>
<comments>http://344791576.qzone.qq.com/blog/1240992099#comment</comments>
<qz:effect>134218241</qz:effect>
<pubDate>Wed, 29 Apr 2009 08:01:39 GMT</pubDate>
<guid>http://344791576.qzone.qq.com/blog/1240992099</guid>
</item>

<item>
<title><![CDATA[GridView合并表头多重表头无错完美版（以合并3列3行举例）]]></title>
<link>http://344791576.qzone.qq.com/blog/1240992048</link>
<description><![CDATA[<span style="font-weight:bold"><wbr /><span style="font-size:13px;line-height:1.8em;">GridView合并表头多重表头无错完美版（以合并3列3行举例）<br></span><wbr /></span><wbr /><span style="font-weight:bold"><wbr /><span style="font-size:13px;line-height:1.8em;">效果图：<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_gv25.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_gv25.gif" /></a><wbr /></span><wbr /></span><wbr /><br><span style="font-weight:bold"><wbr /><span style="font-size:13px;line-height:1.8em;"><br>后台代码：<br></span><wbr /></span><wbr />using System;<br>using System.Data;<br>using System.Configuration;<br>using System.Web;<br>using System.Web.Security;<br>using System.Web.UI;<br>using System.Web.UI.WebControls;<br>using System.Web.UI.WebControls.WebParts;<br>using System.Web.UI.HtmlControls;<br>using System.Data.SqlClient;<br>using System.Drawing;<br>public partial class _Default : System.Web.UI.Page <br>{<br>    SqlConnection sqlcon;<br>    SqlCommand sqlcom;<br>    string strCon = &quot;Data Source=(local);Database=北风贸易;Uid=sa;Pwd=sa&quot;;<br>    protected void Page_Load(object sender, EventArgs e)<br>    {<br>        if (!IsPostBack)<br>        {<br>            bind();<br>            <br>        }<br>    }<br>    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)<br>    {<br>        GridView1.EditIndex = e.NewEditIndex;<br>        bind();<br>    }<br>    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)<br>    {<br>        sqlcon = new SqlConnection(strCon);<br>        string sqlstr = &quot;update 飞狐工作室 set 姓名='&quot;<br>            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + &quot;',家庭住址='&quot;<br>            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + &quot;' where 身份证号码='&quot; <br>            + GridView1.DataKeys[e.RowIndex].Value.ToString() + &quot;'&quot;;<br>        sqlcom=new SqlCommand(sqlstr,sqlcon);<br>        sqlcon.Open();<br>        sqlcom.ExecuteNonQuery();<br>        sqlcon.Close();<br>        GridView1.EditIndex = -1;<br>        bind();<br>    }<br>    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)<br>    {<br>        GridView1.EditIndex = -1;<br>        bind();<br>    }<br>    public void bind()<br>    {<br>        string sqlstr = &quot;select top 10 * from 飞狐工作室&quot;;<br>        sqlcon = new SqlConnection(strCon);<br>        SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);<br>        DataSet myds = new DataSet();<br>        sqlcon.Open();<br>        myda.Fill(myds, &quot;飞狐工作室&quot;);<br>        GridView1.DataSource = myds;<br>        GridView1.DataKeyNames = new string[] { &quot;身份证号码&quot; };<br>        GridView1.DataBind();<br>        sqlcon.Close();<br>    }<br><span style="font-weight:bold"><wbr /><span style="color:#ff0000;line-height:1.8em;">//这里就是解决方案<br></span><wbr /></span><wbr />    <span style="color:#ff0000;line-height:1.8em;">protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)<br></span><wbr />    {<br>        switch (e.Row.RowType)<br>        {<br>            case DataControlRowType.Header:<br>                //第一行表头<br>                TableCellCollection tcHeader = e.Row.Cells;<br>                tcHeader.Clear();<br>                tcHeader.Add(new TableHeaderCell());<br>                tcHeader[0].Attributes.Add(&quot;rowspan&quot;, &quot;3&quot;); //跨Row<br>                tcHeader[0].Attributes.Add(&quot;bgcolor&quot;, &quot;white&quot;);<br>                tcHeader[0].Text = &quot;&quot;;<br>                tcHeader.Add(new TableHeaderCell());<br>                //tcHeader[1].Attributes.Add(&quot;bgcolor&quot;, &quot;Red&quot;);<br>                tcHeader[1].Attributes.Add(&quot;colspan&quot;, &quot;6&quot;); //跨Column<br>                tcHeader[1].Text = &quot;全部信息&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&quot;;<br>                //第二行表头<br>                tcHeader.Add(new TableHeaderCell());<br>                tcHeader[2].Attributes.Add(&quot;bgcolor&quot;, &quot;DarkSeaGreen&quot;);<br>                tcHeader[2].Text = &quot;身份证号码&quot;;<br>                tcHeader.Add(new TableHeaderCell());<br>                tcHeader[3].Attributes.Add(&quot;bgcolor&quot;, &quot;LightSteelBlue&quot;);<br>                tcHeader[3].Attributes.Add(&quot;colspan&quot;, &quot;2&quot;);<br>                tcHeader[3].Text = &quot;基本信息&quot;;<br>                tcHeader.Add(new TableHeaderCell());<br>                tcHeader[4].Attributes.Add(&quot;bgcolor&quot;, &quot;DarkSeaGreen&quot;);<br>                tcHeader[4].Text = &quot;福利&quot;;<br>                tcHeader.Add(new TableHeaderCell());<br>                tcHeader[5].Attributes.Add(&quot;bgcolor&quot;, &quot;LightSteelBlue&quot;);<br>                tcHeader[5].Attributes.Add(&quot;colspan&quot;, &quot;2&quot;);<br>                tcHeader[5].Text = &quot;联系方式&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&quot;;<br>                //第三行表头<br>                tcHeader.Add(new TableHeaderCell());<br>                tcHeader[6].Attributes.Add(&quot;bgcolor&quot;, &quot;Khaki&quot;);<br>                tcHeader[6].Text = &quot;身份证号码&quot;;<br>                tcHeader.Add(new TableHeaderCell());<br>                tcHeader[7].Attributes.Add(&quot;bgcolor&quot;, &quot;Khaki&quot;);<br>                tcHeader[7].Text = &quot;姓名&quot;;<br>                tcHeader.Add(new TableHeaderCell());<br>                tcHeader[8].Attributes.Add(&quot;bgcolor&quot;, &quot;Khaki&quot;);<br>                tcHeader[8].Text = &quot;出生日期&quot;;<br>                tcHeader.Add(new TableHeaderCell());<br>                tcHeader[9].Attributes.Add(&quot;bgcolor&quot;, &quot;Khaki&quot;);<br>                tcHeader[9].Text = &quot;薪水&quot;;<br>                tcHeader.Add(new TableHeaderCell());<br>                tcHeader[10].Attributes.Add(&quot;bgcolor&quot;, &quot;Khaki&quot;);<br>                tcHeader[10].Text = &quot;家庭住址&quot;;<br>                tcHeader.Add(new TableHeaderCell());<br>                tcHeader[11].Attributes.Add(&quot;bgcolor&quot;, &quot;Khaki&quot;);<br>                tcHeader[11].Text = &quot;邮政编码&quot;;<br>                break;<br>        }<br>    }<br>}<br><br>前台：<br>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</span><wbr /></a><wbr />&quot;&gt;<br>&lt;html xmlns=&quot;<a href="http://www.w3.org/1999/xhtml" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://www.w3.org/1999/xhtml</span><wbr /></a><wbr />&quot; &gt;<br>&lt;head runat=&quot;server&quot;&gt;<br>    &lt;title&gt;GridView合并多重表头表头 清清月儿<a href="http://blog.csdn.net/21aspnet" target="_blank"><span style="color:#000000;line-height:1.8em;">http://blog.csdn.net/21aspnet</span><wbr /></a><wbr /> &lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body &gt;<br>    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;<br>    &lt;div  &gt;<br>                   &lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot;    AutoGenerateColumns=&quot;False&quot; CellPadding=&quot;3&quot;  OnRowEditing=&quot;GridView1_RowEditing&quot;<br>                        OnRowUpdating=&quot;GridView1_RowUpdating&quot; OnRowCancelingEdit=&quot;GridView1_RowCancelingEdit&quot; BackColor=&quot;White&quot; BorderColor=&quot;#CCCCCC&quot; BorderStyle=&quot;None&quot; BorderWidth=&quot;1px&quot; Font-Size=&quot;12px&quot; OnRowCreated=&quot;GridView1_RowCreated&quot;  &gt;<br>                        &lt;FooterStyle BackColor=&quot;White&quot; ForeColor=&quot;#000066&quot; /&gt;<br>                        &lt;Columns&gt;<br>                            &lt;asp:CommandField HeaderText=&quot;编辑&quot; ShowEditButton=&quot;True&quot; /&gt;<br>                            &lt;asp:BoundField DataField=&quot;身份证号码&quot; HeaderText=&quot;编号&quot; ReadOnly=&quot;True&quot; /&gt;<br>                            &lt;asp:BoundField DataField=&quot;姓名&quot; HeaderText=&quot;姓名&quot;  /&gt;<br>                            &lt;asp:BoundField DataField=&quot;出生日期&quot; HeaderText=&quot;邮政编码&quot;  /&gt;<br>                             &lt;asp:BoundField DataField=&quot;起薪&quot; HeaderText=&quot;起薪&quot;  /&gt;<br>                            &lt;asp:BoundField DataField=&quot;家庭住址&quot; HeaderText=&quot;家庭住址&quot;  /&gt;<br>                            &lt;asp:BoundField DataField=&quot;邮政编码&quot; HeaderText=&quot;邮政编码&quot; /&gt;<br>                           <br>                        &lt;/Columns&gt;<br>                        &lt;RowStyle ForeColor=&quot;#000066&quot; /&gt;<br>                        &lt;SelectedRowStyle BackColor=&quot;#669999&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;<br>                        &lt;PagerStyle BackColor=&quot;White&quot; ForeColor=&quot;#000066&quot; HorizontalAlign=&quot;Left&quot;  CssClass=&quot;ms-formlabel DataGridFixedHeader&quot;/&gt;<br>                        &lt;HeaderStyle BackColor=&quot;#006699&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;<br>                    &lt;/asp:GridView&gt;<br>        &lt;/div&gt;<br>    &lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br><br> <!--v:3.2--> ]]></description>
<category><![CDATA[.Net帮助]]></category>
<author><![CDATA[344791576@qq.com(【廆●仼】)]]></author>
<comments>http://344791576.qzone.qq.com/blog/1240992048#comment</comments>
<qz:effect>134218241</qz:effect>
<pubDate>Wed, 29 Apr 2009 08:00:48 GMT</pubDate>
<guid>http://344791576.qzone.qq.com/blog/1240992048</guid>
</item>

<item>
<title><![CDATA[GridView固定表头(不用javascript只用CSS!，很好用)]]></title>
<link>http://344791576.qzone.qq.com/blog/1240991980</link>
<description><![CDATA[<span style="font-weight:bold"><wbr /><span style="font-size:13px;line-height:1.8em;">GridView固定表头(不用javascript只用CSS!，很好用)</span><wbr />：</span><wbr /><span style="font-weight:bold"><wbr />效果图：<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_gv24.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_gv24.gif" /></a><wbr /></span><wbr /><br><span style="font-weight:bold"><wbr />代码：<br></span><wbr />&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</span><wbr /></a><wbr />&quot;&gt;<br>&lt;html xmlns=&quot;<a href="http://www.w3.org/1999/xhtml" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://www.w3.org/1999/xhtml</span><wbr /></a><wbr />&quot; &gt;<br>&lt;head runat=&quot;server&quot;&gt;<br>    &lt;title&gt;GridView固定表头 清清月儿<a href="http://blog.csdn.net/21aspnet" target="_blank"><span style="color:#000000;line-height:1.8em;">http://blog.csdn.net/21aspnet</span><wbr /></a><wbr /> &lt;/title&gt;<br><span style="color:#ff0000;line-height:1.8em;">        &lt;style&gt; <br>.Freezing <br></span><wbr /><span style="color:#ff0000;line-height:1.8em;"><span style="font-weight:bold"><wbr />   { <br>    <br></span><wbr />   position:relative ; <br>   table-layout:fixed;<br>   top:expression(this.offsetParent.scrollTop);   <br>   z-index: 10;<br>   } </span><wbr /><br><span style="color:#ff0000;line-height:1.8em;">.Freezing th{text-overflow:ellipsis;overflow:hidden;white-space: nowrap;padding:2px;}<br>&lt;/style&gt; <br></span><wbr />&lt;/head&gt;<br>&lt;body style=&quot;font-size=12px&quot;&gt;<br>    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;<br>    &lt;div style=&quot;overflow-y: scroll; height: 200px;width:300px&quot; id=&quot;dvBody&quot;&gt;<br>                   &lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot;    AutoGenerateColumns=&quot;False&quot; CellPadding=&quot;3&quot; OnRowDeleting=&quot;GridView1_RowDeleting&quot; OnRowEditing=&quot;GridView1_RowEditing&quot;<br>                        OnRowUpdating=&quot;GridView1_RowUpdating&quot; OnRowCancelingEdit=&quot;GridView1_RowCancelingEdit&quot; BackColor=&quot;White&quot; BorderColor=&quot;#CCCCCC&quot; BorderStyle=&quot;None&quot; BorderWidth=&quot;1px&quot; Font-Size=&quot;12px&quot; OnRowCreated=&quot;GridView1_RowCreated&quot;  &gt;<br>                        &lt;FooterStyle BackColor=&quot;White&quot; ForeColor=&quot;#000066&quot; /&gt;<br>                        &lt;Columns&gt;<br>                            &lt;asp:BoundField DataField=&quot;身份证号码&quot; HeaderText=&quot;编号&quot; ReadOnly=&quot;True&quot; /&gt;<br>                            &lt;asp:BoundField DataField=&quot;邮政编码&quot; HeaderText=&quot;邮政编码&quot; SortExpression=&quot;邮政编码&quot; /&gt;<br>                            &lt;asp:BoundField DataField=&quot;家庭住址&quot; HeaderText=&quot;家庭住址&quot;  /&gt;<br>                            &lt;asp:BoundField DataField=&quot;姓名&quot; HeaderText=&quot;姓名&quot;  /&gt;<br>                            <br>                        &lt;/Columns&gt;<br>                        &lt;RowStyle ForeColor=&quot;#000066&quot; /&gt;<br>                        &lt;SelectedRowStyle BackColor=&quot;#669999&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;<br>                        &lt;PagerStyle BackColor=&quot;White&quot; ForeColor=&quot;#000066&quot; HorizontalAlign=&quot;Left&quot;  CssClass=&quot;ms-formlabel DataGridFixedHeader&quot;/&gt;<br>                        &lt;HeaderStyle BackColor=&quot;#006699&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; <span style="color:#ff0000;line-height:1.8em;">CssClass=&quot;Freezing&quot;</span><wbr /><span style="font-weight:bold"><wbr />/</span><wbr />&gt;<br>                    &lt;/asp:GridView&gt;<br>        &lt;/div&gt;<br>    &lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br>用法：CSS设如上的样式，HeaderStyle加<span style="color:#ff0000;line-height:1.8em;">CssClass=&quot;Freezing</span><wbr />，套住GridView的Div设置高度宽度 &lt;div style=&quot;overflow-y: scroll; height: 200px;width:200px&quot; &gt; <!--v:3.2--> ]]></description>
<category><![CDATA[.Net帮助]]></category>
<author><![CDATA[344791576@qq.com(【廆●仼】)]]></author>
<comments>http://344791576.qzone.qq.com/blog/1240991980#comment</comments>
<qz:effect>134218241</qz:effect>
<pubDate>Wed, 29 Apr 2009 07:59:40 GMT</pubDate>
<guid>http://344791576.qzone.qq.com/blog/1240991980</guid>
</item>

<item>
<title><![CDATA[GridView弹出新页面/弹出制定大小位置新窗口]]></title>
<link>http://344791576.qzone.qq.com/blog/1240991937</link>
<description><![CDATA[<span style="font-weight:bold"><wbr />GridView弹出新页面/弹出制定大小位置新窗口：</span><wbr /><span style="font-weight:bold"><wbr />效果图：<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_gv23.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_gv23.gif" /></a><wbr /></span><wbr /><br>方案一：简单的方法，新窗口不固定大小<br> &lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot; CellPadding=&quot;3&quot; OnRowDeleting=&quot;GridView1_RowDeleting&quot; OnRowEditing=&quot;GridView1_RowEditing&quot;<br>                        OnRowUpdating=&quot;GridView1_RowUpdating&quot; OnRowCancelingEdit=&quot;GridView1_RowCancelingEdit&quot; BackColor=&quot;White&quot; BorderColor=&quot;#CCCCCC&quot; BorderStyle=&quot;None&quot; BorderWidth=&quot;1px&quot; Font-Size=&quot;12px&quot;  &gt;<br>                        &lt;FooterStyle BackColor=&quot;White&quot; ForeColor=&quot;#000066&quot; /&gt;<br>                        &lt;Columns&gt;<br>                            &lt;asp:BoundField DataField=&quot;身份证号码&quot; HeaderText=&quot;编号&quot; ReadOnly=&quot;True&quot; /&gt;<br>                            &lt;asp:BoundField DataField=&quot;邮政编码&quot; HeaderText=&quot;邮政编码&quot; SortExpression=&quot;邮政编码&quot; /&gt;<br>                            &lt;asp:BoundField DataField=&quot;家庭住址&quot; HeaderText=&quot;家庭住址&quot;  /&gt;<br>                           <span style="font-weight:bold"><wbr /> &lt;asp:HyperLinkField HeaderText=&quot;姓名&quot; Text=&quot;姓名&quot; <span style="color:#ff0000;line-height:1.8em;">DataNavigateUrlFields</span><wbr />=&quot;姓名&quot; DataNavigateUrlFormatString=&quot;Default6.aspx?GoodsID={0}&quot; Target=&quot;mainframe&quot; NavigateUrl=&quot;~/Default6.aspx&quot; DataTextField=&quot;姓名&quot; &gt;<br>                    &lt;/asp:HyperLinkField&gt;<br></span><wbr />                            &lt;asp:CommandField HeaderText=&quot;选择&quot; ShowSelectButton=&quot;True&quot; /&gt;<br>                            &lt;asp:CommandField HeaderText=&quot;编辑&quot; ShowEditButton=&quot;True&quot; /&gt;<br>                            &lt;asp:CommandField HeaderText=&quot;删除&quot; ShowDeleteButton=&quot;True&quot; /&gt;<br>                        &lt;/Columns&gt;<br>                        &lt;RowStyle ForeColor=&quot;#000066&quot; /&gt;<br>                        &lt;SelectedRowStyle BackColor=&quot;#669999&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;<br>                        &lt;PagerStyle BackColor=&quot;White&quot; ForeColor=&quot;#000066&quot; HorizontalAlign=&quot;Left&quot; /&gt;<br>                        &lt;HeaderStyle BackColor=&quot;#006699&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;<br>                    &lt;/asp:GridView&gt;<br><span style="color:#ff0000;line-height:1.8em;">DataNavigateUrlFields</span><wbr />是链接的字段名，DataNavigateUrlFormatString是路径。<br>方案二：精确控制弹出窗口大小位置<br>&lt;asp:HyperLinkColumn DataNavigateUrlField=&quot;EmployeeID&quot; DataNavigateUrlFormatString=&quot;javascript:varwin=window.open('detail.aspx?ID={0}',null,'width=300,height=200');window.Close();&quot;<br>       DataTextField=&quot;LastName&quot; HeaderText=&quot;LastName&quot;&gt;&lt;/asp:HyperLinkColumn&gt;<br>使用的是结合javascript的window.open方法，关于window.open的参数网上有很多帖子，本站也有许多参考<br><span style="text-decoration:underline;"><wbr /><span style="color:#800080;line-height:1.8em;">弹出窗口大全</span><wbr /></span><wbr /> <a href="http://blog.csdn.net/21aspnet/archive/2004/10/25/150231.aspx" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://blog.csdn.net/21aspnet/archive/2004/10/25/150231.aspx</span><wbr /></a><wbr />   即可！ <!--v:3.2--> ]]></description>
<category><![CDATA[.Net帮助]]></category>
<author><![CDATA[344791576@qq.com(【廆●仼】)]]></author>
<comments>http://344791576.qzone.qq.com/blog/1240991937#comment</comments>
<qz:effect>134218241</qz:effect>
<pubDate>Wed, 29 Apr 2009 07:58:57 GMT</pubDate>
<guid>http://344791576.qzone.qq.com/blog/1240991937</guid>
</item>

<item>
<title><![CDATA[GridView显示隐藏某一列]]></title>
<link>http://344791576.qzone.qq.com/blog/1240991893</link>
<description><![CDATA[<span style="font-weight:bold"><wbr />GridView显示隐藏某一列：<br></span><wbr />本方案为<span style="font-weight:bold"><wbr />月儿</span><wbr /><span style="color:#ff0000;line-height:1.8em;">独创</span><wbr />，不同于网上其他方式，我觉得用一个<span style="font-weight:bold"><wbr />CheckBox更人性化</span><wbr />，这样可以隐藏不必要的列，让用户自己选择需要出现的列，在处理多列时这是一个很好的解决方案！<span style="font-weight:bold"><wbr />效果图：<br>图1-开始<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_gv22.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_gv22.gif" /></a><wbr /><br>图2-点击显示的CheckBox后<br><wbr /><a href="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_gv21.gif" target="_blank"><img style="border:0;" src="http://p.blog.csdn.net/images/p_blog_csdn_net/21aspnet/286353/o_gv21.gif" /></a><wbr /></span><wbr /><br><span style="font-weight:bold"><wbr />解决方案：<br></span><wbr />public void bind()<br>    {<br>        string sqlstr = &quot;select top 5 * from 飞狐工作室&quot;;<br>        sqlcon = new SqlConnection(strCon);<br>        SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);<br>        DataSet myds = new DataSet();<br>        sqlcon.Open();<br>        myda.Fill(myds, &quot;飞狐工作室&quot;);<br>        GridView1.DataSource = myds;<br>        GridView1.DataKeyNames = new string[] { &quot;身份证号码&quot; };<br>        GridView1.DataBind();<br>        sqlcon.Close();<br><span style="font-weight:bold"><wbr />        GridView1.Columns[3].Visible = false;//一开始隐藏<br>        CheckBox1.Checked = false;//如果不这样后面的代码会把他True</span><wbr /><br>    }<br>双击CheckBox1，在CheckedChanged方法里写上代码，最后代码如下：<br>protected void CheckBox1_CheckedChanged(object sender, EventArgs e)<br>    {<br>         GridView1.Columns[3].Visible=! GridView1.Columns[3].Visible;<br>         Response.Write(&quot;GridView1的第4列现在的显示隐藏状态是：&quot;+GridView1.Columns[3].Visible.ToString());<br>    }<br>注意：CheckBox1的<span style="color:#ff0000;line-height:1.8em;">AutoPostBack要True</span><wbr />！<br><span style="font-weight:bold"><wbr />后台全部代码如下：</span><wbr /><br>using System;<br>using System.Data;<br>using System.Configuration;<br>using System.Web;<br>using System.Web.Security;<br>using System.Web.UI;<br>using System.Web.UI.WebControls;<br>using System.Web.UI.WebControls.WebParts;<br>using System.Web.UI.HtmlControls;<br>using System.Data.SqlClient;<br>public partial class _Default : System.Web.UI.Page <br>{<br>    SqlConnection sqlcon;<br>    SqlCommand sqlcom; <br>    string strCon = &quot;Data Source=(local);Database=北风贸易;Uid=sa;Pwd=sa&quot;;<br>    protected void Page_Load(object sender, EventArgs e)<br>    {<br>        if (!IsPostBack)<br>        {<br>            ViewState[&quot;SortOrder&quot;] = &quot;身份证号码&quot;;<br>            ViewState[&quot;OrderDire&quot;] = &quot;ASC&quot;;<br>            bind();<br>        }<br>    }<br>    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)<br>    {<br>        GridView1.EditIndex = e.NewEditIndex;<br>        bind();<br>    }<br>    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)<br>    {<br>        string sqlstr = &quot;delete from 飞狐工作室 where 身份证号码='&quot; + GridView1.DataKeys[e.RowIndex].Value.ToString() + &quot;'&quot;;<br>        sqlcon = new SqlConnection(strCon);<br>        sqlcom = new SqlCommand(sqlstr,sqlcon);<br>        sqlcon.Open();<br>        sqlcom.ExecuteNonQuery();<br>        sqlcon.Close();<br>        bind();<br>    }<br>    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)<br>    {<br>        sqlcon = new SqlConnection(strCon);<br>        string sqlstr = &quot;update 飞狐工作室 set 姓名='&quot;<br>            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + &quot;',家庭住址='&quot;<br>            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + &quot;' where 身份证号码='&quot; <br>            + GridView1.DataKeys[e.RowIndex].Value.ToString() + &quot;'&quot;;<br>        sqlcom=new SqlCommand(sqlstr,sqlcon);<br>        sqlcon.Open();<br>        sqlcom.ExecuteNonQuery();<br>        sqlcon.Close();<br>        GridView1.EditIndex = -1;<br>        bind();<br>    }<br>    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)<br>    {<br>        GridView1.EditIndex = -1;<br>        bind();<br>    }<br>    public void bind()<br>    {<br>        string sqlstr = &quot;select top 5 * from 飞狐工作室&quot;;<br>        sqlcon = new SqlConnection(strCon);<br>        SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);<br>        DataSet myds = new DataSet();<br>        sqlcon.Open();<br>        myda.Fill(myds, &quot;飞狐工作室&quot;);<br>        GridView1.DataSource = myds;<br>        GridView1.DataKeyNames = new string[] { &quot;身份证号码&quot; };<br>        GridView1.DataBind();<br>        sqlcon.Close();<br>        GridView1.Columns[3].Visible = false;<br>        CheckBox1.Checked = false;<br>    }<br>    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)<br>    {<br>         GridView1.Columns[3].Visible=! GridView1.Columns[3].Visible;<br>         Response.Write(&quot;GridView1的第4列现在的显示隐藏状态是：&quot;+GridView1.Columns[3].Visible.ToString());<br>    }<br>}<br><br><span style="font-weight:bold"><wbr />前台代码：<br></span><wbr />&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</span><wbr /></a><wbr />&quot;&gt;<br>&lt;html xmlns=&quot;<a href="http://www.w3.org/1999/xhtml" target="_blank"><span style="color:#cc4c7f;line-height:1.8em;">http://www.w3.org/1999/xhtml</span><wbr /></a><wbr />&quot; &gt;<br>&lt;head runat=&quot;server&quot;&gt;<br>    &lt;title&gt;GridView显示隐藏列 清清月儿<a href="http://blog.csdn.net/21aspnet" target="_blank"><span style="color:#000000;line-height:1.8em;">http://blog.csdn.net/21aspnet</span><wbr /></a><wbr /> &lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body style=&quot;font-size=12px&quot;&gt;<br>    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;<br>    &lt;div&gt;<br>                   &lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot; CellPadding=&quot;3&quot; OnRowDeleting=&quot;GridView1_RowDeleting&quot; OnRowEditing=&quot;GridView1_RowEditing&quot;<br>                        OnRowUpdating=&quot;GridView1_RowUpdating&quot; OnRowCancelingEdit=&quot;GridView1_RowCancelingEdit&quot; BackColor=&quot;White&quot; BorderColor=&quot;#CCCCCC&quot; BorderStyle=&quot;None&quot; BorderWidth=&quot;1px&quot; Font-Size=&quot;12px&quot;  &gt;<br>                        &lt;FooterStyle BackColor=&quot;White&quot; ForeColor=&quot;#000066&quot; /&gt;<br>                        &lt;Columns&gt;<br>                            &lt;asp:BoundField DataField=&quot;身份证号码&quot; HeaderText=&quot;编号&quot; ReadOnly=&quot;True&quot; /&gt;<br>                            &lt;asp:BoundField DataField=&quot;姓名&quot; HeaderText=&quot;用户姓名&quot; /&gt;<br>                            &lt;asp:BoundField DataField=&quot;邮政编码&quot; HeaderText=&quot;邮政编码&quot; SortExpression=&quot;邮政编码&quot; /&gt;<br>                            &lt;asp:BoundField DataField=&quot;家庭住址&quot; HeaderText=&quot;家庭住址&quot;  /&gt;<br>                            &lt;asp:CommandField HeaderText=&quot;选择&quot; ShowSelectButton=&quot;True&quot; /&gt;<br>                            &lt;asp:CommandField HeaderText=&quot;编辑&quot; ShowEditButton=&quot;True&quot; /&gt;<br>                            &lt;asp:CommandField HeaderText=&quot;删除&quot; ShowDeleteButton=&quot;True&quot; /&gt;<br>                        &lt;/Columns&gt;<br>                        &lt;RowStyle ForeColor=&quot;#000066&quot; /&gt;<br>                        &lt;SelectedRowStyle BackColor=&quot;#669999&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;<br>                        &lt;PagerStyle BackColor=&quot;White&quot; ForeColor=&quot;#000066&quot; HorizontalAlign=&quot;Left&quot; /&gt;<br>                        &lt;HeaderStyle BackColor=&quot;#006699&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;<br>                    &lt;/asp:GridView&gt;<br>        &lt;asp:CheckBox ID=&quot;CheckBox1&quot; runat=&quot;server&quot; AutoPostBack=&quot;True&quot; Font-Size=&quot;12px&quot;<br>            OnCheckedChanged=&quot;CheckBox1_CheckedChanged&quot; Text=&quot;显示隐藏家庭住址&quot; /&gt;&lt;/div&gt;<br>    &lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt; <!--v:3.2--> ]]></description>
<category><![CDATA[.Net帮助]]></category>
<author><![CDATA[344791576@qq.com(【廆●仼】)]]></author>
<comments>http://344791576.qzone.qq.com/blog/1240991893#comment</comments>
<qz:effect>134218241</qz:effect>
<pubDate>Wed, 29 Apr 2009 07:58:13 GMT</pubDate>
<guid>http://344791576.qzone.qq.com/blog/1240991893</guid>
</item>

</channel>
</rss>

