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

validation at the time of clicking insert button ON RADGRID

3 Answers 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
shankar mohan
Top achievements
Rank 1
shankar mohan asked on 27 Apr 2010, 08:06 AM
ex:-->
i ve two column ...A and B ON RAD GRID

AFTER CLICKING THE ADD NEW RECORD
IF I CLICK THE INSERT BUTTON WITHOUT ENTERING ANY VALUES ON BOTH THE COLUMNS
I NEED TO SHOW AN ALERT


3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Apr 2010, 09:14 AM
Hello Shankar,

One suggestion would be adding RequireFieldValidators for the TextBoxes from code behind. You can wire the ItemCreated event of the grid to add a validator in the handler. The following documentation describes how you can achieve this.
Validation

Regards,
Shinu.
0
shankar mohan
Top achievements
Rank 1
answered on 27 Apr 2010, 12:25 PM
yeah shinu its working but
my scenario is different


col_1    col_2    col_3    col_4    col_5

if i leave all the 5 columns blank ,alert should come
if am entering  in any one of the column also is acceptable so no alert is needed
0
Shinu
Top achievements
Rank 2
answered on 28 Apr 2010, 12:25 PM
Hello Shankar,

Here is another approach that I tried for showing an alert when any of the textboxes is empty (while inserting).

CS:

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted) 
        { 
            GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item; 
            TextBox column1 = (TextBox)insertedItem["col_1"].Controls[0]; 
            TextBox column2 = (TextBox)insertedItem["col_2"].Controls[0]; 
            TextBox column3 = (TextBox)insertedItem["col_3"].Controls[0]; 
            TextBox column4 = (TextBox)insertedItem["col_4"].Controls[0]; 
            TextBox column5 = (TextBox)insertedItem["col_5"].Controls[0]; 
            LinkButton insert = e.Item.FindControl("PerformInsertButton"as LinkButton; 
            insert.Attributes.Add("onclick""return ShowErrorMessage('" + column1.ClientID+"','"+column2.ClientID+ "','"+column3.ClientID+ "','"+column4.ClientID+ "','"+column5.ClientID+"');"); 
        } 
    } 

JAVA SCRIPT:

<script type=
"text/javascript"
    function ShowErrorMessage(col1, col2, col3, col4, col5) { 
        var column1 = document.getElementById(col1); 
        var column2 = document.getElementById(col2); 
        var column3 = document.getElementById(col3); 
        var column4 = document.getElementById(col4); 
        var column5 = document.getElementById(col5); 
        if ((column1.value == "") && (column2.value == "") && (column3.value == "") && (column4.value == "") && (column5.value == "")) { 
            alert("fill atleast one field"); 
            return false
        } 
    } 
</script> 
 

Regards,
Shinu.


Tags
Grid
Asked by
shankar mohan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
shankar mohan
Top achievements
Rank 1
Share this question
or