ASP.NET - Telerik radgrid
Asked By sushma on 02-Aug-11 06:48 AM
Hi all,
Can any one send the javascript code for checkbox in radgrid and that javascript code should be called at server side.
here is the radgrid code
<telerik:RadGrid runat="server" ID="rgScheduleStatus" AutoGenerateColumns="false" GridLines="None"
OnItemDataBound="rgScheduleStatus_ItemDataBound" AllowPaging="true" PageSize="3"
OnPageIndexChanged="rgScheduleStatus_PageIndexChanged" AllowMultiRowSelection="true" AllowSorting="true">
<PagerStyle Mode="NumericPages" PageButtonCount="3" Position="TopAndBottom"/>
<MasterTableView CssClass="table_12" DataKeyNames="StudentHistoryPrintID" TableLayout="Auto" RowIndicatorColumn-ShowSortIcon="true">
<Columns>
<telerik:GridTemplateColumn HeaderText="Delete" HeaderStyle-CssClass="tal la" ItemStyle-CssClass="tal la" UniqueName="chkschedulestatus">
<HeaderTemplate>
<asp:CheckBox runat="server" ID="chkSelectall" Text="Delete" CssClass="chkheader"/>
</HeaderTemplate>
<ItemTemplate>
<asp:HiddenField runat="server" ID="hdnStudentHistoryPrintID" />
<asp:CheckBox runat="server" ID="chkSelect"/>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
Jitendra Faye replied to sushma on 02-Aug-11 07:02 AM
Use this code for select all and delete code in RadGrid-
protected void chkDelete_CheckedChanged(object sender, EventArgs e)
{
foreach (GridDataItem grdItem in RadGrid1.Items)
{
CheckBox chkDelete = (CheckBox)grdItem .FindControl("chkDelete");
//In the radgrid's second cell we are binding the userid and delete
//the row using this unique id
int userid = Convert.ToInt32(grdItem .Cells[2].Text);
if (chkDelete.Checked == true)
{
//Defining the Sqlconnection using the connection string "strConn"
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
string query = "Delete from Users where UserId=" + userid;
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
conn.Close();
}
}
RadGrid1.Rebind();
}
Hope this will help you.