日期:2013-09-26  浏览次数:21140 次

1.判断权限部分的代码

int i=Convert.ToInt32((string)Session["user_flag"]);

switch(i)

{//根据权限执行不同的sql语句

case 0://管理员

e.Item.Cells[9].Visible=false;

break;

case 1://厅领导

e.Item.Cells[6].Visible=false;

e.Item.Cells[7].Visible=false;

e.Item.Cells[8].Visible=false;

e.Item.Cells[9].Visible=false;

break;

case 2://省律师协会

e.Item.Cells[8].Visible=false;

break;

case 3://省律师处

e.Item.Cells[8].Visible=false;

break;

case 4://市律师协会

e.Item.Cells[8].Visible=false;

break;

case 5://市律师处

e.Item.Cells[8].Visible=false;

break;

case 6://省直律师事务所

e.Item.Cells[8].Visible=false;

break;

}

2.根据linkbutton来动态显示或者隐藏某些控件

private void LinkButton2_Click(object sender, System.EventArgs e)

{

LinkButton lb=(LinkButton)sender;

Panel1.Visible=lb.CommandName=="yes";

lb.CommandName=(lb.CommandName=="no")?"yes":"no";

}

3.设置标题列的背景颜色

private void dg1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)

{

if(e.Item.ItemType==ListItemType.Header)

{//设置标题列的背景颜色

for(int j=0;j<e.Item.Cells.Count;j++)

{

//e.Item.Cells[j].BackColor=Color.FromName("#ffff66");

e.Item.Cells[j].CssClass="title";

}

}

}

4.本程序所用样式表

body

{

font-size:12px;

}

table{

border-collapse:collapse;

border: 1px solid #28ACE2;

word-wrap:break-word;

}td {

border: 1px solid #28ACE2;

background-color: #E7F8FF;

font-size: 12px;

}

a {

color: #003399;

text-decoration: none;

}

a:hover {

color: #003366;

}

.title

{

background-color:#ffff66;

}

5.多条件高级查询

void bindgrid(string word1,string word2)

{

SqlConnection myconn=oa.cls.globalstate.GetConnection();

string sql=@"select * from [suo] where ([id] is not null)";//因为id是主键,所以不可能为null,这是个小技巧

if(Convert.ToInt32((string)Session["user_flag"])==0)

{//如果是管理员就只能看到已经提交的信息

sql=@"select * from [suo] where [is]<>0";

}

if(word1!=""){sql+=" and ([name] like '%"+word1+"%')";}//加一个判断条件,注意语句开头有一个空格

if(word2!=""){sql+=" and ([zhiye] like '%"+word2+"%')";}//加一个判断条件,注意语句开头有一个空格

sql+=" order by id desc";

Response.Write(sql);

SqlDataAdapter da=new SqlDataAdapter(sql,myconn);

DataSet ds=new DataSet()