Telerik Forums
UI for ASP.NET AJAX Forum
2 answers
404 views
Hi

On page load I want to set one of the custom filters if querystring has a value.  I am getting an exception (no items in collection) in my CombineFilters method on line

GridFilteringItem filterItem = grdParts.MasterTableView.GetItems(GridItemType.FilteringItem)[0] as GridFilteringItem;

I believe this is mostly about the order I am doing things in (page load running before filter pre render event) 
but I am not sure how to modify the code to get this working. 

Code attached below

Check QueryString, if company passed in have the filter preselected
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        BindGrid();
    }
 
    //if (querystring has value)
    //{
        ViewState["CompanyFilterVal"] = "123";
        CombineFilters();
    //}
}

Setting the filter dropdown values on grid item created event
//Item created - binding data to custom company filter 
protected void grdParts_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridFilteringItem)
    {
        try
        {
            using (MyEntities db = new MyEntities())
            {
                //Set options for the filter controls
                GridFilteringItem filterItem = (GridFilteringItem)e.Item;
 
                RadComboBox CompanyCbo = (RadComboBox)filterItem["Company"].FindControl("cboFilterCompany");
                BindCompanyFilterData(db, CompanyCbo);
 
                //...other filters
        }
        catch (Exception ex)
        {
            ...
        }
    }
}

setting selected value on filter pre render event. 
protected void cboFilterCompany_PreRender(object sender, EventArgs e)
{
    RadComboBox combo = sender as RadComboBox;
    if (ViewState["CompanyFilterVal"] != null)
        combo.SelectedValue = ViewState["CompanyFilterVal"].ToString();
    else
        combo.ClearSelection();
}

method inspects all filters for value and sets grid filter based on filters
protected void CombineFilters()
{
    string filterToApply = "";
    List<string> filtexprn = new List<string>();
 
    ClearFilterFromViewState();
 
    GridFilteringItem filterItem = grdParts.MasterTableView.GetItems(GridItemType.FilteringItem)[0] as GridFilteringItem;
 
    //COMPANY
    RadComboBox cboCompany = (RadComboBox)filterItem.FindControl("cboFilterCompany");
    if (cboCompany.SelectedIndex != -1)
    {
        if(cboCompany.SelectedValue != "All")
        {
            filtexprn.Add("([Company] ='" + cboCompany.SelectedValue + "')");
            ViewState["CompanyFilterVal"] = cboCompany.SelectedValue; //to persist value on postback
        }
    }
 
    //...
     
    //SITE
    RadComboBox cboSite = (RadComboBox)filterItem.FindControl("cboFilterSite");
    if (cboSite.SelectedIndex != -1)
    {
        if (cboSite.SelectedValue != "All")
        {
            filtexprn.Add("([Site] ='" + cboSite.SelectedValue + "')");
            ViewState["SiteFilterVal"] = cboSite.SelectedValue; //to persist value on postback
        }
    }
 
    int count = filtexprn.Count - 1;
    foreach (string s in filtexprn)
    {
        filterToApply += s;
        if (count-- != 0)
            filterToApply += " AND ";
    }
 
    grdParts.MasterTableView.FilterExpression = filterToApply;
    grdParts.MasterTableView.Rebind();
}

