This is a migrated thread and some comments may be shown as answers.

Out of range issue and combobox filter

6 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
grand lorie
Top achievements
Rank 1
grand lorie asked on 09 Apr 2010, 12:49 PM
Hi
can anyone tell me why i am getting this error:
--------------------------------------------------------------
[ArgumentOutOfRangeException: Selection out of range
Parameter name: value]
   Telerik.Web.UI.RadComboBox.PerformDataBinding(IEnumerable dataSource) +259
   Telerik.Web.UI.RadComboBox.OnDataSourceViewSelectCallback(IEnumerable data) +10
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
   Telerik.Web.UI.RadComboBox.OnDataBinding(EventArgs e) +73
   Telerik.Web.UI.RadComboBox.PerformSelect() +21
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   System.Web.UI.Control.DataBindChildren() +211
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.Control.DataBindChildren() +211
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
   System.Web.UI.Control.DataBind() +15
   Telerik.Web.UI.GridItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows) +515
   Telerik.Web.UI.GridTableView.CreateFilteringItem(Boolean useDataSource, GridColumn[] copiedColumnSet, GridTHead thead) +100
   Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +761
   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +495
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
   Telerik.Web.UI.GridTableView.PerformSelect() +4
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   Telerik.Web.UI.GridTableView.DataBind() +221
   Telerik.Web.UI.GridTableView.Rebind() +48
   Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +1019
   Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +134
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   Telerik.Web.UI.GridEditFormItem.OnBubbleEvent(Object source, EventArgs e) +299
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

------------------------------------------------------------------
here is my source code
---------------------------------------------------------------------------
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <table class="style1">
            <tr>
                <td>
                    <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticInserts="True"
                        AllowAutomaticUpdates="True" AllowFilteringByColumn="True" AllowPaging="True"
                        AllowSorting="True" AutoGenerateEditColumn="True" DataSourceID="SqlDataSource1"
                        GridLines="None" ShowFooter="True">
<MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Top" DataKeyNames="CategoryID"
                            DataSourceID="SqlDataSource1">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>

<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
    <Columns>
        <telerik:GridBoundColumn DataField="CategoryID" DataType="System.Int32"
            DefaultInsertValue="" HeaderText="CategoryID" ReadOnly="True"
            SortExpression="CategoryID" UniqueName="CategoryID">
            <HeaderStyle Width="20%" />
        </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="CategoryName" DataField="CategoryName" HeaderText="Category" HeaderStyle-Width="250px">
                        <FilterTemplate>
                            <telerik:RadComboBox ID="RadComboBoxCategory" Width="250" DataSourceID="SqlDataSource2" DataTextField="CategoryName"
                                DataValueField="CategoryName" Height="400px" AppendDataBoundItems="true" SelectedValue='<%# TryCast(Container,GridItem).OwnerTableView.GetColumn("CategoryName").CurrentFilterValue %>'
                                runat="server" OnClientSelectedIndexChanged="CategoryIndexChanged">
                                <Items>
                                    <telerik:RadComboBoxItem Text="All" />
                                </Items>
                            </telerik:RadComboBox>
                            <telerik:RadScriptBlock ID="RadScriptBlock2" runat="server">

                                <script type="text/javascript">
                                    function CategoryIndexChanged(sender, args) {
                                        var tableView = $find("<%# TryCast(Container,GridItem).OwnerTableView.ClientID %>");
                                        tableView.filter("CategoryName", args.get_item().get_value(), "EqualTo");
                                    }
                                </script>

                            </telerik:RadScriptBlock>
                        </FilterTemplate>

<HeaderStyle Width="250px"></HeaderStyle>
                    </telerik:GridBoundColumn>
    </Columns>
</MasterTableView>
                        <ClientSettings>
                            <Selecting AllowRowSelect="True" />
                        </ClientSettings>
                    </telerik:RadGrid>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;</td>
            </tr>
        </table>
    </div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:OrderSystemConn %>"
        DeleteCommand="DELETE FROM [Category] WHERE [CategoryID] = @CategoryID"
        InsertCommand="INSERT INTO [Category] ([CategoryName]) VALUES (@CategoryName)"
        SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Category] ORDER BY [CategoryName]"
        UpdateCommand="UPDATE [Category] SET [CategoryName] = @CategoryName WHERE [CategoryID] = @CategoryID">
        <DeleteParameters>
            <asp:Parameter Name="CategoryID" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="CategoryName" Type="String" />
            <asp:Parameter Name="CategoryID" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="CategoryName" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server"
        ConnectionString="<%$ ConnectionStrings:OrderSystemConn %>"
        SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Category] ORDER BY [CategoryName]">
    </asp:SqlDataSource>
    </form>
--------------------------------------------------------------------------------

Thanks

6 Answers, 1 is accepted

Sort by
0
grand lorie
Top achievements
Rank 1
answered on 13 Apr 2010, 02:04 PM
Hi

I think i found the logic behind the problem and hope this make sense so someone can help.

