Programatically created radgrid bound client side (registerStartupScripts)

4 posts, 0 answers
  1. Gilberto
    Gilberto avatar
    65 posts
    Member since:
    Sep 2006

    Posted 15 Sep 2009 Link to this post

    Can i have a sample of a RadGrid created programatically and bound client side? Registering all scripts to page in order to get the client side databinging feature.

    By the way i am facing similar issue when i have to register scripts for a filtertemplate using RegisterStartupScripts. Once i generate and register the script in server side , i dont need to use the radscriptblock because i dont need  <% %> tags because i already have the clientId at the serverside, but this does not work, seems like i cannot find a control using the registerStartupScripts. Any suggestions?

    Thanks in advance

    Gilberto
  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 17 Sep 2009 Link to this post

    Hello Gilberto,

    Could you please send the problematic page code? I will check it out and try finding what could have wrong there.

    All the best,
    Iana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Gilberto
    Gilberto avatar
    65 posts
    Member since:
    Sep 2006

    Posted 23 Sep 2009 Link to this post

    Hi Iana,

    Thanks for your answer, lets split my issue em 2 parts:

    First: register scripts to achieve a client side filter in a radgrid using filter template.

    We have a inherited radgrid called flexradgrid, everything is created at runtime based in kind of metadata annotation saved in description property of collumns and tables, including filter template and SQL to CRUD operations also is created at runtime. Sort of pseudo dynamic data without using a ORM model.

    So, in this scenario we need to register the java scripts to handle OnClientSelectedIndexChanged of a rabcombo.

    assuming:

    •  FlexRadGrid1 is the ID of a Grid at server side.
    • NomeCategoria is the DataTextField and ValueTextField of a particular filter radcombo.

     

    Here we have a link to a FlexRadGrid to check the registered scripts at client.

    ps:the alert is only to check purposes.

    function ClientComboFilterSelected_id_Categoria(sender,args)   
    {  
      var tableView=$find("FlexRadGrid1_ctl00");  
      if (tableView)  
      {  
        alert(args.get_item().get_value());  
        tableView.filter("NomeCategoria",args.get_item().get_value(),"EqualTo");  
      }  
    }  
     


    Here we have the server code to register the script

     public class ComboFilterTemplate : ITemplate  
        {  
            private RadComboBox combo;  
            private string columnName;  
            protected FlexTelerik.Table.Field field;  
            protected String connectionString;  
            protected Page page;  
     
            public ComboFilterTemplate(Page Page, string ColumnName, FlexTelerik.Table.Field Field, String _connectionString)  
            {  
                field = Field;  
                columnName = ColumnName;  
                connectionString = _connectionString;  
                page = Page;  
     
            }  
            public void InstantiateIn(Control container)  
            {  
                combo = new RadComboBox();  
                combo.ID = String.Format("RadComboBox{0}", columnName);  
                combo.AppendDataBoundItems = true;  
                if (field.Description.GetElementsByTagName("DataTextField").Count > 0)  
                    combo.DataTextField = field.GetDataTextField();  
                combo.DataValueField = field.GetDataTextField();  
                combo.EmptyMessage = "Pesquisar";  
                combo.Items.Insert(0, new RadComboBoxItem("Todos"));  
                combo.DataBound += combo_DataBound;  
                combo.DataBinding += new EventHandler(combo_DataBinding);  
                combo.OnClientSelectedIndexChanged = String.Format("ClientComboFilterSelected_{0}", columnName);  
                container.Controls.Add(combo);  
     
            }  
     
            void combo_DataBinding(object sender, EventArgs e)  
            {  
                Helper helper = new Helper();  
                combo.DataSource = helper.ReturnDatasetCombo(field, String.Empty, connectionString);  
     
            }  
     
            void combo_DataBound(object sender, EventArgs e)  
            {  
                RadComboBox combo = (RadComboBox)sender;  
                GridItem container = (GridItem)combo.NamingContainer;  
                string script = "function ClientComboFilterSelected_" + columnName + "(sender,args) {var tableView=$find(\"" + ((GridItem)container).OwnerTableView.ClientID + "\");if (tableView)alert(args.get_item().get_value());tableView.filter(\"" + field.GetDataTextField() + "\",args.get_item().get_value(),\"EqualTo\");}";  
                ScriptManager.RegisterStartupScript(page, GetType(), String.Format("ClientComboFilterSelected_{0}", field.GetDataTextField()), script, true);  
                combo.SelectedValue = container.OwnerTableView.GetColumn(columnName).CurrentFilterValue;  
            }  
     
        } 

    Well i already use filtertemplate exactly as i doing here but columns and standard SqlDataSouce was defined in design time, and works very well.

    The alert show we are currently handle the client event, and the content of a Radcombo selected is fine.

    In my point of view everything necerssary to filter is done by a runtime creation, and the registered scripts seems like exactly the same but the filter doesnot work at all in runtime scenario.

    Could you help me?

    Thanks in advance



  5. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 29 Sep 2009 Link to this post

    Hello Gilberto,

    I went through your code and if lloks fine to me. Additionally, I have tested it and it works fine on my end. Could you please check the attached sample and let me know what differs in your case and if I missed something from your logic?

    Kind regards,
    Iana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top