grid aspx code
<telerik:RadGrid ID="grdParts" runat="server"
    OnItemCreated="grdParts_ItemCreated"
    OnItemDataBound="grdParts_ItemDataBound"
    OnItemCommand="grdParts_ItemCommand"
    OnNeedDataSource="grdParts_NeedDataSource"
    AllowFilteringByColumn="true" AllowSorting="true"
    AllowPaging="True" PageSize="15" EnableLinqExpressions="false"
    AllowMultiRowSelection="true">
    <PagerStyle AlwaysVisible="true"></PagerStyle>
    <MasterTableView AutoGenerateColumns="False" DataKeyNames="UniquePartID" ClientDataKeyNames="UniquePartID"
        Width="100%" CommandItemDisplay="None" PageSize="15">
        <Columns>
            <telerik:GridBoundColumn DataField="UniquePartID" HeaderText="UniquePartID" ReadOnly="True"
                SortExpression="UniquePartID" UniqueName="UniquePartID" Display="false">
            </telerik:GridBoundColumn>
 
            <telerik:GridBoundColumn DataField="Company" HeaderText="CONO" SortExpression="Company" UniqueName="Company" FilterControlAltText="Filter Company column"
                ItemStyle-Width="4%" HeaderStyle-Width="4%" AllowFiltering="true" AllowSorting="true">
                <FilterTemplate>
                    <telerik:RadComboBox runat="server" ID="cboFilterCompany" AutoPostBack="false"
                        OnPreRender="cboFilterCompany_PreRender"
                        DataValueField="CompanyID" DataTextField="CompanyDescription"
                        Width="100%">
                    </telerik:RadComboBox>
                </FilterTemplate>
            </telerik:GridBoundColumn>
 
            <telerik:GridBoundColumn DataField="Site" HeaderText="Site" SortExpression="Site" UniqueName="Site" FilterControlAltText="Filter Site column"
                ItemStyle-Width="6%" HeaderStyle-Width="6%" AllowFiltering="true" AllowSorting="true">
                <FilterTemplate>
                    <telerik:RadComboBox runat="server" ID="cboFilterSite" AutoPostBack="false"
                        OnPreRender="cboFilterSite_PreRender"
                        DataValueField="SiteDesc" DataTextField="SiteDesc"
                        Width="100%">
                    </telerik:RadComboBox>
                </FilterTemplate>
            </telerik:GridBoundColumn>
 
            ...
 
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <Selecting AllowRowSelect="true"></Selecting>
        <ClientEvents OnRowDblClick="RowDblClick"></ClientEvents>
    </ClientSettings>
    <GroupingSettings CaseSensitive="false" />
</telerik:RadGrid>
Kostadin
Telerik team
 answered on 28 May 2014
1 answer
127 views
Hi Telerik team,

When i am double clicking in the Radgrid displaying/focusing textbox with data. If i have special characters inside the textbox then focus propety is giving error. Kindly help me ASAP.

Please find my code below:

<ClientEvents OnRowCreated="rgManualTestSteps_RowCreated" OnCommand="rgManualTestSteps_RadGrid1_Command"
OnRowClick="rgManualTestSteps_RowClick" OnRowMouseOut="rgManualTestSteps_RowClick"
OnRowDestroying="rgManualTestSteps_RowDestroying" />

function rgManualTestSteps_RowCreated(sender, eventArgs)
{
        var dataItem = eventArgs.get_gridDataItem();
        for (var i = 1; i < dataItem.get_element().cells.length; i++) 
             {
                 var cell = dataItem.get_element().cells[i];
                 if (cell)
                     {
                          $addHandler(cell, "dblclick", Function.createDelegate(cell, rgManualTestSteps_ShowColumnEditor));
                     }
             }
}

function rgManualTestSteps_ShowColumnEditor()
{
             rgManualTestSteps_editedCell = this;
             //hide text and show column editor in the edited cell
             var cellText = this.getElementsByTagName("span")[0];
             if (cellText != undefined)
                  {
                        cellText.style.display = "none";
                        //display the span which wrapps the hidden checkbox editor
                        if (this.getElementsByTagName("span")[1]) {
                        this.getElementsByTagName("span")[1].style.display = "";
                   }
             var colEditor = this.getElementsByTagName("input")[0] || this.getElementsByTagName("select")[0];
             //if the column editor is a form decorated select dropdown, show it instead of the original
             if (colEditor.className == "rfdRealInput" && colEditor.tagName.toLowerCase() == "select") colEditor = Telerik.Web.UI.RadFormDecorator.getDecoratedElement  (colEditor);
             colEditor.style.display = "";
             colEditor.focus();
      }
}
nazeer
Top achievements
Rank 1
 answered on 28 May 2014
3 answers
141 views

Hi,

I have the exact similar scenario which is descrbed in the below thread. The solution suggested by Telerik Team in this thread is given below

1) To drop the resizing and reordering features from this grid.
2) To disable the ViewState of the whole placeholder where you load the RadGrid control. In this scenario have in mind that the SqlDataReader binding may not works, as each postback in the page will make the grid try to rebind and if the reader is currently closed, you will get an exception.

Unfortunately I cannot use the above suggestion as my customer is so particular on the ReOrder functionality.

As it an old thread(2011) My query here is there any solution available for this issue in latest Telerik Controls?

Thanks,
A2H
Eyup
Telerik team
 answered on 28 May 2014
1 answer
367 views
Hi,

