Sultan jahan
Sultan jahan

Reputation: 85

Checkbox not working in asp radgrid

This is my code. I want to add checkbox column in grid so that as I click on check box then a required value ie: abc should be inserted in database. I am using C#. THanks

     <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
        GridLines="None" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"
        AlternatingItemStyle-HorizontalAlign="Center" Skin="Forest" AllowPaging="True">
        <mastertableview datasourceid="SqlDataSource1">
            <RowIndicatorColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridBoundColumn DataField="epin" DefaultInsertValue="" HeaderText="Epin"
                    SortExpression="epin" UniqueName="epin">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Recharge_epin" DefaultInsertValue=""
                    HeaderText="Recharge Code" SortExpression="Recharge_epin" UniqueName="Recharge_epin">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="topupdate" DataType="System.String" DefaultInsertValue=""
                    HeaderText="Activated On" SortExpression="topupdate" UniqueName="topupdate">
                </telerik:GridBoundColumn>

               <telerik:GridCheckBoxColumn HeaderText="LinkRisk" AllowFiltering="false" ReadOnly="false"  HeaderStyle-Width="3%">  
               </telerik:GridCheckBoxColumn>
            </Columns>
        </mastertableview>
    </telerik:RadGrid>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
        SelectCommand="SELECT [epin], [Recharge_epin], convert(nvarchar,topupdate,103) as 'topupdate' FROM [Top_up_details]">
    </asp:SqlDataSource>

Upvotes: 1

Views: 1847

Answers (1)

Krunal Patil
Krunal Patil

Reputation: 3676

HTML :

<telerik:GridTemplateColumn UniqueName="MasterTemplate" HeaderText="Checkbox column 1">
        <ItemTemplate>
          <asp:CheckBox ID="cbChecked" runat="server" AutoPostBack="True" OnCheckedChanged="CheckChanged">
          </asp:CheckBox>
        </ItemTemplate>
</telerik:GridTemplateColumn>

C# Code behind :

protected void CheckChanged(Object sender, System.EventArgs e)
{
    // Do your stuff here
}

private void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;
        CheckBox box = (CheckBox)item.FindControl("cbChecked");

       //store into Database fetching the text/value of the check box.
    }
}

you can follow this link too : http://www.telerik.com/help/aspnet-ajax/grid-persist-checkbox-state-in-gridtemplatecolumn-on-rebind.html

Upvotes: 2

Related Questions