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

FindControl in Radgrid

1 Answer 1318 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marta
Top achievements
Rank 1
Marta asked on 04 Jun 2009, 03:15 PM
Hi,

I am trying to acess a radiobuttonlist which is placed inside a radgrid, so that i can insert its selected value into my database.
I realized that I need to use FindControl, but can't get it to work... the name of my grid is "FichaConteúdo".
I tried:

Control myRadioBtnListTipo = FichaConteúdo.FindControl("RadioBtnListTipo");
sel = myRadioBtnListTipo.SelectedValue;

and also:

Control myRadioBtnListTipo = FichaConteúdo.MasterTableView.Items.FindControl("RadioBtnListTipo");

The problem is that I can't access "SelectedValue", it doesn't appear... I really need the selected value so that I can use it as an sql parameter in my query...
Any suggestions please?

Thank you,
Marta

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Jun 2009, 04:32 AM
Hi Marta,

I am not sure where you have placed the RadioButtonList control in the Grid. You may access the control as shown below :

# if the control is in a TemplateColumn:

 
 protected void FichaConteúdo_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            RadioButtonList radbtnlst = (RadioButtonList)item["ColumnUniqueName"].FindControl("RadioBtnListTipo"); 
        } 
 
  } 


# if the control is inside the CommandItemTemplate:

 
 protected void FichaConteúdo_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
 
        if (e.Item is GridCommandItem) 
        { 
            GridCommandItem item = (GridCommandItem)e.Item; 
            RadioButtonList radbtnlst = (RadioButtonList)item.FindControl("RadioBtnListTipo"); 
        } 
  } 

#if the control is in Editform:

 
 protected void FichaConteúdo_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
 
        if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode)) 
        { 
            GridEditFormItem item = (GridEditFormItem)e.Item; 
            RadioButtonList radbtnlst = (RadioButtonList)item.FindControl("RadioBtnListTipo"); 
        } 
   } 
 

If this does not help I would suggest you to send your aspx code.

Thanks
Shinu



Tags
Grid
Asked by
Marta
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or