I am receiving an exception whenever i peform any postback on a page with a grid.
I am adding the grid's column in code and also putting the whole grid into edit mode. The datasource is a datatable. I've been using the examples from the tutorials to get started. I also have 2 linkbuttons in the CommandItemTemplate. Whenever i click on either button, i never back it to the ItemCommand, instead i receive an exception:
DotNetNuke.Services.Exceptions.PageLoadException: Specified argument was out of the range of valid values. Parameter name: index ---> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: indexat System.Web.UI.ControlCollection.get_Item(Int32 index)at Telerik.Web.UI.GridTextBoxColumnEditor.LoadControlsFromContainer() ...
I can provide the rest of the stack trace if you need.
here is the ascx code:
| <telerik:RadGrid ID="grdProspects" runat="server" AutoGenerateColumns="false" AllowMultiRowEdit="true"> |
| <ClientSettings EnableRowHoverStyle="true"> |
| <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="400" /> |
| </ClientSettings> |
| <MasterTableView EditMode="InPlace" CommandItemDisplay="TopAndBottom"> |
| <CommandItemStyle Height="25px" HorizontalAlign="Right" /> |
| <CommandItemTemplate> |
| <asp:LinkButton ID="lnkAddProspect" runat="server" CommandName="ADD_PROSPECT"><asp:Image ID="imgAddProspect" runat="server" ImageUrl="~/DesktopModules/BAOffice/images/ADD.gif" ToolTip="Add New Prospect" /> Add New Prospect</asp:LinkButton> |
| |
| <asp:LinkButton ID="lnkSaveProspects" runat="server" CommandName="SAVE_PROSPECTS"><asp:Image ID="Image1" runat="server" ImageUrl="~/DesktopModules/BAOffice/images/save.gif" ToolTip="Save Changes" /> Save Changes</asp:LinkButton> |
| |
| </CommandItemTemplate> |
| </MasterTableView> |
| </telerik:RadGrid> |
| Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
| If Not IsPostBack Then |
| For Each column As SourceColumn In MyProspectEditor.SourceColumns |
| Dim boundColumn As New GridBoundColumn() |
| boundColumn.DataField = column.Name |
| boundColumn.HeaderText = column.Name |
| boundColumn.ReadOnly = column.IsReadOnly |
| grdProspects.MasterTableView.Columns.Add(boundColumn) |
| Next |
| End If |
| End Sub |
| #Region " Prospects " |
| Private Sub grdProspects_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grdProspects.ItemCommand |
| Select Case e.CommandName.ToUpper |
| Case "SAVE_PROSPECTS" |
| Case "ADD_PROSPECT" |
| End Select |
| End Sub |
| Private Sub grdProspects_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grdProspects.NeedDataSource |
| If MyProspectEditor IsNot Nothing Then |
| grdProspects.DataSource = MyProspectEditor.GetWorkingData() |
| End If |
| End Sub |
| Private Sub grdProspects_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdProspects.PreRender |
| If Not IsPostBack Then |
| For Each item As GridItem In grdProspects.MasterTableView.Items |
| If TypeOf item Is GridEditableItem Then |
| Dim editableItem As GridEditableItem = CType(item, GridDataItem) |
| editableItem.Edit = True |
| End If |
| Next |
| grdProspects.Rebind() |
| End If |
| End Sub |
Using this example, I was able to create a working CRUD interface using a SQL view; however, when I added calculated columns to the view, I received the following error.
Sys.WebForms.PageRequestManagerServerErrorException: Update or insert of view or function 'dbo.vwEnum' failed because it contains a derived or constant field.
Here's the table class definition. CreateUser and UpdateUser are the calculated columns, and it works if they are removed. Does anyone know how to prevent the calculated columns from being updated?
| <Table Name="dbo.vwEnum" Member="vwEnums"> |
| <Type Name="vwEnum"> |
| <Column Name="EnumId" Type="System.Int32" DbType="Int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" /> |
| <Column Name="Created" Type="System.DateTime" DbType="DateTime NOT NULL" CanBeNull="false" /> |
| <Column Name="CreateUserId" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" /> |
| <Column Name="Updated" Type="System.DateTime" DbType="DateTime NOT NULL" CanBeNull="false" /> |
| <Column Name="UpdateUserId" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" /> |
| <Column Name="Name" Type="System.String" DbType="VarChar(50) NOT NULL" CanBeNull="false" /> |
| <Column Name="Code" Type="System.String" DbType="VarChar(20) NOT NULL" CanBeNull="false" /> |
| <Column Name="Description" Type="System.String" DbType="VarChar(1000) NOT NULL" CanBeNull="false" /> |
| <Column Name="Attributes" Type="System.Xml.Linq.XElement" DbType="Xml" CanBeNull="true" UpdateCheck="Never" /> |
| <Column Name="CreateUser" Type="System.String" DbType="VarChar(153)" IsReadOnly="true" CanBeNull="true" /> |
| <Column Name="UpdateUser" Type="System.String" DbType="VarChar(153)" IsReadOnly="true" CanBeNull="true" /> |
| <Association Name="vwEnum_vwEnumValue" Member="vwEnumValues" ThisKey="EnumId" OtherKey="EnumId" Type="vwEnumValue" /> |
| </Type> |
| </Table> |
<telerik:RadPanelBar ID="rpbSections" runat="server">
<Items>
<telerik:RadPanelItem runat="server">
<Items>
<telerik:RadPanelItem runat="server">
<ItemTemplate>
<asp:GridView ID="gvPlanContents" runat="server" AutoGenerateColumns="True"
DataKeyNames="PlanContentID" HorizontalAlign="Center" Width="60%" ShowHeader="true"
EmptyDataText="No Data here">
</asp:GridView>
</ItemTemplate>
</telerik:RadPanelItem>
</Items>
</telerik:RadPanelItem>
</Items>
</telerik:RadPanelBar>
My code starts something like this:
List<PlanSections> mySections = PlanSections.GetAllPlanSections();
rpbSections.DataSource = mySections;
rpbSections.DataValueField =
"PlanSectionID";
rpbSections.DataTextField =
"PlanSectionName";
rpbSections.DataBind();
for (int i = 0; i < rpbSections.Controls.Count; i++)
{
int mySectionID = Convert.ToInt32(rpbSections.Items[i].Value);
// what I need to know is, what code do I use to access the gridview. I want to bind it for each
// of its instantiations, by generating an object that depends on the value of MySectionID.
// Where do I go from here?
}
Thanks!
Laurie