jeudi 22 mars 2018

select checkboxes dynamically asp net

I want to select checkbox dynamically of a datagrid, if datagrid contains the matching value in dataset. I m binding datagrid when user selects a value of a dropdownlist.

To achieve this I have written following code.

protected void dgAvailableCandidates_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        DataSet dsSelectedCandidates = (DataSet)Session["SelectedCandidatesDataSet"];

        if (dsSelectedCandidates.Tables[1].Rows.Count > 0)
        {
            for (int i = 0; i < dgAvailableCandidates.Items.Count; i++)
            {
               string indRow = dgAvailableCandidates.DataKeys[i].ToString();

               if (indRow == dsSelectedCandidates.Tables[1].Rows[i]["fk_recId"].ToString())
               {
                    CheckBox shouldCheck = (CheckBox)dgAvailableCandidates.Items[i].FindControl("chkbox_SelectCandidate");
                    shouldCheck.Checked = true;
               }

             }
        }

    }

I have created a stored procedure that returns two datatables, tables0 is to bind datagrid and table1 holds recordIds that are already available in database table as selected or bit value (1).

My issue is here, when datagrid doesn't find a value in table1 it throws an exception 'there is no matching row'. How should I fix this exception

Thanks!




Aucun commentaire:

Enregistrer un commentaire