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

OpenAccessLinqDataSource filtering with radtreeview.SelectedValue(multiple results)

4 Answers 84 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Cuneyt
Top achievements
Rank 1
Cuneyt asked on 20 Jan 2014, 12:10 PM
Hi.
I have radtreeview1 (CheckBoxes=true,CheckChildNodes=true, TriStateCheckBoxes=true) and  I am filtering OpenAccessLinqDataSource with this radtreeview1.SelectedValue.
But there are multiple selected value of radtreeview and this give me an error.
How can i filter to OpenAccessLinqDataSource with control.SelectedValue (multiple value).


This error solved:Error is something like that : system.web.query.dynamic.parseexception: '==' operator incompatible with operand types 'int32?' and 'object'. Solution:OADLSSoruTV.Where = "KategoriId ==Int32?(@KategoriId)";


But i cant solved the filter problem yet.
Thanks.

4 Answers, 1 is accepted

Sort by
0
Cuneyt
Top achievements
Rank 1
answered on 20 Jan 2014, 09:58 PM
i tried this in both selecting event and buttonclick event but no result.
selecting event:
protected void OADLSCSoru_Selecting(object sender, Telerik.OpenAccess.Web.OpenAccessLinqDataSourceSelectEventArgs e)
        {
            
            OADLSSoruTV.WhereParameters.Clear();
            IList<RadTreeNode> nodeCollection = tvKat.CheckedNodes;
            foreach (RadTreeNode node in nodeCollection)
            {
                OADLSSoruTV.Where = "KategoriId ==Int32?(@KategoriId)";
                //i want to add every node.index to OADLSSoruTV 's
                       //where parameter as kategoriId=1,2,4 check nodes
                //but actually i dont what i am doing here.
                OADLSSoruTV.WhereParameters.Add("KategoriId",
                                 TypeCode.Int32,
                                 node.Value.ToString());
            }
               OADLSSoruTV.DataBind();
                

        }

button click event

protected void button1_Click(object sender, EventArgs e)
        {
             
            OADLSSoruTV.WhereParameters.Clear();
            IList<RadTreeNode> nodeCollection = tvKat.CheckedNodes;
            foreach (RadTreeNode node in nodeCollection)
            {
                OADLSSoruTV.Where = "KategoriId ==Int32?(@KategoriId)";
                //i want to add every node.index to OADLSSoruTV 's
                       //where parameter as kategoriId=1,2,4 check nodes
                //but actually i dont what i am doing here.
                OADLSSoruTV.WhereParameters.Add("KategoriId",
                                                       TypeCode.Int32,
                                                       node.Value.ToString());
            }
               OADLSSoruTV.DataBind();
                 
        }

0
Doroteya
Telerik team
answered on 23 Jan 2014, 01:04 PM
Hi Cuneyt,

Thank you for the additional information.

In general, you can execute the described scenario with OpenAccessLinqDataSource, although in this case you will need to use the events it exposes rather then Linq DataSource Configuration Wizard. If you find this feasible, I would suggest to you to enhance the Selecting event in a way that adds a new parameter to the datasource's collection of Where parameters as well as a new condition to the where clause for each of the checked nodes in RadTreeView. As a guide line, you can use the following code snippet:
protected void oaLinqDataSource_Selecting(object sender, Telerik.OpenAccess.Web.OpenAccessLinqDataSourceSelectEventArgs e)
{
    IList<RadTreeNode> nodes = this.rtView.CheckedNodes;
    string whereClause = null;
 
    for (int i = 0; i < nodes.Count; i++)
    {
        string parameterName = "CategoryID" + i.ToString();
        int paramterValue = 0;
        Int32.TryParse(nodes[i].Value, out paramterValue);
 
        e.WhereParameters.Add(parameterName, paramterValue);
 
        if (whereClause == null)
        {
            whereClause = "CategoryID == @" + parameterName;
        }
        else
        {
            whereClause += " || CategoryID == @" + parameterName;
        }
    }
 
    this.oaLinqDataSource.Where = whereClause;
}

I hope this helps. If you have additional questions, or need further assiatance, do not hesitate to get back to us.


Regards,
Doroteya
Telerik
OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features shipped with our latest release!
0
Cuneyt
Top achievements
Rank 1
answered on 23 Jan 2014, 03:17 PM
Hi Doroteya.
Thank you very much. it worked. but i put this code into button click event because my selecting event fires only first page load. it is normal?
final code with little change as you mention:
protected void button1_Click(object sender, EventArgs e)
        {
             IList<RadTreeNode> nodes = this.rtView.CheckedNodes;
    string whereClause = null;
 
    for (int i = 0; i < nodes.Count; i++)
    {
        //string parameterName = "CategoryID" + i.ToString();
        int paramterValue = 0;
        Int32.TryParse(nodes[i].Value, out paramterValue);
 
        //e.WhereParameters.Add(parameterName, paramterValue);
 
        if (whereClause == null)
        {
            whereClause = "CategoryID == " + paramterValue;      //parameterName;
        }
        else
        {
            whereClause += " || CategoryID == " +paramterValue;   //parameterName;
        }
    }
 
    this.oaLinqDataSource.Where = whereClause;
 
                  
        }

Thank you.
0
Boyan
Telerik team
answered on 28 Jan 2014, 12:37 PM
Hi Cuneyt,

Generally the OpenAccessLinqDataSource Selecting event occurs before a select statement is executed. This could be just before the list control is populated when the page loads. 
If this is not applicable for your implementation scenario and you prefer filtering to happen on button click (or another) event it is a valid approach to perform filtering on that event.

Should you have any further questions, do not hesitate to contact us. 

Regards,
Boyan
Telerik
OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features shipped with our latest release!
Tags
Getting Started
Asked by
Cuneyt
Top achievements
Rank 1
Answers by
Cuneyt
Top achievements
Rank 1
Doroteya
Telerik team
Boyan
Telerik team
Share this question
or