【问题标题】:RadGrid not displaying rows in sequence (Insert record sequence)RadGrid 不按顺序显示行(插入记录序列)
【发布时间】:2015-11-26 04:19:45
【问题描述】:

下面是RadGrid的HTML代码:

<telerik:RadGrid ID="RGGSTAcCode" runat="server" AutoGenerateColumns="false"  
                                                                                         ShowFooter="True" GroupingEnabled="False" ShowStatusBar="true"         
                                                                                         AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AllowAutomaticDeletes="true"
                                                                                         OnNeedDataSource= "rggstAcCode_NeedDataSource" OnItemDataBound="rggstAcCode_ItemDataBound"                    
                                                                                         OnInsertCommand="rggstAcCode_InsertCommand" OnDeleteCommand="rggstAcCode_DeleteCommand"
                                                                                         OnUpdateCommand="rggstAcCode_UpdateCommand" OnItemCommand="RGGSTAcCode_ItemCommand"
                                                                                         EnableEmbeddedSkins="true" Skin="Outlook">

                                                                                        <mastertableview commanditemdisplay="Top" autogeneratecolumns="false" datakeynames="AccountCodeID" 
                                                                                            insertitempageindexaction="ShowItemOnCurrentPage" ShowFooter="True" ShowHeadersWhenNoRecords="true">
                                    <CommandItemSettings AddNewRecordText="New" />
                                    <Columns>
                                        <telerik:GridEditCommandColumn UniqueName="imagebutton1" ButtonType="ImageButton"></telerik:GridEditCommandColumn>

                                        <telerik:GridTemplateColumn DataField="in_line" HeaderText="Line Number"> 
                                          <ItemTemplate> 
                                             <asp:Label ID="Label1" runat="server" Text="<%# Container.DataSetIndex+1 %>"></asp:Label> 
                                          </ItemTemplate> 
                                        </telerik:GridTemplateColumn>

                                        <telerik:GridTemplateColumn UniqueName="AccountCode" HeaderText="Account Code">
                                            <ItemTemplate>
                                                <asp:Label ID="lblAcCode" Text='<%# Eval("AccountCode") %>' runat="server"></asp:Label>
                                            </ItemTemplate>
                                            <EditItemTemplate>
                                                <asp:Label ID="lblAcCode2" runat="server" Text='<%# Eval("AccountCode") + " - " + Eval("AccountDescription")%>' Visible="false"></asp:Label>

                                                <telerik:RadComboBox ID="ddlAccountCode" runat="server" Height="200" Width="250" DropDownWidth="350" 
                                                    HighlightTemplatedItems="true" Filter="Contains" AppendDataBoundItems="true" DataTextField="AccountDescription" DataValueField="AccountCodeID"
                                                    OnItemsRequested="ddlAccountCode_ItemsRequested" ItemsPerRequest="50" EnableItemCaching="true"
                                                    AutoPostBack="true" OnSelectedIndexChanged="ddlAccountCode_SelectedIndexChanged"
                                                    EnableLoadOnDemand="True" ShowMoreResultsBox="true" EnableVirtualScrolling="true">
                                                </telerik:RadComboBox>

                                            </EditItemTemplate>
                                        </telerik:GridTemplateColumn>

                                        <telerik:GridBoundColumn DataField="AccountDescription" HeaderText="Description"
                                            UniqueName="AccountDescription" SortExpression="AccountDescription" ReadOnly="True">                                           
                                        </telerik:GridBoundColumn>                                     

                                        <telerik:GridBoundColumn aggregate="SUM" DataFormatString="{0:n}" DataField="Amount" HeaderText="Amount" FooterAggregateFormatString="Total : {0:###,##0.00}" 
                                            UniqueName="Amount" SortExpression="Amount" FooterStyle-BackColor="#ffc04c">
                                            <ItemStyle HorizontalAlign="Left" /> 
                                            <FooterStyle HorizontalAlign="Left" /> 
                                            <ColumnValidationSettings EnableRequiredFieldValidation="true">
                                                <RequiredFieldValidator ForeColor="Red" Text="*This field is required">
                                                </RequiredFieldValidator>
                                            </ColumnValidationSettings>                                            
                                        </telerik:GridBoundColumn>

                                        <telerik:GridBoundColumn DataField="Remark" HeaderText="IFCA Description"
                                            UniqueName="Remark" SortExpression="Remark">
                                            <ItemStyle HorizontalAlign="Left" /> 
                                            <FooterStyle HorizontalAlign="Left" />                                             
                                        </telerik:GridBoundColumn>                                        

                                        <telerik:GridButtonColumn ConfirmTextFormatString="Are you sure you want to Delete Selected Account Code(s)?" ConfirmTextFields="AccountCodeID"
                                         ConfirmDialogType="RadWindow" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" ButtonType="ImageButton"></telerik:GridButtonColumn>
                                    </Columns>

                                    <EditFormSettings>
                                        <EditColumn ButtonType="ImageButton" />
                                    </EditFormSettings>
                                    <PagerStyle AlwaysVisible="True" PageSizeControlType="RadComboBox" />
                                </mastertableview>
                                                                                    </telerik:RadGrid>

在 RadGrid 中显示数据的存储过程:

ALTER PROCEDURE [Invoice].[usp_tbl_AccountCode_Select_Transaction]
    @RequestID nvarchar(50)

AS
BEGIN
    SET NOCOUNT ON;

    Select
        AccountCodeID,
        RequestID,
        AccountCode,
        AccountDescription,
        Amount,
        Remark
    From [Invoice].[tbl_AccountCodeTransaction] (NOLOCK)
    Where RequestID = @RequestID

我在这里观察到的是,如果用户输入以下数量的行:

1) 0.00(第一次插入时,作为第一行)
2) 2,000.00(第二次插入时,作为第二行)行)
3) 6,767.00(当第三次插入时,这将作为第一行(代替成为第三行)
之前的第 1 行将变为第 2 行,之前的第 2 行将变为 作为第 3 行)
4) 56,565.00(当第 4 次插入时,这将作为第 3 行(代替成为第 4 行)
& 2,000.00 将成为第 4 行,& 0.00 将成为第 2 行,& 6,767.00 将保留为第一行。

以下是上述定义问题的快照:

我希望数据应该按顺序显示,当我插入 RadGrid 中的行。即,无论我插入 1st 应该首先显示, 2nd 作为 2nd , 3rd 作为 3rd 等等。不是随机顺序。

我试图把“自动生成行号”,但也 它没有按预期工作。

请让我知道为什么它没有按顺序显示数据?
请回复

【问题讨论】:

  • 您需要以某种方式在数据库中跟踪请求的顺序(例如,将默认为 GETDATE() 的列 DateCreated 添加到 tbl_AccountCodeTransaction) - 否则您的问题出在 SQL 上。 SQL 不保证行的顺序,除非通过存储过程中的 ORDER BY 子句明确指定。见stackoverflow.com/questions/26236352/…
  • 请在您的存储过程中添加 orderby 子句。行号仅在 radgrid 中显示行号,不显示序列详细信息。

标签: asp.net radgrid


【解决方案1】:

我在Select 语句中添加了Order By CreatedDate(这个CreatedDate 列保存了日期和时间)并且它工作正常。非常感谢 @Ondrej Svejdar 和 @Jayesh Goyani 的帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-17
    • 1970-01-01
    • 2017-01-25
    • 1970-01-01
    相关资源
    最近更新 更多