GridView控件批量更新

CS代码:
    protected void ButtontBatchPrice_Click(object sender, EventArgs e)
    {
        CheckBox cb=new CheckBox();
        for (int i = 0; i < GridView1.Rows.Count;i++ )
        {
            cb = (GridView1.Rows[i].Cells[7].FindControl("CheckBox1") as CheckBox);
            if (cb.Checked)
            {
                HiddenField hf=new HiddenField();
                hf=GridView1.Rows[i].Cells[7].FindControl("HiddenField1") as HiddenField;
                Price_LFacade_Web.UpdatePrice(hf.Value, Convert.ToDecimal(GridView1.Rows[i].Cells[2].Text), Convert.ToDecimal(GridView1.Rows[i].Cells[2].Text), Convert.ToDecimal(GridView1.Rows[i].Cells[2].Text), Convert.ToDecimal(GridView1.Rows[i].Cells[2].Text));
            }
        }
    }

    public static void UpdatePrice(string ObjectId, decimal OnlineBidPrice, decimal OnlineSellPrice, decimal OrderBidPrice, decimal OrderSellPrice)
    {
        //更新失败情况未做处理,日后完善
        Price_LFacade tmpPrice = new Price_LFacade(ObjectId);
        String blockName = System.Guid.NewGuid().ToString();
        WebUndoBlockHelper.StartUndoBlock(blockName);
        tmpPrice.QuoteScenario.ModifyPriceAndProfitMargin(tmpPrice.GoodsSubjectId, tmpPrice.ProfitMargin, OrderSellPrice, OnlineSellPrice, tmpPrice.PriceUnit);
        WebUndoBlockHelper.UpdateBlock(blockName);
    }

HTML代码
<body>
    <form id="form1" runat="server">
    <div align="left">
        <asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1" AutoGenerateColumns="False" DataKeyNames="ObjectId" AllowPaging="True" PageSize="20" Width="98%" OnRowUpdating="GridView1_RowUpdating" EnableViewState="False">
            <Columns>
                <asp:BoundField HeaderText="对象ID" DataField="ObjectId" ReadOnly="True" Visible="False" />
                <asp:BoundField HeaderText="产品名称" DataField="GoodsName" ReadOnly="True" >
                    <ItemStyle Width="22%" />
                </asp:BoundField>
                <asp:BoundField HeaderText="面值" DataField="FacePrice" ReadOnly="True" DataFormatString="{0:c}" >
                    <ItemStyle Width="8%" />
                </asp:BoundField>
                <asp:TemplateField HeaderText="直储进价">
                    <EditItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("OnlineBidPrice") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemStyle Width="14%" />
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "OnlineBidPrice", "{0:c}") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="直储售价">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("OnlineSellPrice") %>' Width="40px"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemStyle Width="14%" />
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "OnlineSellPrice", "{0:c}") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="订购进价">
                    <EditItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("OrderBidPrice") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemStyle Width="14%" />
                    <ItemTemplate>
                        <asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "OrderBidPrice", "{0:c}") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="订购售价">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("OrderSellPrice") %>' Width="40px"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "OrderSellPrice", "{0:c}") %>'></asp:Label>
                    </ItemTemplate>
                    <ItemStyle Width="14%" />
                </asp:TemplateField>
                <asp:CommandField ShowEditButton="True" />
                <asp:TemplateField>
                    <EditItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" />
                    </EditItemTemplate>
                    <HeaderTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" />
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" />
                        <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("ObjectId") %>' />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <table width="98%">
            <tr>
                <td>请输入要更改的折扣:<asp:TextBox ID="TextBoxGgio" runat="server" Width="30px"></asp:TextBox>
                    &nbsp;&nbsp; <font color="red">注(如果您要按9.5折销售的话,请输入0.95,以此类推)</font></td>
            </tr>
            <tr>
                <td><asp:Button ID="ButtontBatchPrice" runat="server" Text="按折扣更新所有的销售价" OnClick="ButtontBatchPrice_Click" /></td>
            </tr>
        </table>
    </div>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="Price_LFacade_Web" SelectMethod="GetPriceList" UpdateMethod="UpdatePrice" OldValuesParameterFormatString="{0,-2}"></asp:ObjectDataSource>
        &nbsp;
    </form>
</body>

posted @ 2006-10-13 09:40  '.Elvis.'  阅读(1003)  评论(0编辑  收藏  举报