复选框在asp radgrid中不起作用
本文关键字:不起作用 radgrid asp 复选框 | 更新日期: 2023-09-27 18:05:56
这是我的代码。我想在网格中添加复选框列,以便当我单击复选框时,所需值即: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>
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