0

I have a radiobutton list named rdbModules and a GridView named dgvMenu.dgvMenu contains five CheckBoxes name chkSelect,chkAdd,chkUpdate,chkDelete,chkReport.

I have populated dgvMenu from the database depends on the selection of rdbModule.

The problem in when I am selecting checkbox inside the gridview it is working fine.

Suppose I have selected first item from radiobuttonlist and then selected some checkboxes from gridview. After that if I select the second or any other other options from the radio button list i am not able to get the selected checkbox details inside the gridview for the selection of first item of the radio button list.

10
  • You want to get the selected checkboxes from dgvMenu when rdbModules selection change? Commented Jan 14, 2014 at 10:43
  • yes....but some how it is getting changed when rdbModules selection is changed Commented Jan 14, 2014 at 11:00
  • How do you fill the gridview? Commented Jan 14, 2014 at 11:03
  • foreach (ListItem item in rdbModules .Items) { if (item.Selected) { string selectedValue = item.Value; dt = objSec.ShowSubMenuModuleWise(Convert.ToInt32(selectedValue)); dgvMenu.DataSource = dt; dgvMenu.DataBind(); } } Commented Jan 14, 2014 at 11:07
  • 1
    Can u please provide me the code. Thanx in advance Commented Jan 14, 2014 at 11:28

1 Answer 1

1
rdbModules_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    //Loop through your gridview here
    foreach (GridViewRow row in dgvMenu.Rows)
    {
        if (((CheckBox)row.FindControl("chkboxid")).Checked)
        {
             //do what you want            
        }            
    }

    if (rdbModules .Items.Cast<ListItem>().Any(item => item.Selected)) 
    { 
        foreach (ListItem item in rdbModules.Items) 
        { 
            if (item.Selected) 
            { 
                string selectedValue = item.Value; 
                dt = objSec.ShowSubMenuModuleWise(selectedValue); 
                dgvMenu.DataSource = dt; dgvMenu.DataBind(); 
            } 
        } 
    } 
}
Sign up to request clarification or add additional context in comments.

5 Comments

I think I am not able to explain my situation.
There is no issue in checkbox selection inside the gridview.But whenever I am changing the rdbModule_SelectedIndexChanged the previous record of the gridview is not coming. Should I use viewsate for this.If yes then how
What do you mean by "coming"?
Whatever I have selected in the gridview checkbox for the first Item of RadioButtonList is getting unchecked after re selection of that item in Radiobuttonlist. It will be better if I show u the screenshot.But since I dnt have that much reputation for attaching the screen shot
If you want the changes to be saved you have to update your database. Thus you will load the updated data when re selecting an item. You could also use viewstate but you will need one for each option of the RadioButtonList.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.