RadGrid 0 records validation

5 posts, 0 answers
  1. Siva Karthik
    Siva Karthik avatar
    8 posts
    Member since:
    Aug 2015

    Posted 04 Sep 2015 Link to this post

    Hi,

    I have a RadGrid and "Next" button in a user control and the user control is one of the wizard steps. The website is built in Sitefinity CMS. 

    I have a requirement to validate no.of records in RadGrid and display a message to user if there are no records. To put in another way, something like RequiredFiledValiation: the user should not be able to proceed to Next step if there are 0 records.  

    I tried the following. 

    1.  

      protected void RadGrid1_PreRender(object sender, EventArgs e) 
        { 
            RadGrid1.MasterTableView.AllowPaging = false; 
            RadGrid1.Rebind(); 
            Label1.Text = RadGrid1.MasterTableView.Items.Count.ToString(); 
            RadGrid1.MasterTableView.AllowPaging = true; 
            RadGrid1.Rebind(); 
        } 

    2. Below code in ItemDataBound 

    if TypeOf e.Item is GridFooterItem Then 

            Label1.Text = RadGrid1.MasterTableView.Items.Count.ToString(); 
     End If

     

    3.  In Page_Load():    Label1.Text = RadGrid1.MasterTableView.Items.Count.ToString(); 

     

    Nothing worked, the count is always 0.

     

    Please suggest me something definite.

     

    Regards,

    Siva Karthik

  2. Siva Karthik
    Siva Karthik avatar
    8 posts
    Member since:
    Aug 2015

    Posted 04 Sep 2015 Link to this post

    I have also tried the below in Next button click. 

                radProviderActivityList.Rebind()
                If radProviderActivityList.MasterTableView.Items.Count <= 0 Then
                    lblErrorMessage.Visible = True
                    lblErrorMessage.Text = "Please enter details of at least one CE Activity"
                    e.Cancel = True
                    Return
                Else
                    lblErrorMessage.Text = ""
                    lblErrorMessage.Visible = False
                End If

    This works for validation, but once the control goes inside if block, other commands "Add", "Edit" and "Delete" doesn't work. Clicking on +Add New Record or Edit no more works. 

  3. Siva Karthik
    Siva Karthik avatar
    8 posts
    Member since:
    Aug 2015

    Posted 04 Sep 2015 in reply to Siva Karthik Link to this post

    I have tried client side validation too.

    <script type="text/javascript"> 
    function RowCount() 

        var grid = $find("<%=RadGrid1.ClientID %>"); 
        var MasterTable = grid.get_masterTableView(); 
        var Rows = MasterTable.get_dataItems(); 
        alert(Rows.length); 

    </script>

    This gives me the error "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)

    I tried # instead if = and it didnt work.

    Then I tried ClientIDMode = static in the grid properties and called it from JQuery function like below. 

     

    var grid = $find("radProviderActivityList");
     var MasterTable = grid.get_masterTableView(); 
     var Rows = MasterTable.get_dataItems(); 
     alert(Rows.length); ​

     But no luck here too, as MasterTable is always null. 

     

  4. Vasil
    Admin
    Vasil avatar
    1637 posts

    Posted 08 Sep 2015 Link to this post

    Hi Siva,

    To resolve this error:
    This gives me the error "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)
    You may wrap your JavaScript inside RadScriptBlock. Check the documentation for further information:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/ajax/radcodeblock-and-radscriptblock

    Please hold on to AutoID ClientIdMode, since the Static is not supported.

    Regards,
    Vasil
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Siva Karthik
    Siva Karthik avatar
    8 posts
    Member since:
    Aug 2015

    Posted 11 Sep 2015 in reply to Vasil Link to this post

    Hi Vasil,

     Thanks for the reply. I had to skip that requirement to work on other priority items. I will try that later and let you know if it works in my case. 

     

    regards,

    Siva Karthik

Back to Top