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

RadGrid 0 records validation

4 Answers 132 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Siva Karthik
Top achievements
Rank 1
Siva Karthik asked on 04 Sep 2015, 02:34 PM

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

4 Answers, 1 is accepted

Sort by
0
Siva Karthik
Top achievements
Rank 1
answered on 04 Sep 2015, 02:44 PM

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. 

0
Siva Karthik
Top achievements
Rank 1
answered on 04 Sep 2015, 02:52 PM

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. 

 

0
Vasil
Telerik team
answered on 08 Sep 2015, 06:54 AM
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
0
Siva Karthik
Top achievements
Rank 1
answered on 11 Sep 2015, 05:45 PM

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

Tags
Grid
Asked by
Siva Karthik
Top achievements
Rank 1
Answers by
Siva Karthik
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or