PDA

View Full Version : جمع زدن تمام رکورد های گریدویو



rational unified process
یک شنبه 15 دی 1392, 22:36 عصر
سلام
من یه گرید ویو دارم که چند تا فیلد داره از جمله فیلد قیمت و فیلد چه تعداد میخواهید.
فیلد قیمت ، عدد است که از بانک خوانده میشود و فیلد تعداد، TemplateField است که داخلش دراپ دان است،یعنی فیلد تعداد از دراپ دان خوانده میشه.
حالا من میخوام که
1)مقدار دراپ دان هر رکورد در مقدار قیمت همان رکورد ضرب شود
2)حاصلضرب های همه رکورد ها با هم جمع بشه
من اینکارا رو توی رویداد کلیک دکمه ای در صفحه انجام دادم و مشکلی هم نیست جز اینکه مقدار دراپ دان هر چه باشد باز هم عدد 1 در مقدار قیمت ضرب میشود چرا؟

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ShoppingCart.ascx.cs" Inherits="View_ShoppingCart" %>
<!----------------------------------------->
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<!----------------------------------------->
<div dir="rtl" align="center">
<asp:Image ID="Image1" runat="server" ImageUrl="~/Icon/shoppingcart.jpeg" />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" BackColor="White"
BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4"
DataKeyNames="ProductionID" DataSourceID="SqlDataSource1"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<RowStyle BackColor="White" ForeColor="#003399" />
<Columns>
<asp:BoundField DataField="ProductionID" HeaderText="آی دی محصول"
ReadOnly="True" SortExpression="ProductionID" />
<asp:BoundField DataField="ProductionCategoryID"
HeaderText="آی دی دسته بندی محصول" SortExpression="ProductionCategoryID" />
<asp:BoundField DataField="ProductionName" HeaderText="نام محصول"
SortExpression="ProductionName" />
<asp:BoundField DataField="Cast" HeaderText="قیمت" SortExpression="Cast" />
<asp:BoundField DataField="IP" HeaderText="آی پی شما" SortExpression="IP" Visible="false"/>
<asp:TemplateField HeaderText="چه تعداد میخواهید" SortExpression="Comments">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Comments") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem Text="1" Value="1"> </asp:ListItem><asp:ListItem Text="2" Value="2"> </asp:ListItem>
<asp:ListItem Text="3" Value="3"> </asp:ListItem><asp:ListItem Text="4" Value="4"> </asp:ListItem>
<asp:ListItem Text="5" Value="5"> </asp:ListItem><asp:ListItem Text="6" Value="6"> </asp:ListItem>
<asp:ListItem Text="7" Value="7"> </asp:ListItem><asp:ListItem Text="8" Value="8"> </asp:ListItem>
<asp:ListItem Text="9" Value="9"> </asp:ListItem><asp:ListItem Text="10" Value="10"> </asp:ListItem>
<asp:ListItem Text="11" Value="11"> </asp:ListItem><asp:ListItem Text="12" Value="12"> </asp:ListItem>
<asp:ListItem Text="13" Value="13"> </asp:ListItem><asp:ListItem Text="14" Value="14"> </asp:ListItem>
<asp:ListItem Text="15" Value="15"> </asp:ListItem><asp:ListItem Text="16" Value="16"> </asp:ListItem>
<asp:ListItem Text="17" Value="17"> </asp:ListItem><asp:ListItem Text="18" Value="18"> </asp:ListItem>
<asp:ListItem Text="19" Value="19"> </asp:ListItem><asp:ListItem Text="20" Value="20"> </asp:ListItem>
</asp:DropDownList>
<%--<asp:Label ID="Label2" runat="server" Text='<%# Bind("Comments") %>'></asp:Label>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="توضیحات" SortExpression="Comments">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Comments") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" TextMode="MultiLine" MaxLength="200"></asp:TextBox>
<%--<asp:Label ID="Label1" runat="server" Text='<%# Bind("Comments") %>'></asp:Label>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" HeaderText="حذف" CancelText="کنسل"
DeleteText="حذف"/>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
DeleteCommand="DELETE FROM [tbl_Temp] WHERE [ProductionID] = @ProductionID"
InsertCommand="INSERT INTO [tbl_Temp] ([ProductionID], [ProductionCategoryID], [ProductionName], [Cast], [IP], [Comments], [Numbers]) VALUES (@ProductionID, @ProductionCategoryID, @ProductionName, @Cast, @IP, @Comments, @Numbers)"
SelectCommand="SELECT * FROM [tbl_Temp] WHERE ([IP] = @IP)"
UpdateCommand="UPDATE [tbl_Temp] SET [ProductionCategoryID] = @ProductionCategoryID, [ProductionName] = @ProductionName, [Cast] = @Cast, [IP] = @IP, [Comments] = @Comments, [Numbers] = @Numbers WHERE [ProductionID] = @ProductionID">
<SelectParameters>
<asp:SessionParameter Name="IP" SessionField="mySession" Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="ProductionID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ProductionCategoryID" Type="Int32" />
<asp:Parameter Name="ProductionName" Type="String" />
<asp:Parameter Name="Cast" Type="Int32" />
<asp:Parameter Name="IP" Type="String" />
<asp:Parameter Name="Comments" Type="String" />
<asp:Parameter Name="Numbers" Type="String" />
<asp:Parameter Name="ProductionID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ProductionID" Type="Int32" />
<asp:Parameter Name="ProductionCategoryID" Type="Int32" />
<asp:Parameter Name="ProductionName" Type="String" />
<asp:Parameter Name="Cast" Type="Int32" />
<asp:Parameter Name="IP" Type="String" />
<asp:Parameter Name="Comments" Type="String" />
<asp:Parameter Name="Numbers" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<br />
<asp:Label ID="Label1" runat="server" ForeColor="#FF0066"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="ثبت" />
</div>
<!----------------------------------------->
</ContentTemplate>
</asp:UpdatePanel>




using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class View_ShoppingCart : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
DropDownList ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList1");
int ddlv = int.Parse(ddl.Items[i].Value);

int cast = int.Parse(GridView1.Rows[i].Cells[3].Text);

int[] star = new int[GridView1.Rows.Count];
star[i] = ddlv * cast;
int add = star.Sum();
Label1.Text = " : چمع کل هست" + add;
}
}
}

rational unified process
سه شنبه 17 دی 1392, 00:16 صبح
کسی جوابی نداره؟

fakhravari
سه شنبه 17 دی 1392, 08:54 صبح
foreach (GridViewRow row in GridView1.Rows)
{
TextBox textnum = row.FindControl("TextBox1") as TextBox;
Label txtid = row.FindControl("Label3") as Label;

}

Alfred188
سه شنبه 17 دی 1392, 10:40 صبح
سلام،
اون قسمتی که قرمز هستش رو تغییر بدید و نتیجه بگید.
for (int i = 0; i < GridView1.Rows.Count; i++)
{
DropDownList ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList1");
int ddlv = int.Parse(ddl.Items[i].SelectedValue.ToString());

int cast = int.Parse(GridView1.Rows[i].Cells[3].Text);

int[] star = new int[GridView1.Rows.Count];
star[i] = ddlv * cast;
int add = star.Sum();
Label1.Text = " : چمع کل هست" + add;
}


[/CSHARP][/QUOTE]