0
<asp:GridView ID="GridView_Stores" runat="server" OnRowDataBound="GridView1_RowDataBound" ShowFooter="True" AllowSorting="false" HTMLEncoded="false" AutoGenerateColumns="true" DataSourceID="myDataSource" ShowHeaderWhenEmpty="True"/>...

ソース/接続/自動生成されたかどうかに関係なく、本文ヘッダーまたは項目テンプレートの最初の行には常に空白<tr><th scope="col">または<tr><td>;が含まれます。それは終わらないし、終わらない。削除する方法が見つかりません。

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
  {
    string ptn = "$#,###;<span style='color:rgb(255,0,0);'>($#,###)</span>;-";
    if (e.Row.RowType == DataControlRowType.DataRow) 
    {
      SalesTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "sales"));
      RentalTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "rental"));
      PartsTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "parts"));
      ServiceTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "service"));
      OverallTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "total"));
    }
    if (e.Row.RowType == DataControlRowType.Footer) 
    {
      Literal TtalSales = (Literal)e.Row.FindControl("TtalSales");
      TtalSales.Text = SalesTotal.ToString(ptn);
      Literal TtalRental = (Literal)e.Row.FindControl("TtalRental");
      TtalRental.Text = RentalTotal.ToString(ptn);
      Literal TtalParts = (Literal)e.Row.FindControl("TtalParts");
      TtalParts.Text = PartsTotal.ToString(ptn);
      Literal TtalService = (Literal)e.Row.FindControl("TtalService");
      TtalService.Text = ServiceTotal.ToString(ptn);
      Literal TtalTotal = (Literal)e.Row.FindControl("TtalTotal");
      TtalTotal.Text = OverallTotal.ToString(ptn);
    }
  }
4

1 に答える 1

0

ヘッダー列を手動で定義できます。

<asp:GridView ID="GridView_Stores" runat="server" OnRowDataBound="GridView1_RowDataBound" ShowFooter="True" AllowSorting="false" HTMLEncoded="false" AutoGenerateColumns="false" DataSourceID="myDataSource" ShowHeaderWhenEmpty="true">
    <Columns>
        <asp:BoundField HeaderText="Sales Total" />
        <asp:BoundField HeaderText="Rental Total" />
        <asp:BoundField HeaderText="Parts Total" />
        <asp:BoundField HeaderText="Service Total" />
        <asp:BoundField HeaderText="Overall Total" />
    </Columns>
</asp:GridView>
于 2013-04-11T18:38:45.183 に答える