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

ELI5 code blocks from RadGrid and RadSearchBox

1 Answer 75 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cholo
Top achievements
Rank 2
Cholo asked on 23 Apr 2016, 03:51 AM

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

1) got this code from the 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;
            RadGrid1.DataBind();
        }
    }
}

2) I added a scenario using the 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)
        RadGrid1.SelectedIndexes.Add(0);
    if (RadGrid2.SelectedIndexes.Count == 0)
    {
        RadGrid2.Rebind();
        RadGrid2.SelectedIndexes.Add(0);
    }
}
 
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    RadGrid2.SelectedIndexes.Clear();
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 27 Apr 2016, 11:07 AM
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.
  

Regards,
Konstantin Dikov
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Cholo
Top achievements
Rank 2
Answers by
Konstantin Dikov
Telerik team
Share this question
or