|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
argumentoutofrangeexception using detailsviewHi,
I'm using the detailsview web control with template fields and object datasource. The fields are bound to the data using the Bind() method. I'm getting an argumentoutofrange exception when the object datasource returns a arraylist with no elements/items. It is not displaying the "emptydatatemplate" content. It displays the "emptydatatemplate" content when I change the template fields to bound fields (i.e not using the bind method). Is this a bug or am I missing something here? Any help is appreciated. I'm using .Net 2.0 Framework, Visual Studio 2005 and C#. Thanks Hi,
Thanks for posting! From your description, I have performed the test. In my sample, whether the arraylist is empty or not, there is no exception to be thrown. >"The fields are bound to the data using the Bind() method.". I'm sorry I don't understand this clearly. I post the demo here. Could you please modify as your scenario and repost it here. This will make me understand the issue very well and repro the problem. I appreciate your understanding! I'm looking forward your reply. Regards, Yuan Ren [MSFT] Microsoft Online Support The following is the page content and exception stacktrace. It should give
you the required info. Please let me know if you need any other info. ..aspx page content: ------------------------ <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="ObjectDataSource1" OnItemInserted="DetailsView1_ItemInserted" OnModeChanging="DetailsView1_ModeChanging" OnItemUpdated="DetailsView1_ItemUpdated" DataKeyNames="CodeID" SkinID="DetailsViewSkin" OnItemCreated="DetailsView1_ItemCreated"> <Fields> <asp:TemplateField HeaderText="Code Group" AccessibleHeaderText="Code Group (Required)"> <EditItemTemplate> <asp:RequiredFieldValidator ID="rfvCodeGroup" runat="server" ControlToValidate="txtCodeGroup" Display="None" EnableClientScript="False" ErrorMessage="Code Group cannot be empty"></asp:RequiredFieldValidator> <asp:TextBox ID="txtCodeGroup" runat="server" Text='<%# Bind("CodeGroup") %>' CssClass="txtbox_uc_required" Columns="30" MaxLength="30"></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:CommandField ShowInsertButton="True" AccessibleHeaderText="Click the links to Insert or Update or Cancel" ButtonType="Button" InsertText="Save" UpdateText="Save" > <ControlStyle CssClass="btn" /> </asp:CommandField> </Fields> <EmptyDataTemplate> <table cellpadding="1" cellspacing="1" border="0" style="border:solid 1px #c0c0c0;background-color:#ffffc0;"> <tr><td><img src="Images/attention.gif" alt="Attention" /></td> <td align="left" colspan="2" style="height:20px;color:red;"><b>Page contains no data.</b></td></tr> </table> </EmptyDataTemplate> </asp:DetailsView> <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" InsertMethod="InsertCode" SelectMethod="GetCode" TypeName="BusinessLogicLayer.AppCode" UpdateMethod="UpdateCode"> <UpdateParameters> <asp:Parameter Name="CodeID" Type="Int32" /> <asp:Parameter Name="CodeGroup" Type="String" /> </UpdateParameters> <SelectParameters> <asp:QueryStringParameter Name="CodeID" QueryStringField="id" Type="Int32" /> </SelectParameters> <InsertParameters> <asp:Parameter Name="CodeGroup" Type="String" /> </InsertParameters> </asp:ObjectDataSource> Stack Trace: -------------- [ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index] System.Web.UI.ControlCollection.get_Item(Int32 index) +2057582 System.Web.UI.WebControls.TableCellCollection.get_Item(Int32 index) +24 System.Web.UI.WebControls.DetailsView.ExtractRowValues(IOrderedDictionary fieldValues, Boolean includeReadOnlyFields, Boolean includeKeys) +345 System.Web.UI.WebControls.DetailsView.PerformDataBinding(IEnumerable data) +86 System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +111 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +29 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70 System.Web.UI.WebControls.DetailsView.DataBind() +4 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82 System.Web.UI.WebControls.DetailsView.EnsureDataBound() +181 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69 System.Web.UI.Control.EnsureChildControls() +87 System.Web.UI.Control.PreRenderRecursiveInternal() +41 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360 ""Yuan Ren[MSFT]"" wrote: Show quoteHide quote > Hi, > > Thanks for posting! > > From your description, I have performed the test. In my sample, whether the > arraylist is empty or not, there is no exception to be thrown. > > >"The fields are bound to the data using the Bind() method.". > I'm sorry I don't understand this clearly. I post the demo here. Could you > please modify as your scenario and repost it here. This will make me > understand the issue very well and repro the problem. I appreciate your > understanding! > > I'm looking forward your reply. > > Regards, > > Yuan Ren [MSFT] > Microsoft Online Support The default mode of the detailsview is set to "edit" mode. It looks like this
is causing the problem. The error does occur when the default mode is set to "readonly" mode and the arraylist is empty. I would like to set the detailsview default mode depending on the arraylist. How do I do this? Should I use the "selected" event of the datasource? Thanks ""Yuan Ren[MSFT]"" wrote: Show quoteHide quote > Hi, > > Thanks for posting! > > From your description, I have performed the test. In my sample, whether the > arraylist is empty or not, there is no exception to be thrown. > > >"The fields are bound to the data using the Bind() method.". > I'm sorry I don't understand this clearly. I post the demo here. Could you > please modify as your scenario and repost it here. This will make me > understand the issue very well and repro the problem. I appreciate your > understanding! > > I'm looking forward your reply. > > Regards, > > Yuan Ren [MSFT] > Microsoft Online Support Sorry. The error does NOT occur when the arraylist is empty and defaultmode
is readonly. ""Yuan Ren[MSFT]"" wrote: Show quoteHide quote > Hi, > > Thanks for posting! > > From your description, I have performed the test. In my sample, whether the > arraylist is empty or not, there is no exception to be thrown. > > >"The fields are bound to the data using the Bind() method.". > I'm sorry I don't understand this clearly. I post the demo here. Could you > please modify as your scenario and repost it here. This will make me > understand the issue very well and repro the problem. I appreciate your > understanding! > > I'm looking forward your reply. > > Regards, > > Yuan Ren [MSFT] > Microsoft Online Support Hi,
I am still doing some research for the current issue. I'll reply you ASAP when I get some result. Thanks for your patience! Regards, Yuan Ren [MSFT] Microsoft Online Support Hi,
Thanks for your patience! I have performed the test. In my opinion, the current issue is by design. If you switch to the bound field, the issue is handled at the binding time. However, if you change to template field, you have to capture the exception manually since the binding is different. So, I suggest you capture the exception manually and perform the related manipulation. Thanks for your understanding! Regards, Yuan Ren [MSFT] Microsoft Online Support Which event should I use to catch this exception? Should I use the
detailsview events or the objectdatasource events? Would you please give me some sample? I tried using the detailsview databinding event but could not figure out how to catch the exception. If you look at the stacktrace, the exception was thrown from the System.Web.UI... classes. Thanks MT ""Yuan Ren[MSFT]"" wrote: Show quoteHide quote > Hi, > > Thanks for your patience! > > I have performed the test. In my opinion, the current issue is by design. > If you switch to the bound field, the issue is handled at the binding time. > However, if you change to template field, you have to capture the exception > manually since the binding is different. So, I suggest you capture the > exception manually and perform the related manipulation. > > Thanks for your understanding! > > Regards, > > Yuan Ren [MSFT] > Microsoft Online Support > > Hi MT,
Thanks for your patience! I'm sorry that I have performed a mismatch sample from the current issue. In your code, I find you bind the "CodeGroup" to a textbox control. So, could you please let me know the type of the "CodeGroup"? I just bind the ArrayList to the DetailViews control directly. My sample is very simple like below: public class ObjectDataSourceClass { public ArrayList getCollection() { ArrayList ary = new ArrayList(4); ary.Add("Tom"); // do more work return ary; } } Based on my experience, the type of the "CodeGroup" is not the ArrayList. If my idea is correct, I think the current issue is not caused by the ArrayList. From the error message, I think the index is zero and there is no index for the ArrayList actually. I understand my explanation is not very exactly. So, could you please make a simple demo and send it to me. This will help me to understand your issue very clearly. Also, I can perform some related researching. I understand this will bring some inconvenience to you. However, it is very important to me. I'm really sorry for inconvenience. I hope you will forgive me. My alias is v-y***@online.microsoft.com (remove .online). Please send the demo as zipped to me directly. I appreciate your understanding! I'm looking forward your reply. Regards, Yuan Ren [MSFT] Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
RadioButtonList, MultiView, and JavaScript
formview with objectDataSource won't display data Web UserControl DropDownlist control event not working... DropDownList select: first visible a label, then post back bug with gridview.selectedvalue? How to refresh a dropdownlist inside a DetailsView? Create a word like doc from C#.NET Passing values between user controls in separate forms Menu control MenuItemClick does not fire. GridView W/Drop Down List Question |
|||||||||||||||||||||||