Click here to Skip to main content
15,891,864 members
Home / Discussions / C#
   

C#

 
GeneralRe: Trying to make a DataGridView field a color if a condition is met. Pin
Norris Chappell22-May-15 11:36
Norris Chappell22-May-15 11:36 
GeneralRe: Trying to make a DataGridView field a color if a condition is met. Pin
Mathi Mani22-May-15 11:46
Mathi Mani22-May-15 11:46 
GeneralRe: Trying to make a DataGridView field a color if a condition is met. Pin
Norris Chappell22-May-15 12:01
Norris Chappell22-May-15 12:01 
AnswerRe: Trying to make a DataGridView field a color if a condition is met. Pin
Mathi Mani22-May-15 12:20
Mathi Mani22-May-15 12:20 
GeneralRe: Trying to make a DataGridView field a color if a condition is met. Pin
Norris Chappell22-May-15 12:25
Norris Chappell22-May-15 12:25 
GeneralRe: Trying to make a DataGridView field a color if a condition is met. Pin
Norris Chappell22-May-15 12:47
Norris Chappell22-May-15 12:47 
GeneralRe: Trying to make a DataGridView field a color if a condition is met. Pin
Mathi Mani22-May-15 12:49
Mathi Mani22-May-15 12:49 
GeneralRe: Trying to make a DataGridView field a color if a condition is met. Pin
Norris Chappell22-May-15 12:52
Norris Chappell22-May-15 12:52 
Not the whole row only that field. ActualFTE.

C#
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Drawing;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace StaffingWebParts.CatwComment
{
    public partial class CatwCommentUserControl : UserControl
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLStaffingConn"].ConnectionString);
        SqlCommand cmd = new SqlCommand();
                
        protected void Page_Load(object sender, EventArgs e)
        {
            lblMsg.Text = "";
            if (!Page.IsPostBack)
            {
                BindSubjectData();
            }
        }
        protected void highlightrow(object sender, GridViewRowEventArgs e)
        {
           if (e.Row.RowType == DataControlRowType.DataRow)
           {
             decimal ActualFTE = Convert.ToDecimal(e.Row.Cells[5].Text.ToString());
               
             if (ActualFTE > 1.2500M)
               {
                  e.Row.BackColor = Color.Red;
                }
            }
        }
        //call to bind gridview
        protected void BindSubjectData()
        {
            using (SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLStaffingConn"].ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandText = ("select a.id, b.StaffTrackingID, a.ResourceName, b. EstimateHours, EstimateFTE, b.ActualHours, b.ActualFTE,b.Comment, b.CommentBy, b.Period  from  StaffTracking a, StaffTrackingFTEData b where a.id = b.StaffTrackingid  order by ResourceName");
                    cmd.Connection = sqlCon;
                    sqlCon.Open();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataTable dt = new DataTable();
                                   
                    da.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        gvCATW.DataSource = dt;
                        gvCATW.DataBind();
                    }
                    else
                    {
                        DataRow dr = dt.NewRow();
                        dt.Rows.Add(dr);
                        gvCATW.DataSource = dt;
                        gvCATW.DataBind();
                        gvCATW.Rows[0].Visible = false;
                    }
                    sqlCon.Close();
                }
            }
        }
        //called on row edit command
        protected void gvCATW_RowEditing(object sender, GridViewEditEventArgs e)
        {
            gvCATW.EditIndex = e.NewEditIndex;
            BindSubjectData();
        }

        //called when cancel edit mode
        protected void gvCATW_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gvCATW.EditIndex = -1;
            BindSubjectData();
        }

        //called on row update command
        protected void gvCATW_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            bool IsUpdated = false;
            //getting key value, row id
            int StaffTrackingID =
            Convert.ToInt32(gvCATW.DataKeys[e.RowIndex].Value.ToString());
            //getting row field details
            TextBox ResourceName =
            (TextBox)gvCATW.Rows[e.RowIndex].FindControl("txtResourceName");
            TextBox EstimateHours = (TextBox)gvCATW.Rows[e.RowIndex].FindControl("txtEstimateHours");
            TextBox EstimateFTE = (TextBox)gvCATW.Rows[e.RowIndex].FindControl("txtEstimateFTE");
            TextBox ActualHours = (TextBox)gvCATW.Rows[e.RowIndex].FindControl("txtActualHours");
            TextBox ActualFTE = (TextBox)gvCATW.Rows[e.RowIndex].FindControl("txtActualFTE");
            TextBox Comment = (TextBox)gvCATW.Rows[e.RowIndex].FindControl("txtComment");
            TextBox CommentBy = (TextBox)gvCATW.Rows[e.RowIndex].FindControl("txtCommentBy");
            TextBox Period =  (TextBox)gvCATW.Rows[e.RowIndex].FindControl("txtPeriod");
                 

            //   TextBox Grade = (TextBox)gvSubDetails.Rows[e.RowIndex].FindControl("txtGrade");
            using (SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLStaffingConn"].ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                   
                    //here i'd added "@" for continuous string in new line
                    cmd.CommandText = @"UPDATE StaffTrackingFTEData SET StaffTrackingID=@StaffTrackingID, EstimateHours=@EstimateHours, EstimateFTE=@EstimateFTE, ActualHours=@ActualHours, ActualFTE=@ActualFTE,Comment=@Comment, CommentBy=@CommentBy, period=@Period WHERE StaffTrackingID=@StaffTrackingID";
                    cmd.Parameters.AddWithValue("@StaffTrackingId", StaffTrackingID);
                    cmd.Parameters.AddWithValue("@EstimateHours", EstimateHours.Text);
                    cmd.Parameters.AddWithValue("@EstimateFTE", EstimateFTE.Text);
                    cmd.Parameters.AddWithValue("@ActualHours", ActualHours.Text);
                    cmd.Parameters.AddWithValue("@ActualFTE", ActualFTE.Text);
                    cmd.Parameters.AddWithValue("@Comment", Comment.Text);
                    cmd.Parameters.AddWithValue("@CommentBy", CommentBy.Text);
                    cmd.Parameters.AddWithValue("@Period", Period.Text);




                    cmd.Connection = sqlCon;
                    sqlCon.Open();
                    IsUpdated = cmd.ExecuteNonQuery() > 0;
                    sqlCon.Close();
                }
            }
            if (IsUpdated)
            {
                lblMsg.Text = "'" + ResourceName.Text + "' CATW Comment updated successfully!";
                lblMsg.ForeColor = System.Drawing.Color.Green;
            }
            else
            {
                lblMsg.Text = "Error while updating '" + ResourceName.Text + "' subject details";
                lblMsg.ForeColor = System.Drawing.Color.Red;
            }
            gvCATW.EditIndex = -1;
            BindSubjectData();
        }

    
    }
}

