Gridview Helper Class Work For BoundField Not In ItemTemplate RRS feed

  • Question

  • User1152553138 posted

    Everyone are awaare of Gridview Helper Class ... See Below


    The Gridview Helper SUM works only for Asp.Net GridView BoundField and it is not working in ItemTemplate ...

    See Below Example BoundField

     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" EnableViewState="False" DataKeyNames="OrderId" CellPadding="3">
                    <asp:BoundField DataField="ShipRegion" HeaderText="ShipRegion" SortExpression="ShipRegion" />
                    <asp:BoundField DataField="ShipName" HeaderText="ShipName" SortExpression="ShipName" />
                    <asp:BoundField DataField="OrderId" HeaderText="OrderId" InsertVisible="False" ReadOnly="True"
                        SortExpression="OrderId" />
                    <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
                    <asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" >
                        <ItemStyle HorizontalAlign="Right" />
                    <asp:BoundField DataField="UnitPrice" DataFormatString="{0:c}" HeaderText="UnitPrice"
                        HtmlEncode="False" SortExpression="UnitPrice" >
                        <ItemStyle HorizontalAlign="Right" />
                    <asp:BoundField DataField="ItemTotal" DataFormatString="{0:c}" HeaderText="ItemTotal"
                        HtmlEncode="False" ReadOnly="True" SortExpression="ItemTotal" >
                        <ItemStyle HorizontalAlign="Right" />

    <asp:Button ID="Button1" runat="server" Text="North" onclick="Button1_Click" />
     protected void Page_Load(object sender, EventArgs e)
            if (!IsPostBack)
            GridViewHelper helper = new GridViewHelper(this.GridView1);
            helper.RegisterGroup("ShipRegion", true, true);
            helper.RegisterSummary("ItemTotal", SummaryOperation.Sum, "ShipRegion");
     private void GridBind()
            String strConnString = ConfigurationManager.ConnectionStrings["NorthWind"].ConnectionString;
            SqlConnection con = new SqlConnection(strConnString);
            SqlCommand cmd12 = new SqlCommand("Select ShipRegion, ShipName, Orders.OrderId, ProductName, Quantity, Products.UnitPrice, (Quantity * Products.UnitPrice) as ItemTotal from Orders, [Order Details], Products where Orders.OrderId = [Order Details].OrderId and [Order Details].ProductId = Products.ProductId and ShipRegion is not null and ShipCountry in ('Brazil') and year(OrderDate) = 1998 and month(OrderDate) = 3 ", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd12);
            DataTable table = new DataTable();
            GridView1.DataSource = table;
            GridView1.Visible = true;
     protected void Button1_Click(object sender, EventArgs e)

    I tried using Item template field its not working ... Help here ... Please ...

    Friday, March 30, 2018 11:03 AM

All replies

  • User-1838255255 posted

    Hi Ashraf007,

    According to your description, you say Item template not working, but i don't see any code about Item template in your sample. Also you say doesn't work, if you meet any exception code or meet other issue? i hope you could give us a detailed description. 

    Best Regards,

    Eric Du 

    Wednesday, April 4, 2018 8:05 AM