Link to home
Start Free TrialLog in
Avatar of mmedi005
mmedi005

asked on

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

Avatar of David Robitaille
David Robitaille
Flag of Canada image

set  the SelectedIndexChange property of the RadioButtonList to "uxAddRadioButtonList_SelectedIndexChanged"
 
sorry, the name of the property is
onSelectedIndexChange
(i forgot the "on")
Avatar of mmedi005
mmedi005

ASKER

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

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

ASKER CERTIFIED SOLUTION
Avatar of David Robitaille
David Robitaille
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

ok, you are in the right direction.
you could try r.parent.fincontrol("uxPanel")
that worked..thank you

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

How is r considered the Parent in this situation?

Thanks again...
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.