locked
checkbox in radgrid. RRS feed

  • Question

  • User1529281529 posted

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

    Saturday, September 24, 2011 11:37 PM

All replies