【问题标题】:DataGridView Row ComputeDataGridView 行计算
【发布时间】:2012-11-26 22:27:47
【问题描述】:

我在 Visual Studio 中使用 C# 进行项目。在我的项目中,它下面有一个 gridview 和一个按钮。当我点击按钮时,我想计算我的工人的总工作时间到最后一行。我阅读了所有类似的主题,但我的代码有问题。如果您有更多/任何说明性示例,请帮助我,我真的需要帮助。我的项目期限很短。

这是逻辑;

Sunday   Monday   Tuesday    ........     TOTAL

   10           50            5          ........        65              works like this..

实际上我不想在我的网格视图下只使用一个按钮。我想为每一行的每个工人使用...

这是 ButtonClick 代码,但我不想这样使用。我需要添加模板列,其中包含每一行的按钮。我知道但是怎么做?它总是失败,我总是遇到一些错误。

 protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            row.Cells[10].Text = (Convert.ToInt32(row.Cells[3].Text) + Convert.ToInt32(row.Cells[4].Text)).ToString() +
                                 (Convert.ToInt32(row.Cells[5].Text) + Convert.ToInt32(row.Cells[6].Text)).ToString() +
                                 (Convert.ToInt32(row.Cells[7].Text) + Convert.ToInt32(row.Cells[8].Text)).ToString() +
                                 (Convert.ToInt32(row.Cells[9].Text));
        }
    }

【问题讨论】:

  • 你问了两个问题。你应该一问一答。你的问题是什么?把按钮放在datagridview的每一行还是计算总工作量?
  • 是的,我的朋友,你是对的。我在问那个;我想在每一行上放置按钮,当我点击按钮时,我想计算该行的总值到最后一行。

标签: c# asp.net datagridview row


【解决方案1】:

要在每一行上都有按钮,您需要使用

DatagridviewButtonColumn

信息:How can i add two buttons to a single datagrid column dynamically?

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewbuttoncolumn.aspx

Define DataGridView Column type Programmatically

已编辑:

你可以这样做:

 DataGridViewButtonColumn clbt_delet = new DataGridViewButtonColumn();
   clbt_delete.HeaderText = "DELETE"
   clbt_delete.Text = "Delete";
   clbt_delete.UseColumnTextForButtonValue = true;
   dataGridView1.Columns.Add(clbt_delete);

如果您需要任何其他信息,请随时说

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多