This is a migrated thread and some comments may be shown as answers.

radgrid checkbox.

2 Answers 31 Views
Grid
This is a migrated thread and some comments may be shown as answers.
goutam
Top achievements
Rank 1
goutam asked on 25 Sep 2011, 04:28 AM
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:



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

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 25 Sep 2011, 06:56 PM
Hello,

Please replace this sb.Append(row.OwnerTableView.DataKeyValues[row.RowIndex]["LicenseId"].ToString());

line with below code.

sb.Append(row.GetDataKeyValue("LicenseId").ToString());

let me know if any concern.

Thanks,
Jayesh Goyani
0
goutam
Top achievements
Rank 1
answered on 27 Sep 2011, 02:38 AM
it is working...thanks for the help...
Tags
Grid
Asked by
goutam
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
goutam
Top achievements
Rank 1
Share this question
or