Saurabh Srivastava
Top achievements
Rank 1
Saurabh Srivastava
asked on 25 Aug 2009, 01:58 PM
Hi,
Since I modified my needdatasourceevent to
my grid started behaving strangely or sort/filter operations. Sometimes it does not show up any record, and sometimes it comes up with an error message of "Index 10 is either negative or above rows count". I am using RadControls v 2009.1.402.20.
Any help?
Regards,
Saurabh
Since I modified my needdatasourceevent to
protected void rgMissingJourneys_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
DataTable gridDataTable = GetData();
rgMissingJourneys.DataSource = gridDataTable.Select(
"update_ind = 0");
}
my grid started behaving strangely or sort/filter operations. Sometimes it does not show up any record, and sometimes it comes up with an error message of "Index 10 is either negative or above rows count". I am using RadControls v 2009.1.402.20.
Any help?
Regards,
Saurabh
4 Answers, 1 is accepted
0
Hello Saurabh,
Your event handler seems to be fine. Make sure that the problem is not coming from somewhere else. To be able to assist you, consider pasting some source code(markup) we can examine.
Kind regards,
Veli
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Your event handler seems to be fine. Make sure that the problem is not coming from somewhere else. To be able to assist you, consider pasting some source code(markup) we can examine.
Kind regards,
Veli
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Saurabh Srivastava
Top achievements
Rank 1
answered on 28 Aug 2009, 02:44 PM
Hi,
I am pretty certain that this is causing the issue. I also looked at some forums here which suggested that using Select in the NeedDataSourceEvent causes the issue.
In any case, here is my entire code
I am pretty certain that this is causing the issue. I also looked at some forums here which suggested that using Select in the NeedDataSourceEvent causes the issue.
In any case, here is my entire code
| <%@ Page Language="C#" MasterPageFile="~/RmsMasterPage.master" AutoEventWireup="true" CodeFile="Custom.aspx.cs" |
| Inherits="Custom" Title="Missing Journeys" %> |
| <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> |
| <telerik:RadCodeBlock ID ="RadCodeBlock1" runat="server"> |
| <script type="text/javascript"> |
| </script> |
| </telerik:RadCodeBlock> |
| <table align="center" width="100%"> |
| <tr> |
| <td align="left"> |
| <asp:Label ID="lblHeader" CssClass = "contentHeading" runat="server" Text="Actualised Journeys with No Grades"></asp:Label> |
| <img src="images/SeperatorNew.png" width="1220"/> |
| <asp:HiddenField ID="hfVoyageSeq" runat="server" /> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="rgMissingJourneys"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="rgMissingJourneys" LoadingPanelID="RadAjaxLoadingPanel1" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManager> |
| <telerik:RadGrid ID="rgMissingJourneys" runat="server" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" |
| AutoGenerateColumns="False" AutoGenerateDeleteColumn="False" AutoGenerateEditColumn="False" GridLines="None" Skin="Custom" |
| OnNeedDataSource="rgMissingJourneys_NeedDataSource" OnItemDataBound="rgMissingJourneys_ItemDataBound" AllowAutomaticUpdates="false" |
| EnableEmbeddedSkins="false" AllowMultiRowEdit="true" AllowMultiRowSelection="true" OnItemCommand="rgMissingJourneys_ItemCommand" OnPreRender="rgMissingJourneys_PreRender" OnDataBound="rgMissingJourneys_DataBound"> |
| <MasterTableView EditMode="InPlace" TableLayout="Auto" DataKeyNames="voyage_seq" CommandItemDisplay="Bottom" CommandItemStyle-Height="30" CommandItemStyle-HorizontalAlign="Right"> |
| <Columns> |
| <telerik:GridBoundColumn UniqueName="VoyageSequence" HeaderText = "Voyage Sequence" DataField = "voyage_seq" AllowFiltering="false" AllowSorting="false" HeaderStyle-Width="50" ReadOnly="true"></telerik:GridBoundColumn> |
| <telerik:GridBoundColumn UniqueName="ShipName" HeaderText = "Ship Name" DataField = "voyage_ship_full_nm" HeaderStyle-Width="120" ReadOnly="true"></telerik:GridBoundColumn> |
| <telerik:GridBoundColumn UniqueName="Year" HeaderText = "Year" DataField = "voyage_year_num" HeaderStyle-Width="80" ReadOnly="true" FilterControlWidth="40" ></telerik:GridBoundColumn> |
| <telerik:GridBoundColumn UniqueName="StartPort" HeaderText = "Start Port" DataField = "start_port" HeaderStyle-Width="120" ReadOnly="true"></telerik:GridBoundColumn> |
| <telerik:GridBoundColumn UniqueName="EndPort" HeaderText = "End Port" DataField = "end_port" HeaderStyle-Width="120" ReadOnly="true"></telerik:GridBoundColumn> |
| <telerik:GridDropDownColumn UniqueName = "CargoType" DataField="grades" HeaderText = "Cargo Type" AllowFiltering ="false" AllowSorting="false" ListTextField="CargoTypeName" ListValueField="CargoTypeId"></telerik:GridDropDownColumn> |
| </Columns> |
| <RowIndicatorColumn> |
| <HeaderStyle Width="20px" /> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn> |
| <HeaderStyle Width="20px" /> |
| </ExpandCollapseColumn> |
| <CommandItemTemplate> |
| <asp:LinkButton ID="lnkUpdate" runat="server" CommandName="Update" > |
| <img style="border:0px;vertical-align:middle;" alt="" src="images/Update.gif" />Upload Records |
| </asp:LinkButton> |
| <asp:LinkButton ID="lnkRefresh" runat="server" CommandName="Refresh"> |
| <img style="border:0px;vertical-align:middle;" alt="" src="images/Refresh.gif"/>Refresh |
| </asp:LinkButton> |
| </CommandItemTemplate> |
| </MasterTableView> |
| <ClientSettings> |
| </ClientSettings> |
| </telerik:RadGrid> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <asp:Label ID="lblRecordsInserted" runat="server" Text="" CssClass="successmessage" style="display:none"></asp:Label> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <asp:Label ID="lblRecordsFailed" runat="server" Text="" CssClass="errormessage" style="display:none"></asp:Label> |
| </td> |
| </tr> |
| </table> |
| <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" CssClass="loadingPanel" Transparency="50"> |
| </telerik:RadAjaxLoadingPanel> |
| </asp:Content> |
| using System; |
| using System.Collections; |
| using System.Data; |
| using System.Configuration; |
| using System.Collections.Generic; |
| using System.Data.SqlClient; |
| using System.Web.UI; |
| using System.Web.UI.WebControls; |
| using Rms.Entity; |
| using Rms.Calculations; |
| using Rms.Services; |
| using Telerik.Web.UI; |
| public partial class Custom : Page |
| { |
| private IReportService service; |
| private IList<CargoType> cargoTypeList; |
| private static string connectionString; |
| readonly IAdminDataService dataService = new AdminDataService(); |
| private string requestDataValidationMessageString = string.Empty; |
| private string errorString; |
| private bool inErrorInd; |
| private bool rerunFinancialCalc; |
| private DateTime lastUpdtDtm; |
| int numberOfVoyagesAnalysed = 0; |
| int numberOfVoyageFailed = 0; |
| private string gridMessage = null; |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| service = new ReportService(); |
| string appScope = ConfigurationManager.AppSettings[CommonConstants.ApplicationConfigScope]; |
| if (appScope.ToUpper().Equals(CommonConstants.LIVE)) |
| { |
| connectionString = CommonConstants.LiveConnectionString; |
| } |
| else if (appScope.ToUpper().Equals(CommonConstants.TEST)) |
| { |
| connectionString = CommonConstants.TestConnectionString; |
| } |
| else if (appScope.ToUpper().Equals(CommonConstants.DEV)) |
| { |
| connectionString = CommonConstants.DevConnectionString; |
| } |
| if(!IsPostBack) |
| { |
| try |
| { |
| cargoTypeList = service.GetCargoTypeNames(); |
| ViewState[CommonConstants.CARGOTYPE] = cargoTypeList; |
| } |
| catch |
| { |
| Response.Redirect(CommonConstants.ERRORPAGE); |
| } |
| } |
| else |
| { |
| cargoTypeList = (IList<CargoType>)ViewState[CommonConstants.CARGOTYPE]; |
| } |
| } |
| protected void PopulateCargoType(DropDownList cmbCargoType) |
| { |
| if (cmbCargoType != null) |
| { |
| cmbCargoType.DataSource = cargoTypeList; |
| cmbCargoType.DataValueField = CargoType.Binding.CargoTypeId; |
| cmbCargoType.DataTextField = CargoType.Binding.CargoTypeName; |
| cmbCargoType.DataBind(); |
| cmbCargoType.Width = 175; |
| } |
| } |
| private bool InvokeRmsAnalysisService(ParentData ParentData, ChildData[] childData, DateTime voyageStartDate, DateTime voyageEndDate, string attachedFixtures, out string reasonForFailure) |
| { |
| //Some code |
| } |
| private bool ValidateRequestData(ParentData ParentData, ChildData[] ChildData) |
| { |
| //Some code |
| } |
| public bool UpdateVoyageRecord(DateTime voyageStartDate, DateTime voyageEndDate, string attachedFixtures, int catVoyageNumber) |
| { |
| //Some code |
| } |
| public bool UpdateAuditRecord(int voyageSequence, bool inErrorInd, bool rerunFinCalc, DateTime lastUpdtDtm, string errorString) |
| { |
| //Some Code |
| } |
| protected static ParentData PrepareParentData(int voyageSeq) |
| { |
| //Some Code |
| } |
| private static DataSet FetchVoyage(int voyageSeq) |
| { |
| //Some code |
| } |
| public ChildData[] PreparChildData(int voyageSequence, int cargoTypeId, out DateTime voyageStartDateTime, out DateTime voyageEndDateTime) |
| { |
| //Some code |
| } |
| private static DataSet FetchPortCallData(int voyageSequence) |
| { |
| //Some Code |
| } |
| protected void rgMissingJourneys_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
| { |
| GridEditableItem editedItem = e.Item as GridEditableItem; |
| if (editedItem != null) |
| { |
| GridEditManager editMan = editedItem.EditManager; |
| GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("CargoType")); |
| editor.DataSource = cargoTypeList; |
| editor.DataBind(); |
| editor.ComboBoxControl.Items.Insert(0, new RadComboBoxItem("Please select", "0")); |
| if (DataBinder.Eval(editedItem.DataItem, "grades") != DBNull.Value) |
| { |
| editor.SelectedValue = (string) DataBinder.Eval(editedItem.DataItem, "grades"); |
| } |
| } |
| } |
| protected void rgMissingJourneys_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
| { |
| DataTable gridDataTable = GetData(); |
| rgMissingJourneys.DataSource = gridDataTable.Select("update_ind = 0"); |
| } |
| private DataTable GetData() |
| { |
| //Some code |
| } |
| protected void rgMissingJourneys_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| foreach (GridEditableItem item in rgMissingJourneys.EditItems) |
| { |
| UpdateRecord(item); |
| } |
| if(e.CommandName == "Update") |
| { |
| RunAnalysis(GetData()); |
| e.Item.OwnerTableView.Rebind(); |
| SetMessage("Records Inserted : " + numberOfVoyagesAnalysed); |
| } |
| return; |
| } |
| private void RunAnalysis(DataTable dataTable) |
| { |
| foreach (DataRow missingDataRecord in dataTable.Rows) |
| { |
| if (missingDataRecord["grades"] != DBNull.Value && Convert.ToInt32(missingDataRecord["grades"]) > 0 && Convert.ToInt32(missingDataRecord["update_ind"]) == 0) |
| { |
| DateTime voyageStartDateTime; |
| DateTime voyageEndDateTime; |
| string reasonForFailure; |
| ParentData ParentData = PrepareParentData(Convert.ToInt32(missingDataRecord["voyage_seq"])); |
| ChildData[] childData = PrepareChildData(Convert.ToInt32(missingDataRecord["voyage_seq"]), Convert.ToInt32(missingDataRecord["grades"]), out voyageStartDateTime, out voyageEndDateTime); |
| if (InvokeRmsAnalysisService(ParentData, childData, voyageStartDateTime, voyageEndDateTime, missingDataRecord["fixture_seqs"].ToString(), out reasonForFailure)) |
| { |
| missingDataRecord["update_ind"] = 1; |
| numberOfVoyagesAnalysed++; |
| missingDataRecord.AcceptChanges(); |
| } |
| else |
| numberOfVoyageFailed++; |
| } |
| } |
| } |
| private void UpdateRecord(GridEditableItem item) |
| { |
| DataTable missingRecords = GetData(); |
| //Locate the changed row in the DataSource |
| DataRow[] changedRows = missingRecords.Select("voyage_seq = '" + item.GetDataKeyValue("voyage_seq") + "'"); |
| if (changedRows.Length != 1) |
| { |
| return; |
| } |
| //Update new values |
| Hashtable newValues = new Hashtable(); |
| //The GridTableView will fill the values from all editable columns in the hash |
| item.OwnerTableView.ExtractValuesFromItem(newValues, item); |
| DataRow changedRow = changedRows[0]; |
| changedRow.BeginEdit(); |
| foreach (DictionaryEntry entry in newValues) |
| { |
| changedRow[(string)entry.Key] = entry.Value; |
| } |
| changedRow.EndEdit(); |
| } |
| protected void rgMissingJourneys_PreRender(object sender, EventArgs e) |
| { |
| foreach (GridDataItem item in rgMissingJourneys.Items) |
| { |
| item.Edit = true; |
| } |
| rgMissingJourneys.Rebind(); |
| } |
| protected void rgMissingJourneys_DataBound(object sender, EventArgs e) |
| { |
| if (!string.IsNullOrEmpty(gridMessage)) |
| { |
| DisplayMessage(gridMessage); |
| } |
| } |
| private void DisplayMessage(string text) |
| { |
| rgMissingJourneys.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>{0}</span>", text))); |
| } |
| private void SetMessage(string message) |
| { |
| gridMessage = message; |
| } |
| } |
0
Saurabh Srivastava
Top achievements
Rank 1
answered on 01 Sep 2009, 08:23 AM
Hi,
Any updates on this please?
Regards,
Saurabh
Any updates on this please?
Regards,
Saurabh
0
Hi Saurabh,
I tested the given sample markup in a project with modified data and it is working OK. You can double check to make sure this is not a data source issue. You can try binding to different data and see how RadGrid behaves.
If the problem continues, consider opening a regular support ticket where you can send a stripped down runnable project we can test, so that we can assist you better.
All the best,
Veli
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I tested the given sample markup in a project with modified data and it is working OK. You can double check to make sure this is not a data source issue. You can try binding to different data and see how RadGrid behaves.
If the problem continues, consider opening a regular support ticket where you can send a stripped down runnable project we can test, so that we can assist you better.
All the best,
Veli
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.