Asp.net 在GridView中显示数据之前编辑数据

Asp.net 在GridView中显示数据之前编辑数据,asp.net,gridview,webforms,Asp.net,Gridview,Webforms,所以基本上,我从数据库中提取数据,我希望它显示在gridview中。不幸的是,一周中的几天被存储为整数,因此星期一等于0,星期二等于1,以此类推 基本上,我如何在输出数据时更改数据,以便将数字转换为一周中的正确日期 我有一个网格视图,如下所示,目前我已使用onrowdatabound进行了设置: <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGene

所以基本上,我从数据库中提取数据,我希望它显示在gridview中。不幸的是,一周中的几天被存储为整数,因此星期一等于0,星期二等于1,以此类推

基本上,我如何在输出数据时更改数据,以便将数字转换为一周中的正确日期

我有一个网格视图,如下所示,目前我已使用onrowdatabound进行了设置:

 <asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
                        AutoGenerateColumns="False" DataSourceID="SqlDataSource2" Width="721px"  
                        onrowdatabound="GridView_RowDataBound" 
                        >
我假设我只需要在那里输入正确的代码。然而,由于某种原因,我不能对单个单元格做任何事情,只能对特定列中的每个单元格做任何事情。因此,我可以将一列中的每个单元格都更改为粗体,但不能单独更改一个单元格。我肯定有办法,但不知道怎么做

任何帮助都将不胜感激

谢谢

        protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int days = (int)GridView1.Rows[e.Row.RowIndex].Cell[2].Text;
            if (days == 0) GridView1.Rows[e.Row.RowIndex].Cell[2].Text = "Monday";
            if (days == 1) GridView1.Rows[e.Row.RowIndex].Cell[2].Text = "Tuesday";
            if (days == 1) GridView1.Rows[e.Row.RowIndex].Cell[2].Text = "Wednesday";
            if (days == 1) GridView1.Rows[e.Row.RowIndex].Cell[2].Text = "Thursday";
            if (days == 1) GridView1.Rows[e.Row.RowIndex].Cell[2].Text = "Friday";

        }

    }
你可以试试这个

if (e.Row.RowType == DataControlRowType.DataRow)
{
     string days = e.Row.Cells[2].Text;
     if (days == "0") e.Row.Cells[2].Text = "Monday";
     if (days == "1") e.Row.Cells[2].Text = "Tuesday";
     if (days == "2") e.Row.Cells[2].Text = "Wednesday";
     if (days == "3") e.Row.Cells[2].Text = "Thursday";
     if (days == "4") e.Row.Cells[2].Text = "Friday";
}

看看这个问题:你想设置每个单元格还是某个特定的单元格?该列中的每个单元格都是一周中正确的一天。你是在
ASP.NET
还是
ASP Classic
中工作?您已经使用了这两个标记。这将循环使用所有标记,还是只使用最上面的标记?这是我之前遇到的问题。不过我会在30分钟内尝试,并会更新你(如果答案正确,会标记为答案)谢谢你的帮助
GridView\u RowDataBound
此事件针对GridView中的每一行发生,因此它将设置该列中的每个单元格。我理解。令人惊叹的。刚刚尝试了它并得到了关于单词“Cell”的以下错误:“System.Web.UI.WebControls.GridViewRow”不包含“Cell”的定义,并且找不到接受类型为“System.Web.UI.WebControls.GridViewRow”的第一个参数的扩展方法“Cell”
if (e.Row.RowType == DataControlRowType.DataRow)
{
     string days = e.Row.Cells[2].Text;
     if (days == "0") e.Row.Cells[2].Text = "Monday";
     if (days == "1") e.Row.Cells[2].Text = "Tuesday";
     if (days == "2") e.Row.Cells[2].Text = "Wednesday";
     if (days == "3") e.Row.Cells[2].Text = "Thursday";
     if (days == "4") e.Row.Cells[2].Text = "Friday";
}