gpt4 book ai didi

javascript - AspxGridview 添加新行并保留最后一行值

转载 作者:行者123 更新时间:2023-12-03 03:45:30 30 4
gpt4 key购买 nike

我有一个aspxgridview,它将允许用户添加新行。我想要做的是每次添加新行时保留最后一行的值。我在 GridView 外部有“添加新行”按钮。是否可以?任何帮助将非常感激。

以下是我目前所掌握的内容。

前端

<dx:ASPxGridView ID="ASPxGridView1" ProcessSelectionChangedOnServer="true"  
ClientInstanceName="sampleGrid" runat="server" AutoGenerateColumns="False"
DataSourceID="forFromGrid" Theme="Material" Font-Size="11px" KeyFieldName="thisid"
Width="100%" CssClass="body"
OnHtmlFooterCellPrepared="ASPxGridView1_HtmlFooterCellPrepared" >
<SettingsBehavior ColumnResizeMode="NextColumn" />
<Settings VerticalScrollBarMode="Visible" VerticalScrollableHeight="345" />
<settingscommandbutton>
<showadaptivedetailbutton buttontype="Image">
</showadaptivedetailbutton>
<hideadaptivedetailbutton buttontype="Image">
</hideadaptivedetailbutton>
</settingscommandbutton>
<SettingsDataSecurity AllowEdit="False" AllowInsert="False" />

<Columns>

<dx:GridViewDataTextColumn FieldName="thisid" ShowInCustomizationForm="True"
VisibleIndex="0" ReadOnly="True" Visible="false">
<SettingsHeaderFilter>
<DateRangePickerSettings EditFormatString="" />
</SettingsHeaderFilter>
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>

<dx:GridViewDataTextColumn FieldName="no." Visible="false"
ShowInCustomizationForm="True" VisibleIndex="1">

</dx:GridViewDataTextColumn>

<dx:GridViewDataTextColumn FieldName="product" visible="false"
ShowInCustomizationForm="True" VisibleIndex="2">
</dx:GridViewDataTextColumn>

<dx:GridViewDataComboBoxColumn FieldName="product id" Caption="Product"
ShowInCustomizationForm="True" VisibleIndex="3">
<DataItemTemplate>
<dx:ASPxComboBox ID="cmdProduct" runat="server" DataSourceID="Product" ValueType="System.String"
ValueField="p_pcode" TextField="p_pname" OnInit="cmbProduct_Init" Width="100%" Theme="Material"
IncrementalFilteringDelay="600" CallbackPageSize="20" EnableCallbackMode="true" DropDownStyle="DropDown">
<Border BorderStyle="None" />
</dx:ASPxComboBox>
<asp:SqlDataSource ID="Product" runat="server"
ConnectionString="<%$ ConnectionStrings:BMS %>"
SelectCommand="SELECT [code], [name] FROM [product] WHERE ([status] = @stat) order by [name] asc ">
<SelectParameters>
<asp:Parameter DefaultValue="A" Name="stat" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</DataItemTemplate>
</dx:GridViewDataComboBoxColumn>

<dx:GridViewDataTextColumn FieldName="variation" visible="false"
ShowInCustomizationForm="True" VisibleIndex="4">

</dx:GridViewDataTextColumn>

<dx:GridViewDataComboBoxColumn FieldName="varid" ShowInCustomizationForm="True" Caption="Version"
VisibleIndex="5">
<DataItemTemplate>
<dx:ASPxComboBox ID = "cmbVariant" runat="server" DataSourceID="Variation" ValueType="System.String"
ValueField="v_matid" TextField="v_var" OnInit="cmbVar_Init" Width="100%" Theme="Material"
IncrementalFilteringMode="Contains" IncrementalFilteringDelay="600" CallbackPageSize="20"
EnableCallbackMode="true" DropDownStyle="DropDown">
<Border BorderStyle="None" />
</dx:ASPxComboBox>
<asp:SqlDataSource ID="Var" runat="server"
ConnectionString="<%$ ConnectionStrings:BMS %>"
SelectCommand="SELECT [varid], [varcode], [var] FROM [variant] WHERE (([varcode] = @varcode) AND ([varstat] = @varstat))">
<SelectParameters>
<asp:SessionParameter Name="varcode" DefaultValue="" SessionField="varid" Type="String" />
<asp:Parameter DefaultValue="A" Name="varstat" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</DataItemTemplate>
</dx:GridViewDataComboBoxColumn>


<dx:GridViewDataTextColumn FieldName="place" visible="false"
ShowInCustomizationForm="True" VisibleIndex="8">

</dx:GridViewDataTextColumn>

