How to Bind checkbox value in radgrid clientside

Thread is closed for posting
2 posts, 0 answers
  1. Tamim
    Tamim avatar
    64 posts
    Member since:
    May 2011

    Posted 17 Sep 2013 Link to this post



    Hi,
     How to Bind checkbox value in radgrid Template column clientside code
     
    Sample Coding:
      <asp:CheckBox runat="server" ID="Byemail" Checked='<%#Bind("Byemail") %>' onkeydown="return (event.keyCode!=13);"
                                                OnCheckedChanged="CheckedChanged" AutoPostBack="true" />

    RadGrid full coding

    <telerik:RadGrid ID="RadGrid1" runat="server" Width="99%" Skin="Office2007" Visible="false"
                            OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand">
                            <MasterTableView AutoGenerateColumns="False" IsFilterItemExpanded="false">
                                <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
                                <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                                </RowIndicatorColumn>
                                <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                                </ExpandCollapseColumn>
                                <Columns>
                                    <telerik:GridBoundColumn ReadOnly="true" DataField="EmailId" HeaderText="EmailId"
                                        SortExpression="EmailId" UniqueName="EmailId" MaxLength="50" HeaderStyle-Width="20px"
                                        Visible="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridTemplateColumn HeaderText="Addresse Type">
                                        <ItemTemplate>
                                             <asp:Label ID="addrestype" runat="server" Text='<%#Bind("addrestype") %>' Width="16px" Style="text-align: left">
                                            </asp:Label>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Party Type">
                                        <ItemTemplate>
                                            <telerik:RadTextBox ID="Partype" runat="server" Text='<%#Bind("Partype") %>' ReadOnly="true" Width="120px" onkeydown="return (event.keyCode!=13);">
                                            </telerik:RadTextBox>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Company Name">
                                        <ItemTemplate>
                                            <telerik:RadTextBox ID="Companyname" runat="server" Text='<%#Bind("Companyname") %>' ReadOnly="true" Width="300px"
                                                onkeydown="return (event.keyCode!=13);">
                                            </telerik:RadTextBox>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Officer Name">
                                        <ItemTemplate>
                                            <telerik:RadTextBox ID="Contactperson" runat="server" Text='<%#Bind("Contactperson") %>' ReadOnly="true" Width="275px"
                                                onkeydown="return (event.keyCode!=13);">
                                            </telerik:RadTextBox>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Email">
                                        <ItemTemplate>
                                            <telerik:RadTextBox ID="Emailid" runat="server" Text='<%#Bind("Emailid") %>' Width="275px" onkeydown="return (event.keyCode!=13);"
                                                MaxLength="100" AutoCompleteType="Disabled" ReadOnly="true">
                                            </telerik:RadTextBox>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="By Email">
                                        <ItemTemplate>
                                            <asp:CheckBox runat="server" ID="Byemail" Checked='<%#Convert.ToBoolean(Eval("Byemail")) %>' onkeydown="return (event.keyCode!=13);"
                                                OnCheckedChanged="CheckedChanged" AutoPostBack="true" />
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="DEL">
                                        <ItemTemplate>
                                            <%-- <telerik:RadButton ID="Button4" runat="server" CausesValidation="false" CommandName="Delete"
                                                Icon-PrimaryIconCssClass="rbCancel">
                                            </telerik:RadButton>--%>
                                            <telerik:RadButton ID="Button4" runat="server" UseSubmitBehavior="false" CommandName="Delete"
                                                Icon-PrimaryIconCssClass="rbCancel" AutoPostBack="true">
                                            </telerik:RadButton>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <%--<telerik:GridButtonColumn HeaderText="Delete" CommandName="Delete" ButtonType="ImageButton"
                                        UniqueName="DeleteColumn" CommandArgument="Child" ConfirmDialogType="RadWindow"
                                        ConfirmText="Are You Sure Want To Delete This Record?" ConfirmTitle="Delete Confirm"
                                        HeaderStyle-Width="10px" />
                                    <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" FilterControlAltText="Filter DeleteColumn column"
                                        Text="Delete" UniqueName="DeleteColumn" ConfirmDialogType="RadWindow" Resizable="false"
                                        ConfirmText="Delete record?">
                                    </telerik:GridButtonColumn>--%>
                                </Columns>
                                <EditFormSettings>
                                    <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                    </EditColumn>
                                </EditFormSettings>
                            </MasterTableView>
                            <ClientSettings EnablePostBackOnRowClick="false" AllowDragToGroup="true">
                                <Selecting AllowRowSelect="true" />
                            </ClientSettings>
                            <FilterMenu EnableImageSprites="False">
                            </FilterMenu>
                            <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_">
                            </HeaderContextMenu>
                        </telerik:RadGrid>

    server side coding

     private DataTable tabledata1
            {
                get
                {
                    DataTable dt = (DataTable)Session["Createproject"];

                    if (dt == null)
                    {
                        dt = new DataTable();
                        object[] emptyrow = new object[columcount];
                        dt.Columns.Add("addrestype", typeof(string));
                        dt.Columns.Add("Partype", typeof(string));
                        dt.Columns.Add("Companyname", typeof(string));
                        dt.Columns.Add("Contactperson", typeof(string));
                        dt.Columns.Add("Emailid", typeof(string));
                        dt.Columns.Add("Byemail", typeof(bool));

                        for (int i = 1; i < rowcount + 1; i++)
                        {
                            emptyrow[0] = i.ToString();
                            dt.Rows.Add(emptyrow);
                        }
                        tabledata1 = dt;
                    }
                    return dt;
                }
                set
                {
                    Session["Createproject"] = value;
                }
            }

            private void assigndt2(DataTable dt)
            {
                RadTextBox r1;
                CheckBox c1;
                Label l1;


                for (int i = 0; i <= RadGrid1.Items.Count - 1; i++)
                {
                    if (dt.Rows.Count - 1 < i)
                    {
                        object[] emptyRow = new object[columcount];
                        dt.Rows.Add(emptyRow);
                    }
                  l1 = (Label)RadGrid1.Items[i].FindControl("addrestype");
                    dt.Rows[i]["addrestype"] = l1.Text;
                    r1 = (RadTextBox)RadGrid1.Items[i].FindControl("Partype");
                    dt.Rows[i]["Partype"] = r1.Text;
                    r1 = (RadTextBox)RadGrid1.Items[i].FindControl("Companyname");
                    dt.Rows[i]["Companyname"] = r1.Text;
                    r1 = (RadTextBox)RadGrid1.Items[i].FindControl("Contactperson");
                    dt.Rows[i]["Contactperson"] = r1.Text;
                    r1 = (RadTextBox)RadGrid1.Items[i].FindControl("Emailid");
                    dt.Rows[i]["Emailid"] = r1.Text;
                    c1 = (CheckBox)RadGrid1.Items[i].FindControl("Byemail");
                    dt.Rows[i]["Byemail"] = c1.Text;
                }
            }

    Thanks & Regards,
    Ansari
  2. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 20 Sep 2013 Link to this post

    Hi Ansari,

    Generally, you can access the checkbox on the client-side using the following approach:
    function pageLoad() {
        var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
        var rowEl = masterTable.get_dataItems()[0].get_element();
        var radTextBox = $telerik.findControl(rowEl, "Emailid");
        var checkBox = $telerik.findElement(rowEl, "Byemail");
    }

    Hope this helps. If you have further requirements or instructions, please elaborate on your specific scenario.

    Regards,
    Eyup
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top