ELI5 code blocks from RadGrid and RadSearchBox

2 posts, 1 answers
  1. Cholo
    Cholo avatar
    14 posts
    Member since:
    Mar 2016

    Posted 22 Apr 2016 Link to this post

    I need help understanding a couple of code blocks i got from the demo but it works 

    1) got this code from the searchbox demo. It works. I just don't understand how it works. What does the Dictionary does (ELI5)

    protected void RadSearchBox1_Search(object sender, SearchBoxEventArgs e)
        RadSearchBox searchBox = (RadSearchBox)sender;
        string JobOrderNumber = string.Empty;
        string likeCondition;
        if (e.DataItem != null)
            JobOrderNumber = ((Dictionary<string, object>)e.DataItem)["JobOrderNumber"].ToString();
            if (!string.IsNullOrEmpty(JobOrderNumber))
                likeCondition = string.Format("'{0}{1}%'", searchBox.Filter == SearchBoxFilter.Contains ? "%" : "", ((Dictionary<string, object>)e.DataItem)["JobOrderNumber"].ToString());
                SqlDataSource1.SelectCommand = "SELECT [JobOrderIndex], [JobOrderNumber], [JobOrderDate], [JobOrderStatus], [ProfitCenter], [JobType]" + "FROM[Bak-JobOrder] WHERE [" + searchBox.DataValueField + "] LIKE " + likeCondition;

    2) I added a radgrid scenario using the telerik UI in visual studio. I Master/Detail scenario which is similar to this demo.

    What does this code do?


    protected void Page_PreRender(object sender, EventArgs e)
        if (RadGrid1.SelectedIndexes.Count == 0)
        if (RadGrid2.SelectedIndexes.Count == 0)
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)

  2. Answer
    Konstantin Dikov
    Konstantin Dikov avatar
    2087 posts

    Posted 27 Apr 2016 Link to this post

    Hi Cholo,

    The Dictionary from the first code snippet is used for casting the DataItem from the event argument, so the "JobOrderNumber" value could be retrieved.

    The second code snippet selects the first items of the RadGrid controls in the PreRender event handler and clears the selection within the OnItemCommand event.

    Hope this helps.

    Konstantin Dikov
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top