在波纹管代码中从forech循环内的datarow行中删除row

在波纹管代码中从forech循环内的datarow行中删除row

本文介绍了如何在波纹管代码中从forech循环内的datarow行中删除row [6]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   protected void gvTimeSheet_DataBound(object sender, EventArgs e)

    {
        DataTable dt = new DataTable();
        int intUserID = TypeConvert.IsNullInt32(ddlUsers.SelectedValue, 0);
        DateTime fromDate = Convert.ToDateTime(UCFromDate.selectedDate);
        DateTime toDate = Convert.ToDateTime(UCToDate.selectedDate);
        string strQuery = "EXEC SPRptUserTimeSheet_AP @User=" + intUserID + ",@dateFrom='" + fromDate + "',@dateTo='" + toDate + "'";
        dt = DataHelper.ExecuteQuery(strQuery);
        dt.Columns.Add("Booked Hrs");
        dt.Columns.Add("Time Zone");



        foreach (DataRow row in dt.Rows)
        {
            string userName = row[0].ToString();
            string bookedHr = row[6].ToString();
            string timezone = row[7].ToString();

            if (userName == string.Empty)
            {
                row[0] = ddlUsers.SelectedItem.Text;
            }

            if (bookedHr == string.Empty)
            {
                row["Booked Hrs"] = 0.0;
            }
            if (bookedHr != string.Empty)
            {
                row["Booked Hrs"] = objCommon.fnGetEffortInHrMinFormat(Convert.ToInt32(bookedHr));
            }

            if (timezone == "0")
            {
                row["Time Zone"] = "Offshore";

            }
            if (timezone == "1")
            {
                row["Time Zone"] = "Onsite";
            }

        }
        ViewState["dtExport"] = dt;
    }
}

What I have tried:

protected void gvTimeSheet_DataBound(object sender, EventArgs e)

    {
        DataTable dt = new DataTable();
        int intUserID = TypeConvert.IsNullInt32(ddlUsers.SelectedValue, 0);
        DateTime fromDate = Convert.ToDateTime(UCFromDate.selectedDate);
        DateTime toDate = Convert.ToDateTime(UCToDate.selectedDate);
        string strQuery = "EXEC SPRptUserTimeSheet_AP @User=" + intUserID + ",@dateFrom='" + fromDate + "',@dateTo='" + toDate + "'";
        dt = DataHelper.ExecuteQuery(strQuery);
        dt.Columns.Add("Booked Hrs");
        dt.Columns.Add("Time Zone");



        foreach (DataRow row in dt.Rows)
        {
            string userName = row[0].ToString();
            string bookedHr = row[6].ToString();
            string timezone = row[7].ToString();

            if (userName == string.Empty)
            {
                row[0] = ddlUsers.SelectedItem.Text;
            }

            if (bookedHr == string.Empty)
            {
                row["Booked Hrs"] = 0.0;
            }
            if (bookedHr != string.Empty)
            {
                row["Booked Hrs"] = objCommon.fnGetEffortInHrMinFormat(Convert.ToInt32(bookedHr));
            }

            if (timezone == "0")
            {
                row["Time Zone"] = "Offshore";

            }
            if (timezone == "1")
            {
                row["Time Zone"] = "Onsite";
            }

        }
        ViewState["dtExport"] = dt;
    }
}

推荐答案


这篇关于如何在波纹管代码中从forech循环内的datarow行中删除row [6]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 19:21