- The Combobox is working fine as a filter on the grid but for somehow this relation got to break when updating the item.

- So say if i have items list which has A,B,C,D on the filter list (here is RadCombobox) then by selecting the item B, the grid respond by displaying only the rows with item B.

- Now if i click edit to edit item B and change it to B1 then here comes the problem because the B1 is not listed yet on the filter Menu which cause the error i mentioned above when i click update.

so my question here is:

How can i fix this relationship between the filter menu and the updated items.

Thanks
Lorie
0
Mira
Telerik team
answered on 15 Apr 2010, 07:55 AM
Hello Lorie,

I have examined your code and have the following suggestion for you: please handle the SqlDataSource.Updated event of the SqlDataSource and rebind the combo from the filter template in its event handler.
You can see how to get reference to control embedded in the filter template here.

I hope this helps.

Greetings,
Mira
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
grand lorie
Top achievements
Rank 1
answered on 20 Apr 2010, 04:29 PM
Hi Mira

Thanks for your reply but

- The link provided did not help me to solve my problem.

- Can you please tell me what exactly is wrong with the code i am using (this code used in filter example by telerik and should work as it is unless there is something Telerik used with their examples and did not mention it to us!!!!!).

Thanks
0
Mira
Telerik team
answered on 23 Apr 2010, 08:27 AM
Hello Lorie,

I have followed your scenario and prepared a sample project implementing it.
In it, as well as in the FilterTemplates demo, the following code is used to update the combo in the filter template each time the grid is rendered and there is a filter expression:
protected void RadGrid1_PreRender(object sender, System.EventArgs e)
{
    if (RadGrid1.MasterTableView.FilterExpression != string.Empty)
    {
        RefreshCombos();
    }
}
 
protected void RefreshCombos()
{
    SqlDataSource2.SelectCommand = SqlDataSource2.SelectCommand + " WHERE " + RadGrid1.MasterTableView.FilterExpression.ToString();
    RadGrid1.MasterTableView.Rebind();
}

Please take a look at the attachment and let me know if there are any differences at your end which I may be leaving out.

Greetings,
Mira
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
grand lorie
Top achievements
Rank 1
answered on 29 Apr 2010, 03:00 PM
Hi Mira

thanks for your help but when i try to filter i get this error:


Incorrect syntax near the keyword 'WHERE'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'WHERE'.

Source Error:

Line 25:     {
Line 26:         SqlDataSource2.SelectCommand = SqlDataSource2.SelectCommand + " WHERE " + RadGrid1.MasterTableView.FilterExpression.ToString();
Line 27:         RadGrid1.MasterTableView.Rebind();
Line 28:     }
Line 29: 

Source File: c:\WebSite1\Default.aspx.cs    Line: 27

Stack Trace:

[SqlException (0x80131904): Incorrect syntax near the keyword 'WHERE'.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1951450
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4849003
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2394
   System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
   System.Data.SqlClient.SqlDataReader.get_MetaData() +83
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141
   System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
   System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +10
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +130
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +287
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1297
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +19
   Telerik.Web.UI.RadComboBox.OnDataBinding(EventArgs e) +585
   Telerik.Web.UI.RadComboBox.PerformSelect() +21
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   Telerik.Web.UI.RadComboBox.DataBind() +37
   System.Web.UI.Control.DataBindChildren() +211
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.Control.DataBindChildren() +211
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
   System.Web.UI.Control.DataBind() +15
   Telerik.Web.UI.GridItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows) +515
   Telerik.Web.UI.GridTableView.CreateFilteringItem(Boolean useDataSource, GridColumn[] copiedColumnSet, GridTHead thead) +100
   Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +761
   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +495
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
   Telerik.Web.UI.GridTableView.PerformSelect() +16
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   Telerik.Web.UI.GridTableView.DataBind() +221
   Telerik.Web.UI.GridTableView.Rebind() +48
   _Default.RefreshCombos() in c:\WebSite1\Default.aspx.cs:27
   _Default.RadGrid1_PreRender(Object sender, EventArgs e) in c:\WebSite1\Default.aspx.cs:20
   System.Web.UI.Control.OnPreRender(EventArgs e) +8684342
   System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +31
   Telerik.Web.UI.RadCompositeDataBoundControl.OnPreRender(EventArgs e) +12
   System.Web.UI.Control.PreRenderRecursiveInternal() +80
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842

---------------------------------------

Also i ll be very much appriciated if you can tell me what is wrong with the code i was using, could not figure out what is wrong with it.

Thanks

0
Mira
Telerik team
answered on 30 Apr 2010, 03:51 PM
Hello Lorie,

Based on the supplied information, it is hard to determine what is causing the error.
Please open a formal support ticket and sent us a small working project, demonstrating your full setup and showing the unwanted behavior.
We will debug it locally and get back to you.

Sincerely yours,
Mira
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
grand lorie
Top achievements
Rank 1
Answers by
grand lorie
Top achievements
Rank 1
Mira
Telerik team
Share this question
or