[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-02-23
9
Medium Priority
?
278 Views
Last Modified: 2013-12-17
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

0
Comment
Question by:mmedi005
  • 5
  • 4
9 Comments
 
LVL 18

Expert Comment

by:David Robitaille
ID: 23713323
set  the SelectedIndexChange property of the RadioButtonList to "uxAddRadioButtonList_SelectedIndexChanged"
 
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 23713336
sorry, the name of the property is
onSelectedIndexChange
(i forgot the "on")
0
 

Author Comment

by:mmedi005
ID: 23713340
Will the RadioButtonList pair up with the Panel in each row the GridView Control creates?

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:mmedi005
ID: 23713575
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
 
LVL 18

Accepted Solution

by:
David Robitaille earned 2000 total points
ID: 23713689
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
 

Author Comment

by:mmedi005
ID: 23713819
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
 
LVL 18

Expert Comment

by:David Robitaille
ID: 23713862
ok, you are in the right direction.
you could try r.parent.fincontrol("uxPanel")
0
 

Author Comment

by:mmedi005
ID: 23713895
that worked..thank you

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

How is r considered the Parent in this situation?

Thanks again...
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 23713934
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question