zoukankan      html  css  js  c++  java
  • (转)aspxgridview记录的批量修改

    使用GridView自带的编辑功能,只能一条一条记录的修改,如果要求批量修改,必须使用模板。

    <dxwgv:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False"
        DataSourceID="DSCourse" KeyFieldName="CourseID" ClientInstanceName="grid" >
        <SettingsPager Visible="False">
        </SettingsPager>
        <Columns>
            <dxwgv:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0">
            </dxwgv:GridViewCommandColumn>
            <dxwgv:GridViewDataTextColumn Caption="序号" VisibleIndex="1" Width="25px">
                <DataItemTemplate>
                    <%# Container.ItemIndex+1%>
                    </DataItemTemplate>
            </dxwgv:GridViewDataTextColumn>
            <dxwgv:GridViewDataTextColumn FieldName="CourseName" VisibleIndex="2">
            </dxwgv:GridViewDataTextColumn>
            <dxwgv:GridViewDataTextColumn FieldName="Credit" VisibleIndex="3">
                <DataItemTemplate>
                    <dxe:ASPxTextBox ID="ASPxTextBox1" runat="server" Text='<%# Bind("Credit") %>'
                        Value='<%# Bind("Credit") %>' Width="170px">
                    </dxe:ASPxTextBox>
                </DataItemTemplate> 
            </dxwgv:GridViewDataTextColumn>
            <dxwgv:GridViewDataTextColumn FieldName="CreditHour" VisibleIndex="4">
                <DataItemTemplate>
                    <dxe:ASPxTextBox ID="ASPxTextBox2" runat="server" Text='<%# Bind("CreditHour") %>'
                        Value='<%# Bind("CreditHour") %>' Width="170px">
                    </dxe:ASPxTextBox>
                </DataItemTemplate>
            </dxwgv:GridViewDataTextColumn>
        </Columns>
    </dxwgv:ASPxGridView>
    <asp:AccessDataSource ID="DSCourse" runat="server" DataFile="~/WebCourse.mdb"
                SelectCommand="SELECT [CourseID], [CourseName], [Credit], [CreditHour],[zp] FROM [Course]" UpdateCommand="update Course set Credit=?,CreditHour=?,zp=Credit+CreditHour where CourseID=?">
                <UpdateParameters>
                    <asp:Parameter Name="Credit" Type="Single" />
                    <asp:Parameter Name="CreditHour" Type="Single" />
                    <asp:Parameter Name="CourseID" Type="Int32" />
                </UpdateParameters>
    </asp:AccessDataSource>

    CS代码文件

    protected void ASPxButton3_Click(object sender, EventArgs e)
       {
           for (int i = 0; i < grid.VisibleRowCount; i++)
           {
               ASPxTextBox tb1 = grid.FindRowCellTemplateControl(i, null, "ASPxTextBox1") as ASPxTextBox;
               ASPxTextBox tb2 = grid.FindRowCellTemplateControl(i, null, "ASPxTextBox2") as ASPxTextBox;
               DSCourse.UpdateParameters["Credit"].DefaultValue = tb1.Text;
               DSCourse.UpdateParameters["CreditHour"].DefaultValue = tb2.Text;
               DSCourse.UpdateParameters["CourseID"].DefaultValue = grid.GetRowValues(i, "CourseID").ToString();
               DSCourse.Update();
    
           }
       }

    版权说明:作者:张颖希PocketZ's Blog
    出处:http://www.cnblogs.com/PocketZ
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    若本文为翻译内容,目的为练习英文水平,如有雷同,纯属意外!有不妥之处,欢迎拍砖

  • 相关阅读:
    WeChat-SmallProgram:组件 scroll-view 横向和纵向 案例
    Codeforces Round #277 (Div. 2) D. Valid Sets 树形DP
    Codeforces Round #243 (Div. 2) E. Sereja and Two Sequences DP
    Codeforces Round #263 (Div. 2) D. Appleman and Tree 树形dp
    Codeforces Round #259 (Div. 2) D. Little Pony and Harmony Chest 状压DP
    Codeforces Round #274 (Div. 2) E. Riding in a Lift DP
    HDOJ 6069 素数筛
    在平面中,一个点绕任意点旋转θ度后的点的坐标
    HDOJ 5724 博弈SG函数
    Codeforces Round #422 (Div. 2) C. Hacker, pack your bags! 排序+贪心
  • 原文地址:https://www.cnblogs.com/PocketZ/p/1744705.html
Copyright © 2011-2022 走看看