posts - 66,comments - 41,trackbacks - 0
          C#代碼
          1. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)  
          2.     {  
          3.         // 設(shè)置行的背景顏色  
          4.         if (e.Row.Cells[1].Text == "0111")  
          5.         {  
          6.             e.Row.BackColor = System.Drawing.Color.Red;  
          7.         }  
          8.         else  
          9.         {  
          10.             e.Row.BackColor = System.Drawing.Color.Gray;  
          11.         }  
          12.         // 設(shè)置單元格的顏色  
          13.         if (e.Row.Cells[1].Text == "0111")  
          14.         {  
          15.             e.Row.Cells[1].BackColor = System.Drawing.Color.Green;  
          16.         }  
          17.       }
          18.  
          19.  
          20.  
            C#代碼
            1. 21. //其實不一定用上面的方面,以下為我的實際應(yīng)用  
            2. 22. public void bind()  
            3.         {  
            4.             string sqlstr = "select a.id,b.department,b.name,c.pname,a.wrktime_start,a.wrktime_end,a.check_time,a.Confirmed_add_time,(select CODE_VALUES from jsboth_hrms_codes where code_num=a.add_type and code_type='WOT_TYPE') as add_type,a.add_apply_sid,a.absense_late,a.absense_early,a.absense_time,(select CODE_VALUES from jsboth_hrms_codes where code_num=a.absense_type and code_type='vocation') as absense_type,a.ABSENSE_SID,a.remarks,pm_checked from jsboth_hrms_dailycheck a,jsboth_hrms_baseinfo b,jsboth_hrms_projectinfo c where a.emp_id=b.id and a.project_id=c.id";  
            5.             using (SqlConnection conn = new SqlConnection(strCon))  
            6.             {  
            7.                 conn.Open();  
            8.                 SqlDataAdapter myda = new SqlDataAdapter(sqlstr, conn);  
            9.                 DataSet myds = new DataSet();  
            10.                 DropDownList ddlAddType;  
            11.                 DropDownList ddlAbsenseType;  
            12.   
            13.                 //myda.Fill(myds,"JSBOTH_HRMS_DAILYCHECK");  
            14.                 myda.Fill(myds, "jsboth_hrms_dailycheck");  
            15.                 GridView1.DataSource = myds;  
            16.                 GridView1.DataKeyNames = new string[] { "id" };//主鍵  
            17.                 GridView1.DataBind();  
            18.   
            19.                 //GridView1.Rows[k].Cells[19].Visible = false;  
            20.   
            21.                 string sqlGetAllDailyData = "select * from jsboth_hrms_dailycheck";  
            22.                 SqlDataAdapter getAllDailyDataDa = new SqlDataAdapter(sqlGetAllDailyData, conn);  
            23.                 DataTable allDailyDt = new DataTable();  
            24.                 getAllDailyDataDa.Fill(allDailyDt);  
            25.   
            26.                 for (int i = 0; i < GridView1.Rows.Count; i++)  
            27.                 {  
            28.                     DataRowView dailyCheckRow = myds.Tables["jsboth_hrms_dailycheck"].DefaultView[i];  
            29.   
            30.                     //Response.Write("ADD_TYPE=" + dailyCheckRow["ADD_TYPE"].ToString());  
            31.   
            32.                    
            33.                     if (Convert.ToString(dailyCheckRow["PM_CHECKED"]) == "0") {  
            34.                      
            35.                     //GridView1.Rows[i].Cells[3].  
            36.                         GridView1.Rows[i].Cells[3].BackColor = System.Drawing.Color.Red;  
            37.                     }  
            38.   
            39.   
            40.                     if ((GridView1.Rows[i].RowState & DataControlRowState.Edit) == DataControlRowState.Edit)  
            41.                     {  
            42.                     if (Convert.ToString(dailyCheckRow["ADD_TYPE"]) == "普通")  
            43.                     {  
            44.                         //Response.Write("000000000000000000000");  
            45.                         ddlAddType = (DropDownList)GridView1.Rows[i].FindControl("gvEditDDLAddType");  
            46.                         ddlAddType.SelectedIndex = 0;  
            47.                     }  
            48.                     if (Convert.ToString(dailyCheckRow["ADD_TYPE"]) == "節(jié)假日")  
            49.                     {  
            50.                         ddlAddType = (DropDownList)GridView1.Rows[i].FindControl("gvEditDDLAddType");  
            51.                         ddlAddType.SelectedIndex = 1;  
            52.                     }  
            53.   
            54.                     //FOR GRIDVIEW DDLABSENSETYPE  
            55.                     if (string.IsNullOrEmpty(Convert.ToString(dailyCheckRow["ABSENSE_TYPE"])))  
            56.                     {  
            57.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvEditDDLAbsenseType");  
            58.                         ddlAbsenseType.SelectedIndex = 0;  
            59.   
            60.                     }  
            61.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "病假")  
            62.                     {  
            63.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvEditDDLAbsenseType");  
            64.                         ddlAbsenseType.SelectedIndex = 1;  
            65.                     }  
            66.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "事假")  
            67.                     {  
            68.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvEditDDLAbsenseType");  
            69.                         ddlAbsenseType.SelectedIndex = 2;  
            70.                     }  
            71.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "調(diào)休")  
            72.                     {  
            73.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvEditDDLAbsenseType");  
            74.                         ddlAbsenseType.SelectedIndex = 3;  
            75.                     }  
            76.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "婚假")  
            77.                     {  
            78.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvEditDDLAbsenseType");  
            79.                         ddlAbsenseType.SelectedIndex = 4;  
            80.                     }  
            81.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "喪假")  
            82.                     {  
            83.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvEditDDLAbsenseType");  
            84.                         ddlAbsenseType.SelectedIndex = 5;  
            85.                     }  
            86.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "產(chǎn)假")  
            87.                     {  
            88.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvEditDDLAbsenseType");  
            89.                         ddlAbsenseType.SelectedIndex = 6;  
            90.                     }  
            91.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "探親假")  
            92.                     {  
            93.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvEditDDLAbsenseType");  
            94.                         ddlAbsenseType.SelectedIndex = 7;  
            95.                     }  
            96.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "帶薪假")  
            97.                     {  
            98.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvEditDDLAbsenseType");  
            99.                         ddlAbsenseType.SelectedIndex = 8;  
            100.                     }  
            101.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "年假")  
            102.                     {  
            103.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvEditDDLAbsenseType");  
            104.                         ddlAbsenseType.SelectedIndex = 9;  
            105.                     }  
            106.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "公差")  
            107.                     {  
            108.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvEditDDLAbsenseType");  
            109.                         ddlAbsenseType.SelectedIndex = 10;  
            110.                     }  
            111.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "路途")  
            112.                     {  
            113.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvEditDDLAbsenseType");  
            114.                         ddlAbsenseType.SelectedIndex = 11;  
            115.                     }  
            116.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "曠工")  
            117.                     {  
            118.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvEditDDLAbsenseType");  
            119.                         ddlAbsenseType.SelectedIndex = 12;  
            120.                     }  
            121.                 }  
            122.                 else {  
            123.                     if (Convert.ToString(dailyCheckRow["ADD_TYPE"]) == "普通")  
            124.                     {  
            125.                         //Response.Write("000000000000000000000");  
            126.                         ddlAddType = (DropDownList)GridView1.Rows[i].FindControl("gvDDLAddType");  
            127.                         ddlAddType.SelectedIndex = 0;  
            128.                     }  
            129.                     if (Convert.ToString(dailyCheckRow["ADD_TYPE"]) == "節(jié)假日")  
            130.                     {  
            131.                         ddlAddType = (DropDownList)GridView1.Rows[i].FindControl("gvDDLAddType");  
            132.                         ddlAddType.SelectedIndex = 1;  
            133.                     }  
            134.   
            135.                     //FOR GRIDVIEW DDLABSENSETYPE  
            136.                     if (string.IsNullOrEmpty(Convert.ToString(dailyCheckRow["ABSENSE_TYPE"])))  
            137.                     {  
            138.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvDDLAbsenseType");  
            139.                         ddlAbsenseType.SelectedIndex = 0;  
            140.   
            141.                     }  
            142.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "病假")  
            143.                     {  
            144.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvDDLAbsenseType");  
            145.                         ddlAbsenseType.SelectedIndex = 1;  
            146.                     }  
            147.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "事假")  
            148.                     {  
            149.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvDDLAbsenseType");  
            150.                         ddlAbsenseType.SelectedIndex = 2;  
            151.                     }  
            152.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "調(diào)休")  
            153.                     {  
            154.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvDDLAbsenseType");  
            155.                         ddlAbsenseType.SelectedIndex = 3;  
            156.                     }  
            157.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "婚假")  
            158.                     {  
            159.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvDDLAbsenseType");  
            160.                         ddlAbsenseType.SelectedIndex = 4;  
            161.                     }  
            162.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "喪假")  
            163.                     {  
            164.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvDDLAbsenseType");  
            165.                         ddlAbsenseType.SelectedIndex = 5;  
            166.                     }  
            167.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "產(chǎn)假")  
            168.                     {  
            169.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvDDLAbsenseType");  
            170.                         ddlAbsenseType.SelectedIndex = 6;  
            171.                     }  
            172.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "探親假")  
            173.                     {  
            174.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvDDLAbsenseType");  
            175.                         ddlAbsenseType.SelectedIndex = 7;  
            176.                     }  
            177.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "帶薪假")  
            178.                     {  
            179.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvDDLAbsenseType");  
            180.                         ddlAbsenseType.SelectedIndex = 8;  
            181.                     }  
            182.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "年假")  
            183.                     {  
            184.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvDDLAbsenseType");  
            185.                         ddlAbsenseType.SelectedIndex = 9;  
            186.                     }  
            187.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "公差")  
            188.                     {  
            189.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvDDLAbsenseType");  
            190.                         ddlAbsenseType.SelectedIndex = 10;  
            191.                     }  
            192.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "路途")  
            193.                     {  
            194.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvDDLAbsenseType");  
            195.                         ddlAbsenseType.SelectedIndex = 11;  
            196.                     }  
            197.                     if (Convert.ToString(dailyCheckRow["ABSENSE_TYPE"]) == "曠工")  
            198.                     {  
            199.                         ddlAbsenseType = (DropDownList)GridView1.Rows[i].FindControl("gvDDLAbsenseType");  
            200.                         ddlAbsenseType.SelectedIndex = 12;  
            201.                     }  
            202.                      
            203.                     }  
            204.                 }  
            205.             }  
            206.   
            207.         }  

          文章來源:http://www.my1984.net/?action=show&id=113

          MSN:
          posted on 2008-07-22 23:57 kylixlu 閱讀(2657) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 安化县| 广东省| 德钦县| 蓝山县| 上高县| 从江县| 沈阳市| 南昌市| 日土县| 曲周县| 措美县| 溧水县| 晋城| 建德市| 来安县| 莲花县| 同江市| 霍邱县| 肥乡县| 江达县| 沙湾县| 监利县| 肇州县| 油尖旺区| 育儿| 县级市| 金溪县| 景宁| 辰溪县| 维西| 商丘市| 彭水| 昌邑市| 云南省| 邢台县| 宁化县| 平江县| 中江县| 汉阴县| 金川县| 甘肃省|