OpenAccessLinqDataSource filtering with radtreeview.SelectedValue(multiple results)

5 posts, 0 answers
  1. Cuneyt
    Cuneyt avatar
    36 posts
    Member since:
    Dec 2011

    Posted 20 Jan 2014 Link to this post

    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.
  2. Cuneyt
    Cuneyt avatar
    36 posts
    Member since:
    Dec 2011

    Posted 20 Jan 2014 Link to this post

    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();
                     
            }

  3. DevCraft banner
  4. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 23 Jan 2014 Link to this post

    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!
  5. Cuneyt
    Cuneyt avatar
    36 posts
    Member since:
    Dec 2011

    Posted 23 Jan 2014 Link to this post

    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.
  6. Boyan
    Admin
    Boyan avatar
    100 posts

    Posted 28 Jan 2014 Link to this post

    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!
Back to Top
DevCraft banner