Toggle option on clicking a button inside Radgrid.

2 posts, 0 answers
  1. Siva
    Siva avatar
    35 posts
    Member since:
    Mar 2013

    Posted 06 Jan 2014 Link to this post

    Hi,
         I need a toggle box with two buttons inside it, on clicking a button in each row of the Radgrid..once I clicked one of the buttons inside the toggle box , it must be set as readonly..Is it possible ..? pls help me with a code..
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 Jan 2014 Link to this post

    Hi Siva,

    I guess that you want to make the RadGrid Row as readonly based on the ToggleButton value. Here I tried two different method to achieve this. In the first one the ToggleButton in ItemTemplate and based on it will value GridEditCommandColumn will enable/disable. Please have a look into the following code snippet.

    ASPX:
    <telerik:RadGrid ID="RadGrid2" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false">
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn DataField="OrderID" UniqueName="OrderID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="CustomerID" UniqueName="CustomerID">
                </telerik:GridBoundColumn>
                <telerik:GridEditCommandColumn UniqueName="GridEditCommandColumn">
                </telerik:GridEditCommandColumn>
                <telerik:GridTemplateColumn>
                    <ItemTemplate>
                        <telerik:RadButton ID="RadButton2" runat="server" ButtonType="StandardButton" ToggleType="CustomToggle"
                            OnToggleStateChanged="RadButton2_ToggleStateChanged">
                            <ToggleStates>
                                <telerik:RadButtonToggleState Text="ReadandWrite" />
                                <telerik:RadButtonToggleState Text="Readonly" />
                            </ToggleStates>
                        </telerik:RadButton>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    C#:
    protected void RadButton2_ToggleStateChanged(object sender, Telerik.Web.UI.ButtonToggleStateChangedEventArgs e)
    {
            RadButton btn = (RadButton)sender;
            GridEditableItem item = (GridEditableItem)btn.NamingContainer;
            LinkButton edit = (LinkButton)item["GridEditCommandColumn"].Controls[0];
            if (e.SelectedToggleState.Text == "Readonly")
            {
                edit.Enabled = false;
            }
            else
            {
                edit.Enabled = true;
            }
    }

    In the second approach the ToggleButton is in EditItemTemplate and based on the value of ToggleButton TextBox is making as readonly. Please have a look into the following code snippet.

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false"
        AutoGenerateEditColumn="true">
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn DataField="OrderID" UniqueName="OrderID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="CustomerID" UniqueName="CustomerID">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn>
                    <EditItemTemplate>
                        <telerik:RadButton ID="RadButton1" runat="server" ButtonType="StandardButton" ToggleType="CustomToggle"
                            OnToggleStateChanged="RadButton1_ToggleStateChanged">
                            <ToggleStates>
                                <telerik:RadButtonToggleState Text="ReadandWrite" />
                                <telerik:RadButtonToggleState Text="Readonly" />
                            </ToggleStates>
                        </telerik:RadButton>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    C#:
    protected void RadButton1_ToggleStateChanged(object sender, Telerik.Web.UI.ButtonToggleStateChangedEventArgs e)
    {
        RadButton btn = (RadButton)sender;
        GridEditableItem item = (GridEditableItem)btn.NamingContainer;
        TextBox txt = (TextBox)item["OrderID"].Controls[0];
        TextBox txt1 = (TextBox)item["CustomerID"].Controls[0];
        if (e.SelectedToggleState.Text == "Readonly")
        {
            txt.ReadOnly = true;
            txt1.ReadOnly = true;
        }
        else
        {
            txt.ReadOnly = false;
            txt1.ReadOnly = false;
        }
    }

    Please elaborate your requirement if it doesn't help.
    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top