<dx:GridViewDataComboBoxColumn FieldName="placeid" Caption="Program"
ShowInCustomizationForm="True" VisibleIndex="9">
<DataItemTemplate>
<dx:ASPxComboBox ID="cmbPlace" runat="server" ValueType="System.String" DataSourceID="Place" Theme="Material"
ValueField = "pg_place" TextField="pg_plcname" Width="100%" CssClass="EditDropdown" OnInit="cmbPlace_Init"
IncrementalFilteringMode="Contains" IncrementalFilteringDelay="600" CallbackPageSize="20"
EnableCallbackMode="true" DropDownStyle="DropDown">
<Border BorderStyle="None" />
</dx:ASPxComboBox>
<asp:SqlDataSource ID="Place" runat="server"
ConnectionString="<%$ ConnectionStrings:BMS %>"
SelectCommand="SELECT [pg_plccode], [pg_plcname] FROM [place] WHERE ([stat] = @stat) order by pg_plcname asc">
<SelectParameters>
<asp:Parameter DefaultValue="A" Name="pg_stat" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</DataItemTemplate>
</dx:GridViewDataComboBoxColumn>





<dx:GridViewDataTextColumn FieldName="cost" Caption="Internal Cost"
ShowInCustomizationForm="True" VisibleIndex="12">
<DataItemTemplate>
<dx:ASPxSpinEdit ID="acost" DecimalPlaces="2" DisplayFormatString="N" OnInit="IntCost_Init" Width="100%" Theme="Material"
CssClass="EditDropdown" runat="server" Number=" 0" SpinButtons-ClientVisible="false" AllowMouseWheel="false" HorizontalAlign="Right">
<Border BorderStyle="None" />
</dx:ASPxSpinEdit>
</DataItemTemplate>
</dx:GridViewDataTextColumn>

<dx:GridViewDataTextColumn FieldName="chnfr_rkey" visible="false"
ShowInCustomizationForm="True" VisibleIndex="13">

</dx:GridViewDataTextColumn>

</Columns>
<StylesPager Button-HorizontalAlign="Right" Button-HoverStyle-BackgroundImage-HorizontalPosition="right"></StylesPager>
<Templates>
<PagerBar>
<table width="100%" class="tablebutton_change">
<tr style="float:right;">

<td class = "btn_setting">
<dx:ASPxButton ID="btn_addnew" runat="server" Text="Add new row" Theme="Mulberry" CssClass="btn_change"
AutoPostBack="true" Image-Url="~/images/icons/addnewrow.png" CausesValidation="false"
UseSubmitBehavior="false" OnClick="AddnewClick">
</dx:ASPxButton>
</td>
</tr>
</table>

</PagerBar>
</Templates>
<settingspager AlwaysShowPager="true">
</settingspager>

<SettingsBehavior ProcessSelectionChangedOnServer="True" />
<Styles Header-HorizontalAlign="Center">
<header horizontalalign="Center">
</header>
</Styles>


</dx:ASPxGridView>

后端

Protected Sub AddnewClick(sender As Object, e As System.EventArgs)
Dim cn As New SqlConnection(ConfigurationManager.ConnectionStrings("sales").ConnectionString)
Dim cmd As New SqlCommand
cmd.CommandText = "insert"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cn
cn.Open()
cmd.Parameters.AddWithValue("@idno", Session("idno").ToString)
cmd.Parameters.AddWithValue("@product", DBNull.Value)
cmd.Parameters.AddWithValue("@productid", DBNull.Value)
cmd.Parameters.AddWithValue("@variant", DBNull.Value)
cmd.Parameters.AddWithValue("@varid", DBNull.Value)
cmd.Parameters.AddWithValue("@palce", DBNull.Value)
cmd.Parameters.AddWithValue("@palceid", DBNull.Value)
cmd.Parameters.AddWithValue("@cost", DBNull.Value)
cmd.Parameters.AddWithValue("@date", Date.Today)
cmd.ExecuteNonQuery()
cn.Close()
cmd.Parameters.Clear()

forFromGrid.SelectParameters(0).DefaultValue = Session("idno").ToString
fordtl.SelectParameters(0).DefaultValue = Session("idno").ToString
ASPxGridView1.DataBind()
End Sub

最佳答案

解决方案:您应该从客户端创建空(添加新)行,而不是从服务器端创建。更改前端的按钮代码如下,

    <dx:ASPxButton ID="btn_addnew" runat="server" Text="Add new row"
Theme="Mulberry" CssClass="btn_change" AutoPostBack="false"
Image-Url="~/images/icons/addnewrow.png" CausesValidation="false" UseSubmitBehavior="false">
<ClientSideEvents Click="function(s, e) {
sampleGrid.AddNewRow();
}" />
</dx:ASPxButton>

https://documentation.devexpress.com/AspNet/DevExpress.Web.Scripts.ASPxClientGridView.AddNewRow.method -- 这里解释了如何从客户端动态调用服务器端事件。而不是使用网格命令按钮列选项或默认按钮。

根据我们的聊天讨论,

您似乎正在尝试批量更新。您可以通过两种方式进行批量更新。 1. 单独(CRUD) 2. 一次(批量更新)。

<强>1。单独(CRUD - ASPxGridView RowInserting/RowUpdating/RowDeleting 事件) 如果您想单独提交一批修改,即使用ASPxGridView RowInserting/RowUpdating/RowDeleting 事件

<强>2。一次(批量更新 - ASPxGridView.BatchUpdate 事件): 如果您想一次提交一批修改(ASPxGridView.BatchUpdate 事件),请使用

以上两个过程都解释得很清楚here

希望对你有帮助。

关于javascript - AspxGridview 添加新行并保留最后一行值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45408547/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com