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

CheckBox value

2 Answers 30 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Najid Hanif
Top achievements
Rank 2
Najid Hanif asked on 26 Sep 2011, 04:55 PM
I must be doing something wrong because I am having a really hard time trying to get the value of a check box in edit mode. I want the check box to be disabled if the value is true. With my code as it is now, it is always false. What am I doing wrong?

protected void RadGrid1_Test(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
    {
        GridEditFormItem edititem = (GridEditFormItem)e.Item;
 
        CheckBox movedtobs_chk = edititem["MovedToBS"].Controls[0] as CheckBox;
        Boolean flag = movedtobs_chk.Checked;
 
        //my issue is this flag is always false even when the checkbox is checked.
        if (flag == true)
        {
            movedtobs_chk.Enabled = false;
        }
 
 
    }
}


2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 26 Sep 2011, 06:03 PM
Hello Najid Hanif ,

I am not able to reproduce the issue.
please check below code snippet.
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false"
           OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound"         
           <MasterTableView CommandItemDisplay="Top">
               <Columns>                  
                   <telerik:GridCheckBoxColumn UniqueName="checkBoxTest" DataField="isChecked"></telerik:GridCheckBoxColumn>
                   <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
               </Columns>
           </MasterTableView>         
       </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            dynamic data = new[] {
                new { ID = 1, Name ="name",salery=123456789,isChecked=true},
                new { ID = 2, Name = "Name",salery=123456789,isChecked=true},
                new { ID = 3, Name = "name",salery=123456789,isChecked=false},
                new { ID = 4, Name = "Name",salery=123456789,isChecked=true},
                new { ID = 5, Name = "name",salery=123456789,isChecked=false}
            };
            RadGrid1.DataSource = data;
        }
 
        protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {         
            if (e.Item.IsInEditMode && e.Item is GridEditableItem)
            {
                GridEditableItem item = e.Item as GridEditableItem;
                      CheckBox chk = item["checkBoxTest"].Controls[0] as CheckBox;             
                bool flag = chk.Checked;             
            }
        }

let me know if any concern.

Thanks,
Jayesh Goyani
0
Najid Hanif
Top achievements
Rank 2
answered on 26 Sep 2011, 07:09 PM
Thank you very much for that. I had it fire OnItemCreated instead of OnItemDataBound. Changing it resolved my problem.
Tags
Grid
Asked by
Najid Hanif
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Najid Hanif
Top achievements
Rank 2
Share this question
or