void AddJobToGridView(JobServiceReference.JobInformation jobInformation) { // Check if the ViewState has a data associated within it. if (ViewState["CurrentData"] != null) { DataTable dt = (DataTable)ViewState["CurrentData"]; int count = dt.Rows.Count; BindGrid(count, jobInformation); } else { BindGrid(1, jobInformation); } _lblJobsCount.Text = "Total Jobs: " + _gridViewClientJobs.Rows.Count.ToString(); }
private void BindGrid(int rowcount, JobServiceReference.JobInformation jobInformation) { if (jobInformation == null) { return; } //Only show multimedia jobs in this demo if (String.Compare(jobInformation.JobType, "Multimedia", true) != 0) { return; } MultimediaData multimediaData = MultimediaData.DeserializeFromString(jobInformation.Metadata.JobMetadata); string inputFileName = multimediaData.SourceFile.Length > 0 ? Path.GetFileName(multimediaData.SourceFile) : String.Empty; string outputFileName = jobInformation.Status == JobStatus.Completed && multimediaData.TargetFile.Length > 0 ? Path.GetFileName(multimediaData.TargetFile) : String.Empty; DataColumn[] dataColums = new DataColumn[] { new DataColumn("Job ID", typeof(string)), new DataColumn("Status", typeof(string)), new DataColumn("Worker", typeof(string)), new DataColumn("Percentage", typeof(int)), new DataColumn("Added Data/Time", Nullable.GetUnderlyingType(typeof(Nullable <DateTime>))), new DataColumn("Completed Data/Time", Nullable.GetUnderlyingType(typeof(Nullable <DateTime>))), new DataColumn("Error ID", typeof(int)), new DataColumn("Error Message", typeof(string)), new DataColumn("Input File", typeof(string)), new DataColumn("Output File", typeof(string)), new DataColumn("Full Path", typeof(string)), new DataColumn("Target Format", typeof(string)), }; DataTable dt = new DataTable(); dt.Columns.AddRange(dataColums); DataRow dr; if (ViewState["CurrentData"] != null) { for (int i = 0; i < rowcount; i++) { dt = (DataTable)ViewState["CurrentData"]; if (dt.Rows.Count > 0) { dr = dt.NewRow(); dr[0] = dt.Rows[i][0].ToString(); dr[1] = dt.Rows[i][1].ToString(); dr[2] = dt.Rows[i][2].ToString(); dr[3] = dt.Rows[i][3].ToString(); if (dt.Rows[i][3] != null) { dr[4] = dt.Rows[i][4]; } else { dr[4] = DBNull.Value; } if (dt.Rows[i][4] != null) { dr[5] = dt.Rows[i][5]; } else { dr[5] = DBNull.Value; } dr[6] = dt.Rows[i][6].ToString(); dr[7] = dt.Rows[i][7].ToString(); dr[8] = dt.Rows[i][8].ToString(); dr[9] = dt.Rows[i][9].ToString(); dr[10] = dt.Rows[i][10].ToString(); dr[11] = dt.Rows[i][11].ToString(); } } if (jobInformation != null) { dr = dt.NewRow(); dr[0] = jobInformation.ID; dr[1] = jobInformation.Status; dr[2] = jobInformation.Worker; dr[3] = jobInformation.Percentage; if (jobInformation.AddedTime != null) { dr[4] = jobInformation.AddedTime; } else { dr[4] = DBNull.Value; } if (jobInformation.CompletedTime != null) { dr[5] = jobInformation.CompletedTime; } else { dr[5] = DBNull.Value; } dr[6] = jobInformation.FailureInformation.FailedErrorID; dr[7] = jobInformation.FailureInformation.FailedMessage; dr[8] = inputFileName; dr[9] = outputFileName; dr[10] = _outputFilesName + outputFileName; dr[11] = multimediaData.ProfileName; dt.Rows.Add(dr); } } else { if (jobInformation != null) { dr = dt.NewRow(); dr[0] = jobInformation.ID; dr[1] = jobInformation.Status; dr[2] = jobInformation.Worker; dr[3] = jobInformation.Percentage; if (jobInformation.AddedTime != null) { dr[4] = jobInformation.AddedTime; } else { dr[4] = DBNull.Value; } if (jobInformation.CompletedTime != null) { dr[5] = jobInformation.CompletedTime; } else { dr[5] = DBNull.Value; } dr[6] = jobInformation.FailureInformation.FailedErrorID; dr[7] = jobInformation.FailureInformation.FailedMessage; dr[8] = inputFileName; dr[9] = outputFileName; dr[10] = _outputFilesName + outputFileName; dr[11] = multimediaData.ProfileName; dt.Rows.Add(dr); } } // If ViewState has a data then use the value as the DataSource if (ViewState["CurrentData"] != null) { _gridViewClientJobs.DataSource = (DataTable)ViewState["CurrentData"]; _gridViewClientJobs.DataBind(); } else { // Bind GridView with the initial data associated in the DataTable _gridViewClientJobs.DataSource = dt; _gridViewClientJobs.DataBind(); } // Store the DataTable in ViewState to retain the values ViewState["CurrentData"] = dt; }