gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 00:21:45 24 4
gpt4 key购买 nike

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

基本上,我如何在输出数据时更改数据,以便将数字转换为正确的星期几。

我有一个 GridView 如下,目前我已经用 onrowdatabound 设置了它:

 <asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
AutoGenerateColumns="False" DataSourceID="SqlDataSource2" Width="721px"
onrowdatabound="GridView_RowDataBound"
>

那么 GridView_RowDataBound 的代码是:

  protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{

}

}

我假设我只需要将正确的代码放在那里。但是,出于某种原因,我不能只对特定列中的每个单元格对单个单元格执行任何操作。所以我可以将一列中的每个单元格更改为粗体,但不能单独更改单元格。我确信有办法,但不知道如何去做!

任何帮助将不胜感激!

谢谢

        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 - 在数据显示在 GridView 中之前编辑数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10642684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com