How do you add an event handler to a control in a row within a GridView in Edit Mode?

How do you add an event handler to a control in a row within a GridView?

I have radiobuttons inside EditItemTemplate tags.   I want to add a the event below to each radiobutton.  I want the RadioButton to control the Panel within the same row.

thx
protected void uxAddRadioButtonList_SelectedIndexChanged(object sender, EventArgs e)
    {
        uxPanel.Visible = Convert.ToBoolean(uxAddRadioButtonList.SelectedValue);
    }

Open in new window

mmedi005Asked:
Who is Participating?
 
David RobitailleConnect With a Mentor Analyst ProgrammerCommented:
ok, you got your event handled.
your problem is (now) there:
 uxPanel.Visible = Convert.ToBoolean(uxAddRadioButtonList.SelectedValue);

the compiler dident find the uxAddRadioButtonList control. put it in comment and it will compile. you could then put a breakpoint to check if the event is lunched.
After that, you will have to use find control to find uxAddRadioButtonList and uxPanel.
A quick hint, you could cast sender (the object sender param) as a control. then you could use
SenderConrol.Parent.findcontrol to find uxAddRadioButtonList and uxPanel.
I hope that will help.
0
 
David RobitailleAnalyst ProgrammerCommented:
set  the SelectedIndexChange property of the RadioButtonList to "uxAddRadioButtonList_SelectedIndexChanged"
 
0
 
David RobitailleAnalyst ProgrammerCommented:
sorry, the name of the property is
onSelectedIndexChange
(i forgot the "on")
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
mmedi005Author Commented:
Will the RadioButtonList pair up with the Panel in each row the GridView Control creates?

0
 
mmedi005Author Commented:
Got an error:

Compiler Error Message: CS0103: The name 'uxAddRadioButtonList' does not exist in the current context

Any ideas?

Here is more of the code....


    protected void uxAddRadioButtonList_SelectedIndexChanged(object sender, EventArgs e)
    {
        uxPanel.Visible = Convert.ToBoolean(uxAddRadioButtonList.SelectedValue);
    }
 
                <asp:GridView ID="uxChecksGridView" runat="server" 
                              HorizontalAlign="Left"
                              DataSourceID="uxChecksSqlDataSource"
                              DataKeyNames="ID, Address"
                              OnRowCancelingEdit="uxChecksGridView_RowCancelingEdit"
                              OnRowDataBound="uxChecksGridView_RowDataBound"
                              OnRowEditing="uxChecksGridView_RowEditing"
                              AutoGenerateColumns="False">
	                <Columns>
	                    <asp:TemplateField>
                                <ItemTemplate>
                                     ....
	                        </ItemTemplate>
	                        <EditItemTemplate>
                                        <asp:RadioButtonList ID="uxAddAddressRadioButtonList" runat="server"
                                                             RepeatDirection="Horizontal" 
                                                             RepeatLayout="Flow"
                                                             AutoPostBack="true"
                                                             OnSelectedIndexChanged="uxAddRadioButtonList_SelectedIndexChanged">
                                            <asp:ListItem Text="Yes |" Value="True" />
                                            <asp:ListItem Text="No" Value="False" />
                                        </asp:RadioButtonList>    
                                        <asp:Panel ID="uxPanel" runat="server"
                                                   Visible="false">
                                                 ......
                                        </asp:Panel>
                            </EditItemTemplate>		                        
	                    </asp:TemplateField>                                      
	                </Columns>
	            </asp:GridView>                              

Open in new window

0
 
mmedi005Author Commented:
is this the right direction...

this compiles, but i think this is having trouble identifying the uxPanel I want to change.  The sender object is the RadioButtonList, correct?  

How do I find the uxPanel  control within the row?

What control do I use to use FindControl within that row?
    protected void uxAddRadioButtonList_SelectedIndexChanged(object sender, EventArgs e)
    {
        RadioButtonList r = (RadioButtonList)sender;
        uxPanel.Visible = Convert.ToBoolean(r.SelectedValue);
    }

Open in new window

0
 
David RobitailleAnalyst ProgrammerCommented:
ok, you are in the right direction.
you could try r.parent.fincontrol("uxPanel")
0
 
mmedi005Author Commented:
that worked..thank you

Why does r.Parent.FindControl("uxPanel") work?

How is r considered the Parent in this situation?

Thanks again...
0
 
David RobitailleAnalyst ProgrammerCommented:
No, r.parent is the parent of the object "r" so since the RadioButtonList and the panel are "beside" they are in the same "container". So you could access that container by calling the parent property of a control.
Glad I could help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.