FindControl in Radgrid

2 posts, 0 answers
  1. Marta
    Marta avatar
    31 posts
    Member since:
    Apr 2009

    Posted 04 Jun 2009 Link to this post

    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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Jun 2009 Link to this post

    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



  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top