3
I am building a dynamic GRIDVIEW, where the information of each TD will be a DIV.
exemplo: <td><div id="d1" class="redips-drag t1">z</div></td>
I am filling the valve as follows:
if (dtWorkServiceTimeByWorkerAndDate.Rows.Count > 0)
finalResult = "<div id=\"column" + count.ToString() + "\" class=\"redips-drag t1\">" + formatSecondsInHourAndMinute(Convert.ToInt32(dtWorkServiceTimeByWorkerAndDate.Rows[0]["work_ServiceTime"])) + "</div>";
My problem is that GRID does not recognize div as an object, but rather as a String. The value of each column is coming out as follows:
exemplo <div id="column1" class="redips-drag t1">23:59</div>
Does anyone know how to avoid this problem?
Vlw.
EDIT
To construct the grid, I am using a function that returns a Datatable, as follows:
public DataTable constructWorkerAvailabilityTime()
{
DateTime fDateDataType = new DateTime(Int32.Parse(fYear), Int32.Parse(fMonth), Int32.Parse(fDay));
DateTime tDateDataType = new DateTime(Int32.Parse(tYear), Int32.Parse(tMonth), Int32.Parse(tDay));
this.fromDate = fDateDataType.ToString("yyyy-MM-dd");
this.toDate = tDateDataType.ToString("yyyy-MM-dd");
DataTable dtFinalResult = new DataTable();
List<String> allWorkers = getAllWorkers();
List<String> columnsSequence = getDateColumnsSequence();
dtFinalResult.Columns.Add("worker", typeof(string));
int count = 0;
foreach (string column in columnsSequence)
dtFinalResult.Columns.Add(column, typeof(string));
foreach (string worker in allWorkers)
{
DataRow newRow = dtFinalResult.NewRow();
newRow["worker"] = getWorkerName(worker);
foreach (string column in columnsSequence)
{
HtmlString htmlString = getWorkServiceTimeByWorkerAndDate(worker, column, count);
newRow[column] = htmlString;
//newRow[column] = "@Html.Raw(" + getWorkServiceTimeByWorkerAndDate(worker, column, count) + ")";
count++;
}
dtFinalResult.Rows.Add(newRow);
}
return dtFinalResult;
}
private HtmlString getWorkServiceTimeByWorkerAndDate(string worker, string executionDate, int count)
{
HtmlString finalResult = new HtmlString("");
DataTable dtWorkServiceTimeByWorker = cmd.selectWorkServiceTimeByWorker(worker);
DataTable dtWorkServiceTimeByWorkerAndDate = cmd.selectWorkServiceTimeByWorkerAndDate(worker, executionDate);
if (dtWorkServiceTimeByWorker.Rows.Count == 1)
finalResult = new HtmlString("<div id=\"column" + count.ToString() + "\" class=\"redips-drag t1\" runat=\"server\">" + formatSecondsInHourAndMinute(Convert.ToInt32("28860")) + "</div>");
else if (dtWorkServiceTimeByWorker.Rows.Count > 1)
{
if (dtWorkServiceTimeByWorkerAndDate.Rows.Count > 0)
finalResult = new HtmlString("<div id=\"column" + count.ToString() + "\" class=\"redips-drag t1\" runat=\"server\">" + formatSecondsInHourAndMinute(Convert.ToInt32(dtWorkServiceTimeByWorkerAndDate.Rows[0]["work_ServiceTime"])) + "</div>");
else
finalResult = new HtmlString("<div id=\"column" + count.ToString() + "\" class=\"redips-drag t1\" runat=\"server\">00:00</div>");
}
return finalResult;
}
And finally fill the grid in the page Load:
protected void Page_Load(object sender, EventArgs e)
{
WorkerManagement wm = new WorkerManagement();
GridWorkerAvailability.DataSource = wm.constructWorkerAvailabilityTime();
GridWorkerAvailability.DataBind();
GridWorkerAvailability.SelectedIndex = -1;
}
Flavio, take a look at this reply and see if you can solve with one of these two solutions, I’m not being able to test now.
– Filipe Oliveira
@Filipeoliveira BOAA! Solved my problem, vlww man.
– Flavio Luiz