来自Asp.net精英论坛:bbs.1aspx.com
using System.Web;
using System.Drawing;
namespace ArgumentsTest
{
/// <summary>
/// RefImage 的摘要说明。
/// </summary>
public class RefImage :IHttpHandler
{
#region IHttpHandler 成员
public void ProcessRequest(HttpContext context)
{
if(context.Request.Url.ToString().ToLower().IndexOf("localhost") <= 0 )
{
context.Response.Clear();
context.Response.WriteFile(@"C:/Inetpub/wwwroot/ArgumentsTest/images/error.gif");
return;
}
context.Response.WriteFile(context.Request.RawUrl);
}
public bool IsReusable
{
get
{
// TODO: 添加 RefImage.IsReusable getter 实现
return false;
}
}
#endregion
}
}
<system.web>
<httpHandlers >
<add verb="*"
path="*.gif"
type="ArgumentsTest.RefImage,ArgumentsTest"/>
</httpHandlers>
11111 | 1 | 22222 | 2 |
333333 | 3 | 444444 | 4 |
555555 | 5 | 666666 | 6 |
777777 | 7 | 888888 | 8 |
9999 | 9 | 10000 | 10 |
11 | 11 | 12 | 12 |
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Set();
}
void Set()
{
HtmlTableRow[] rows = new HtmlTableRow[]{cell1,cell2,cell3,cell4,cell5,cell6};
//显示或是隐藏行
for(int i=1;i<7;i++)
{
Label l1 =(Label) Page.FindControl("lblCustomColumn"+(2*i-1).ToString()) ;
Label l2 =(Label) Page.FindControl("lblCustomColumn"+(2*i).ToString()) ;
rows[i-1].Visible = l1.Visible||l2.Visible;
if(rows[i-1].Visible&& l1.Visible!=l2.Visible&&l2.Visible)
{
HtmlTableCell temp1;
HtmlTableCell temp2;
temp1 = rows[i-1].Cells[2];
temp2 = rows[i-1].Cells[3];
rows[i-1].Cells.RemoveAt(2);
rows[i-1].Cells.RemoveAt(2);
rows[i-1].Cells.Insert(0,temp2);
rows[i-1].Cells.Insert(0,temp1);
}
}
//*将只有一列显示的的上移
for(int i=0;i<6;i++)
{
if(!rows[i].Visible)continue;
Label l1 = rows[i].Cells[0].Controls[0] as Label;
Label l2 = rows[i].Cells[2].Controls[0] as Label;
if(l2.Visible==l1.Visible)continue;
int j = i+1 ;
bool change = false;
do
{
if(j >5 )
{
break;
}
if(!rows[j].Visible)
{
j++;
continue;
}
Label l3 = rows[j].Cells[0].Controls[0] as Label;
Label l4 = rows[j].Cells[2].Controls[0] as Label;
if(l3.Visible == l4.Visible)
{
j++;
continue;
}
TextBox t3 = rows[j].Cells[1].Controls[0] as TextBox;
rows[i].Cells[2].Controls.Add(l3);
rows[i].Cells[3].Controls.Add(t3);
rows[j].Visible = false;
Response.Write( i.ToString() + "与"+j.ToString()+"交换位置 <br>" );
change = true;
}while(!change);
}
}