GridView控制項批次更新

來源:互聯網
上載者:User

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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.