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

CheckBox Validation

2 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 25 Aug 2008, 07:45 PM
I have a hopefully a simple question now that we have purchased your product.

In my RadGrid I have three columns one is a checkbox, the other two are GridBoundColumns. 

Above the grid is a RadComboBox that has a dropdown for COOL  with values of "Yes" or "No".  If I check one of the checkboxes and select "No" in my deopdownlist for Britney Spears is there a way I can have an alert say.....
"Currently she is Cool, are you sure you want to make her Not Cool?"

DropDownList[Yes-No] [submit button]
ChxBox        NAME                        COOL
[ ]                 James Brown                     Yes                 
[x]                 Britney Spears                   Yes  <-- Need to Change to No
[ ]                 Roy Orbison                      Yes
[ ]                 Robert Smith                      Yes

Thank You!

                                            

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Aug 2008, 08:33 AM
Hello George,

You can try out the following code to achieve the required scenario.
aspx:
 <asp:DropDownList AutoPostBack="true" ID="DropDownList1" runat="server"  OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" > 
        <asp:ListItem Text="Yes"
        </asp:ListItem> 
        <asp:ListItem Text="No"></asp:ListItem> 
        </asp:DropDownList> 
 
 <MasterTableView DataSourceID="SqlDataSource1" > 
        <Columns>         
        <telerik:GridTemplateColumn HeaderText="Check" UniqueName="check"
        <ItemTemplate> 
            <asp:CheckBox ID="CheckBox1" AutoPostBack="true" runat="server" OnCheckedChanged="CheckBox_Changed"  /> 
        </ItemTemplate> 
        </telerik:GridTemplateColumn> 
        <telerik:GridBoundColumn DataField="FirstName" HeaderText="Name" UniqueName="Name"
        </telerik:GridBoundColumn> 
        <telerik:GridTemplateColumn HeaderText="Cool" UniqueName="Cool"
        <ItemTemplate> 
            <asp:Label ID="Label1" runat="server" Text="Yes"></asp:Label> 
        </ItemTemplate> 
        </telerik:GridTemplateColumn> 
 </MasterTableView> 

cs:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
                foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
                { 
                    CheckBox chk = (CheckBox)item.FindControl("CheckBox1"); 
                    if (chk.Checked) 
                    { 
                        Label lbl = (Label)item["Cool"].FindControl("Label1"); 
                        lbl.Text = DropDownList1.Text; 
                    } 
                }          
    } 
   
    protected void CheckBox_Changed(object sender, EventArgs e) 
    { 
        CheckBox chkbx = (CheckBox)sender; 
        if (chkbx.Checked) 
        { 
            DropDownList1.Attributes.Add("onchange", "confirm();"); 
        } 
    } 

js:
 function confirm() 
    {    
       var drop = document.getElementById('<%=DropDownList1.ClientID %>').selectedIndex; 
       if(drop==1) 
       { 
         alert("Currently she is Cool, are you sure you want to make her Not Cool?"); 
         } 
          
     return false;       
    } 

Princy.
0
Mike
Top achievements
Rank 1
answered on 26 Aug 2008, 12:21 PM
Princy,

Two Questions:
1. Is there away to use it with the <tereik:RadComboBox and not using a Label in the Item Template in the grid?
2. Can I do this in the server side and loop through the checkboxes and check it with the dropdownlist throwing a javascript alert if a change is made?

Thanks!
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mike
Top achievements
Rank 1
Share this question
or