A couple of months ago I saw one of the menu demos where one if the menu items was a login.  The item had a user id and password inputs along with a submit button.  I now need to code out something like this but I cannot find the demo as it seems to have been replaced with some newer ones.  Anyway can anyone provide a link to the demo if it still exists or some code samples (either C# or VB is fine) of how to accomplish having the login elements in a Rad Menu?

Thanks in advance...

K
Princy
Top achievements
Rank 2
 answered on 28 May 2014
1 answer
131 views
I have all auto generated columns and some field has a validator.
The problem is that the field with the validator are moved on the right to leave space between the header and the text box making the form really ugly.
See picture attached.

Is there a way to move the validator message on the right of the field so that I can avoid to have to build a template?
Thanks,
Felice

Princy
Top achievements
Rank 2
 answered on 28 May 2014
3 answers
217 views
I have grid contains more than 6k records, when i'm selecting pagesize form "ALL" to 10 getting error page (IE Diagnosis error page).
tested it for low number of records which is working fine.

Can plz someone help me on this issue.

Thanks,
Jagadeesh
Princy
Top achievements
Rank 2
 answered on 28 May 2014
2 answers
102 views
Hi Telerik team:

I'm currently using DropDownList with checkboxes on javascript and I found out that method get_checked, that retrieves wether an item is checked or not
does not work on IE.
Exists some fix to use this method on IE? 

Any help would be appreciated.
Thanks.


function doSaveReport(id) {

            if ($("#txtSaveAs").val() == "" && id == "")
                alert("You must specify a name for the report definition");
            else {
            
                      oEmployee = $find("<%= ddlEmployees.ClientID %>").get_items(),
                        
                var ReportData = {                  
                    EmployeeId: []
                }   
           
                for (i = 0; i < oEmployee.get_count(); i++) {
                    item = oEmployee.getItem(i);
                    if (item.get_checked())
                        ReportData.EmployeeId.push(item.get_value());
                }
}

























Shinu
Top achievements
Rank 2
 answered on 28 May 2014
6 answers
829 views
How do we prevent submit button click, if user has selected invalid date.

Currently, I am able to display the error message. But even if the error message is there and user clicks on Submit/Save  I am still able to submit form with invalid date.

While searching in Google, I found one suggestion to achieve this is adding RequiredFieldValidator on page. But this would turn make that field mandatory, which I cannot do.

Thanks.
Princy
Top achievements
Rank 2
 answered on 28 May 2014
5 answers
254 views
Hello,

I need to show a RadWindow through javascript and what I need on there are two dropdown controls that are binded. The first the user will select a company and the second will list contacts for that company that was selected. Can I do this binding update all on the window without any postback or at least keeping the radwindow modal?

Thanks,

Warren
Shinu
Top achievements
Rank 2
 answered on 28 May 2014
4 answers
253 views
Hi,

I'm opening a radwindow from within a radwindow. I want to use some of the client side functionsm like, center(), set_modal(). But when I run it, the webpage throws error says these functions are undefined. I'm using the following code. Also, is there a way to set radwindow skin using client code.

Thanks!

01.function GetRadWindow() {
02.        var oWindow = null; if (window.radWindow)
03.            oWindow = window.radWindow; else if (window.frameElement.radWindow)
04.            oWindow = window.frameElement.radWindow; return oWindow;
05.    }
06. 
07.    function openWinTest() {
08. 
09.        //store the overflow   
10. 
11.        bodyOverflow = document.body.style.overflow;
12. 
13.        htmlOverflow = document.documentElement.style.overflow;
14. 
15.        //hide the overflow   
16. 
17.        document.body.style.overflow = "hidden";
18. 
19.        document.documentElement.style.overflow = "hidden";
20. 
21.        var oBrowserWnd = GetRadWindow().BrowserWindow;
22.       
23. 
24.        var url = "www.google.com"
25. 
26.        oBrowserWnd.radopen(url, "", 1100, 620);
27.        oBrowserWnd.center()
28.        oBrowserWnd.set_modal(true);
29.    }

Tao
Top achievements
Rank 1
 answered on 27 May 2014
Narrow your results
Selected tags
Tags
+? more
Top users last month
Hiba
Top achievements
Rank 1
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Max
Top achievements
Rank 1
Veteran
Iron
Alina
Top achievements
Rank 1
Rakhee
Top achievements
Rank 1
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Hiba
Top achievements
Rank 1
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Max
Top achievements
Rank 1
Veteran
Iron
Alina
Top achievements
Rank 1
Rakhee
Top achievements
Rank 1
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?