AnswerRe: Trying to make a DataGridView field a color if a condition is met. Pin
Mathi Mani22-May-15 13:00
Mathi Mani22-May-15 13:00 
GeneralRe: Trying to make a DataGridView field a color if a condition is met. Pin
Norris Chappell23-May-15 11:11
Norris Chappell23-May-15 11:11 
Questionway around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
BillWoodruff22-May-15 6:49
professionalBillWoodruff22-May-15 6:49 
AnswerRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
Sascha Lefèvre22-May-15 7:04
professionalSascha Lefèvre22-May-15 7:04 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
BillWoodruff22-May-15 21:12
professionalBillWoodruff22-May-15 21:12 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
Sascha Lefèvre24-May-15 3:33
professionalSascha Lefèvre24-May-15 3:33 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
BillWoodruff24-May-15 22:42
professionalBillWoodruff24-May-15 22:42 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
Sascha Lefèvre25-May-15 4:21
professionalSascha Lefèvre25-May-15 4:21 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
BillWoodruff25-May-15 7:54
professionalBillWoodruff25-May-15 7:54 
AnswerRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
Richard Deeming22-May-15 7:11
mveRichard Deeming22-May-15 7:11 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
BillWoodruff22-May-15 21:27
professionalBillWoodruff22-May-15 21:27 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
BillWoodruff24-May-15 22:46
professionalBillWoodruff24-May-15 22:46 
AnswerRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
Pete O'Hanlon22-May-15 8:06
mvePete O'Hanlon22-May-15 8:06 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
BillWoodruff22-May-15 21:33
professionalBillWoodruff22-May-15 21:33 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
Pete O'Hanlon22-May-15 21:47
mvePete O'Hanlon22-May-15 21:47 
AnswerRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
Alan N22-May-15 14:15
Alan N22-May-15 14:15 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
BillWoodruff22-May-15 21:35
professionalBillWoodruff22-May-15 21:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.