I am having radgrid.
I want to show a checkbox before each row.
I am having a delete button outside the grid.
Selected checkboxes rows should be deleted when user clicks on Delete button.
my primary key is LicenseId, by using this i want to delete the selected checkbox row.
Can you please continue my code to achieve the functionality?
i am getting error in the line, is there anyone other way to acheive this functionality?? sb.Append(row.OwnerTableView.DataKeyValues[row.RowIndex]["LicenseId"].ToString());
this is the error "array index outofbounds" in foreach i am getting only 4, but in the above line it is showing 8...
None
0 Points
3 Posts
checkbox in radgrid.
Sep 24, 2011 11:37 PM|m313|LINK
Hello
I am having radgrid.
I want to show a checkbox before each row.
I am having a delete button outside the grid.
Selected checkboxes rows should be deleted when user clicks on Delete button.
my primary key is LicenseId, by using this i want to delete the selected checkbox row.
Can you please continue my code to achieve the functionality?
aspx page:
<radg:radgrid id="Grid" runat="server" Allowsorting="True"horizontalalign="NotSet"
onneeddatasource="Grid_NeedDataSource"
OnSortCommand="Grid_SortCommand" AllowPaging="True" PageSize="8" >
<MasterTableView DataKeyNames="LicenseId" CommandItemDisplay="Top" >
<Columns>
<radG:GridTemplateColumn FooterText="Delete"UniqueName="Delete" >
<ItemTemplate>
<asp:CheckBox ID="ChkDelete" runat="server" />
</ItemTemplate>
</radG:GridTemplateColumn>
<radg:GridBoundColumn HeaderText="State" FooterText="State"UniqueName="State" SortExpression="State" DataField="State" >
</radg:GridBoundColumn>
<radG:GridBoundColumn HeaderText="Number" FooterText="Lcn "UniqueName="No" DataField="No" ">
</radG:GridBoundColumn>
</MasterTableView>
</radg:radgrid>
<asp:Button ID="btnDelete" Text = "Delete" runat ="server" />
CODE BEHIND :
protected void btnDelete_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
bool flg = false;
foreach (GridDataItem row in Grid.MasterTableView.Items)
{
CheckBox cb = (CheckBox)row.FindControl("ChkDelete");
if (cb.Checked)
{
if (flg)
{
sb.Append(",");
}
else
{
flg = true;
}
sb.Append(row.OwnerTableView.DataKeyValues[row.RowIndex]["LicenseId"].ToString());
}
}
i am getting error in the line, is there anyone other way to acheive this functionality??
sb.Append(row.OwnerTableView.DataKeyValues[row.RowIndex]["LicenseId"].ToString());
this is the error "array index outofbounds" in foreach i am getting only 4, but in the above line it is showing 8...
can anyone please help me out. thanks.,
Contributor
3720 Points
1011 Posts
Re: checkbox in radgrid.
Sep 25, 2011 02:37 PM|nobdy|LINK
why dont you check RadGrid demos, They have code for this already.
Here is the Link:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/selectrowwithcheckbox/defaultcs.aspx
I hope this helps.