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

checkbox element in Data Item

2 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shir
Top achievements
Rank 1
Shir asked on 23 Oct 2012, 11:11 AM
hi, I'm new in telerik so maybe this question is trivial.

anyway, i want to know if the checkbox element in the data item in the grid is eanble, and if so then i want to do something.

    if (args.get_gridDataItem().get_selected(). get_checkboxelement() .Enabled == true)
        args.get_gridDataItem().set_selected(!args.get_gridDataItem().get_selected()); // or something

this the code. what i need to do to make it work?



2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Oct 2012, 09:59 AM
Hi,

I suppose you want to select a row on clicking the CheckBox in the ItemTemplate of GridTemplateColumn.

ASPX:
<telerik:GridTemplateColumn>
    <ItemTemplate>
        <asp:CheckBox ID="CheckBox1" runat="server" Enabled="true" />
    </ItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        CheckBox check = (CheckBox)item.FindControl("CheckBox1");
        int rowindex=item.ItemIndex;
        string id=check.ClientID;
        check.Attributes.Add("OnClick","OnClick('"+rowindex+"','"+id+"')");
    }
}

Javascript:
<script type="text/ecmascript">
    function OnClick(index, id)
    {
        var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
        var row = masterTable.get_dataItems()[index];
        if (row.findElement(id).isDisabled == false)
        {
            if (row.get_selected() == false)
            {
                row.set_selected(true);
            }
        }
    }
</script>

Please elaborate the scenario if it doesn't help.

Thanks,
Princy. 
0
Shir
Top achievements
Rank 1
answered on 25 Oct 2012, 10:07 AM
Thank you for the answer.

It realy help me.
Tags
Grid
Asked by
Shir
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Shir
Top achievements
Rank 1
Share this question
or