比较乱的整理

  1. Gridview的RowCommand事件。

    protected void GridViewNonReviewLogView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        
for(int i=0;i<GridViewNonReviewLogView.Rows.Count;i++)
        {
            
//控制选中行的背景色,先做前景色和背景色的初始化。
            if (i % 2 == 0)
            {
                GridViewNonReviewLogView.Rows[i].BackColor 
= System.Drawing.Color.White;
            }
            
else 
            {
                GridViewNonReviewLogView.Rows[i].BackColor 
= System.Drawing.ColorTranslator.FromHtml("#E7E7E7");//从16进制颜色字符串转化为GDI+颜色值            
            }
            
if (GridViewNonReviewLogView.Rows[i].Cells[6].Text == "Fail")
            {
                GridViewNonReviewLogView.Rows[i].ForeColor 
= System.Drawing.Color.OrangeRed;
            }
            
else
                GridViewNonReviewLogView.Rows[i].ForeColor 
= System.Drawing.Color.Black;
        }
        
        
if (e.CommandName == "UpdateInfo")
        {
            GridViewRow row 
= (GridViewRow)((Control)e.CommandSource).Parent.Parent;//取得触发命令的当前行,Source为触发命令按钮,父控件为Gridview的Cell,再父
             //控件为GridViewRow

              row.BackColor = System.Drawing.Color.SkyBlue;
            
int logId = Convert.ToInt32(e.CommandArgument);
            
this.BindInitCategory(logId);
            
this.HiddenAddOrUpdate.Value = "1";
            
this.HiddenGetID.Value = logId.ToString();
            
this.ExpandInfoVisible();
        }
        
if (e.CommandName == "DeleteInfo"
        {
            
int logId = Convert.ToInt32(e.CommandArgument);
            
this.DeleteCategory(logId);
            
this.BindGridViewNonReviewLogView();
        }
    }

2.  JavaScript中取到下拉选项的值.
        var objSelect = window.document.getElementById("DropDownListDate");
        var year = objSelect.options[objSelect.selectedIndex].value;
3.  去掉页面缓存,<%@ OutputCache Location="none" VaryByParam="none" Duration="1" %>。
3.  模态窗口中,控制链接不重新打开新窗口。<base target="_self" />加到Head中。
4.  获取一目录下的所有文件名,并将文件名绑定到DropDownList中。

/// <summary>
/// 绑定模板选择下拉列表函数
/// </summary>
/// <param name="templatePath">模板文件所在路径</param>
 private void BindDropDownTemplate(string templatePath)
    {
        
string path = string.Empty;
        
if (templatePath.Substring(templatePath.Length - 11== @"\")
        {
            path 
= templatePath;
        }
        
else
        {
            path 
= templatePath + "\\";
        }
        
string[] templateName = Directory.GetFiles(path);
        
for (int i = 0; i < templateName.Length; i++)
        {
            
if (templateName[i].Substring(templateName[i].Length - 44== ".xls")
            {
                
string tempFileName = templateName[i].Substring(path.Length , templateName[i].Length - path.Length);
                ListItem item 
= new ListItem( tempFileName);
                
this.DropDownListTemplate.Items.Add(item);
            }
        }
    }

5.  GridView的OnRowDataBound事件(做AD信息读取的时候要计算Duration,下面的不是DropDownListADInfo,是GridviewADInfo,保持前台调用名与之一致就OK)

/// <summary>
/// 绑定Gridview时进行计算得到Duration字段
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void DropDownListADInfo_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
        
if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DataRowView dv 
= (DataRowView)e.Row.DataItem;
            
if (dv != null)
            {
                DateTime now 
= DateTime.Parse(DateTime.Now.ToShortDateString());
                DateTime modifyDate 
= DateTime.Parse(DateTime.Parse(dv["ADInfo_LastModifyTime"].ToString()).ToShortDateString());
                TimeSpan ts 
= now.Subtract(modifyDate);
                
string duration = ts.TotalDays.ToString();
                System.Web.UI.WebControls.Label label 
= (System.Web.UI.WebControls.Label)e.Row.FindControl("du");
                label.Text 
= duration;
            }
            
if ((e.Row.DataItem as DataRowView)["ADInfo_State"].ToString() == "4")
            {
                System.Web.UI.WebControls.Image stateImage 
= (System.Web.UI.WebControls.Image)e.Row.FindControl("ADState");
                stateImage.ImageUrl 
= @"../Images/disable_1.jpg";
            }
        }
    }
6.  AD登陆验证。
 protected void ButtonLogin_Click(object sender, EventArgs e)
    {
        
if (this.txtUserName.Text != "" && this.txtPWD.Text != "")
        {
            
string strLDAP = ConfigurationManager.AppSettings["LDAP"].ToString();
            
string userName = this.txtUserName.Text.Trim();
            
string passWord = this.txtPWD.Text.Trim();
            
try
            {
                DirectoryEntry de 
= new DirectoryEntry(strLDAP, userName, passWord);
                DirectorySearcher ds 
= new DirectorySearcher(de);
                SearchResult sr 
= ds.FindOne();

                Response.Write(
"<script>alert('Login Success !');</script>");
                
this.hiddenUName.Value = userName;
                
this.hiddenPWD.Value = passWord;
                
this.Login.Visible = false;
                
this.SetLabelUser();
            }
            
catch (Exception ex)
            {
                Response.Write(
"" + strLDAP + "<br />" + ex.Message.ToString());
                
//throw new Exception(string.Format("Can't visit specifid active directory: {0} .Plz make sure that you have input the right UserName and PWD!", strLDAP));
                return;
            }
        }
        
else
        {
            Response.Write(
"<script>alert('Please input your UserName and Password !');</script>");
            
return;
        }
    }
以后陆续添加。
posted on 2008-09-26 17:31  Jinspet  阅读(238)  评论(0编辑  收藏  举报