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

Problem with control in radgrid itemtemplate

2 Answers 147 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marta
Top achievements
Rank 1
Marta asked on 16 Jun 2009, 11:48 AM
Hi,
I am trying to access the selected value of a radiobuttonlist which is placed inside a radgrid. The problem is that the control is directly in radgrid>MasterTableView>ItemTemplate. It is not in a TemplateColumn or anything of the sort. I tried acessing it directly through the name of the radgrid "FichaConteudo" but I get the error "Object reference not set to an instance of an object." so I figure I'm not accessing the control in the correct way. Here is part of my aspx code:

<telerik:RadGrid ID="FichaConteúdo" DataSourceID="GET_DETAILS_CONTEUDO" runat="server"
                GridLines="None" MasterTableView-CommandItemStyle-BorderColor="Transparent" BorderColor="transparent" ShowHeader="False">
                <MasterTableView TableLayout="Fixed" CellSpacing="-1" DataSourceID="GET_DETAILS_CONTEUDO" >
                    <ItemTemplate>
                    <p></p>
                            <asp:RadioButtonList ID="RadioBtnListTipo" runat="server" DataSourceID="GET_TIPOS" DataTextField="Tipo" DataValueField="Tipo" />
...

Here is how I am trying to access the control:

 

RadioButtonList myRadioBtnListTipo = (RadioButtonList) FichaContedo.FindControl("RadioBtnListTipo");

Thank you for your help!
Marta

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 16 Jun 2009, 12:08 PM
Hello Marta,

You can try out the following code to access the RadioButtonList in the ItemTemplate of the MasterTableView:
c#:
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    {       
        foreach (GridDataItem item in FichaConteúdo.Items) 
        { 
            RadioButtonList myRadioBtnListTipo = (RadioButtonList)item.FindControl("RadioBtnListTipo"); 
          
        } 
    } 
 

Thanks
Princy.
0
Marta
Top achievements
Rank 1
answered on 16 Jun 2009, 04:20 PM
Thanks! I had to add this line outside the foreach so that I could acess the control in my select statement afterwards as I have this code in a protected void button_submit and not in  protected void RadGrid1_PreRender(object sender, EventArgs e) like you suggested.

 

RadioButtonList myRadioBtnListTipo = new RadioButtonList();

It works, hope it's fine!

 

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