复选框无法在asp radgrid中工作

时间:2014-05-31 05:34:24

标签: c# asp.net asp.net-mvc-4

这是我的代码。我想在网格中添加复选框列,以便在我单击复选框时,然后需要一个值,即:abc应插入数据库中。我正在使用C#。感谢

     <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>

1 个答案:

答案 0 :(得分:2)

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#代码落后:

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.
    }
}

您也可以点这个链接:http://www.telerik.com/help/aspnet-ajax/grid-persist-checkbox-state-in-gridtemplatecolumn-on-rebind.html