We help IT Professionals succeed at work.
Get Started

Please Help...Two listviews in formview one works fine the other wont display SelectedItemTemplate

acelaya
acelaya asked
on
488 Views
Last Modified: 2012-05-09
Hello I am using to listviews with identical configurations exept for the listview names.  The selected item templates for both are identical except they are bound to different datasources.
When I click a radiobutton from the first listview the SelectedItemTemplate displays just the way I expected.  When I click the radio button on the second listview the SelectedItemTemplate does not display and the radio button does not stay checked unless I click the same radio button a second time.  Although the radio button stays clicked after clicking it twice the SelectedItemTemplate never displays.

Here is the problem listview

 <asp:ListView ID="Listview2" runat="server" DataSourceID="dsSessions2" DataKeyNames="session">
        <LayoutTemplate>
                   <table width="80%" cellspacing="0" cellpadding="0" rules="all" border="0">
                   <tr><td>
                   <table width="100%" cellspacing="0" cellpadding="0" bordercolor="#330066" border="2"><tr class="group"><td border="0" colspan="6" align="left">Session : 2</td></tr>
                  <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
                 
      </table></table>
   </LayoutTemplate>
                <ItemTemplate>
      <tr style="border:none;" class='data<%# Container.DataItemIndex Mod 2 %>'>
         <td class="sessTime" style="border:none;" align="left"><%#Eval("sessionTime")%></td>
         <td class="sessTopic" style="border:none;" align="left"><%#Eval("topic")%></td>
         <td class="sessPresenter" style="border:none;" align="left"><%#Eval("presenter")%></td>
        <td class="sessCheck" style="border:none;"><asp:RadioButton ID="rb2" GroupName='<%#bind("sessionID")%>' runat="server" AutoPostBack="True" OnCheckedChanged="rbID_rbClicked"/></td>
       
       </tr>
   </ItemTemplate>
                 <SelectedItemTemplate>
     <tr style="border:none;" class='data<%# Container.DataItemIndex Mod 2 %>'>
         <td class="sessTime" style="border:none;" align="left"><%#Eval("sessionTime")%></td>
         <td class="sessTopic" style="border:none;" align="left"><%#Eval("topic")%></td>
         <td class="sessPresenter" style="border:none;" align="left"><%#Eval("presenter")%></td>
        <td class="sessCheck" style="border:none;"><asp:RadioButton ID="rb2" GroupName='<%#bind("sessionID")%>' runat="server" AutoPostBack="True" checked="True" OnCheckedChanged="rbID_rbClicked" Text='"uuuuuuuuu"' /></td>
    </tr>
      </SelectedItemTemplate>
        </asp:ListView>

Here is the good listview
<asp:ListView ID="ListView1" runat="server" DataSourceID="dsSessions" DataKeyNames="session" >
                <LayoutTemplate>
                   <table width="80%" cellspacing="0" cellpadding="0" rules="all" border="0">
                   <tr><td>
                   <table width="100%" cellspacing="0" cellpadding="0" bordercolor="#330066" border="2"><tr class="group"><td border="0" colspan="6" align="left">Session : 1</td></tr>
                  <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
                 
      </table></table>
   </LayoutTemplate>
   <ItemTemplate>
      <tr style="border:none;" class='data<%# Container.DataItemIndex Mod 2 %>'>
         <td class="sessTime" style="border:none;" align="left"><%#Eval("sessionTime")%></td>
         <td class="sessTopic" style="border:none;" align="left"><%#Eval("topic")%></td>
         <td class="sessPresenter" style="border:none;" align="left"><%#Eval("presenter")%></td>
        <td class="sessCheck" style="border:none;"><asp:RadioButton ID="rbID" GroupName='<%#bind("sessionID")%>' runat="server" AutoPostBack="True" OnCheckedChanged="rbID_rbClicked"/></td>
       
       </tr>
   </ItemTemplate>
   <SelectedItemTemplate>
     <tr style="border:none;" class='data<%# Container.DataItemIndex Mod 2 %>'>
         <td class="sessTime" style="border:none;" align="left"><%#Eval("sessionTime")%></td>
         <td class="sessTopic" style="border:none;" align="left"><%#Eval("topic")%></td>
         <td class="sessPresenter" style="border:none;" align="left"><%#Eval("presenter")%></td>
        <td class="sessCheck" style="border:none;"><asp:RadioButton ID="rbID" GroupName='<%#bind("sessionID")%>' runat="server" AutoPostBack="True" checked="True" OnCheckedChanged="rbID_rbClicked" Text="ppo" /></td>
    </tr>
      </SelectedItemTemplate>
         </asp:ListView>

Here is the event handler in code behind

 Protected Sub rbID_rbClicked(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim radBtn1 As RadioButton = CType(sender, RadioButton)
        Dim lv1 As ListView = FormView1.FindControl("ListView1")
        Dim lv2 As ListView = FormView1.FindControl("ListView2")
        Dim txtSession_Checked As TextBox = FormView1.FindControl("session1TextBox")
        Dim txtSession2_Checked As TextBox = FormView1.FindControl("session2TextBox")

        If radBtn1.ID = "rbID" Then
            lv1.SelectedIndex = radBtn1.GroupName - 1
            txtSession_Checked.Text = radBtn1.GroupName - 1
        ElseIf radBtn1.ID = "rb2" Then
            lv2.SelectedIndex = radBtn1.GroupName - 1
            txtSession2_Checked.Text = radBtn1.GroupName - 1
        End If
    End Sub
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE