2012-03-14 41 views
0

我有一个名为lbxUpcommingEvents的ListBox。当索引改变时,事件处理程序被触发以检查重复记录。如果没有找到重复项,则通过显示样式的方式打开一个名为pnlAction的面板。如果发现嘟嘟声,另一面板pnlActionCancel打开并且oter关闭。基本上是toogle效果。面板可见性开/关切换效果不起作用

我试过了可视属性,viewstate属性,但它不起作用,我再也找不到它了,我从集体中寻找wizdom。这是我的代码。

protected void lbxUpcommingEvents_OnSelectedIndexChanged(object sender, EventArgs e) 
{ 
    pnlEventsSignUp.Visible = true; 
    string _selectedItemValue = lbxUpcommingEvents.SelectedValue.ToString(); 
    int _eventid = Convert.ToInt32(_selectedItemValue); 

    Guid _memberId = Guid.Empty; 
    _memberId = new Guid(Session["myId"].ToString()); 

    // Check for existing signup 
    EventsMemberSignup _createSingup = new EventsMemberSignup(); 
    dsEventsSingupTableAdapters.MemberEventsTableAdapter da = new dsEventsSingupTableAdapters.MemberEventsTableAdapter(); 
    dsEventsSingup.MemberEventsDataTable dt = da.GetDataForDupCheck(_memberId, _eventid); 

    if (dt.Rows.Count == 1) 
    { 
     Panel pnlAction = (Panel)(fvEventSignUp.FindControl("pnlAction")); 
     //pnlAction.Visible = false; 
     pnlAction.Style.Add("display","none"); 

     Panel pnlActionCancel = (Panel)(fvEventSignUp.FindControl("pnlActionCancel")); 
     //pnlActionCancel.Visible = true; 
     pnlActionCancel.Style.Remove("display"); 
    } 
    else 
    { 
     Panel pnlActionCancel = (Panel)(fvEventSignUp.FindControl("pnlActionCancel")); 
     //pnlActionCancel.Visible = false; 
     pnlActionCancel.Style.Add("display", "none"); 

     Panel pnlAction = (Panel)(fvEventSignUp.FindControl("pnlAction")); 
     //pnlAction.Visible = true; 
     pnlAction.Style.Remove("display"); 
    } 
} 

<div id="columnleft"> 
<a name="content_start" id="content_start"></a> 
<div class="leftblock"> 
    <h2>Events Signup</h2> 
    <p>    
    </p> 
    <h3> Upcomming Events</h3> 
    <p> 
     <asp:ListBox ID="lbxUpcommingEvents" runat="server" DataSourceID="odsUpcommingEvents" 
      Rows="6" DataTextField="Title" DataValueField="id" AutoPostBack="true" 
      Width="206px" OnSelectedIndexChanged="lbxUpcommingEvents_OnSelectedIndexChanged" /> 
    </p> 
    <h3> Members Attending</h3> 
    <p> 
     <asp:DataGrid ID="lboxSignedUpMembers" runat="server" DataSourceID="odsSignedUpMembers" 
      AutoPostBack="true" AutoGenerateColumns="false" RowStyle-CssClass="gridview" AlternatingRowStyle-CssClass="altbgcolor" 
      Width="206px" onselectedindexchanged="lboxSignedUpMembers_SelectedIndexChanged" CssClass="gridview" 
      GridLines="None" BorderStyle="Solid" BorderWidth="1" BorderColor="Black" > 
      <AlternatingItemStyle BackColor="White" /> 
      <Columns> 
       <asp:BoundColumn DataField="Name" /> 
       <asp:BoundColumn DataField="Title" /> 
       <asp:TemplateColumn > 
        <ItemTemplate> 
         <asp:Label runat="server" ID="lblDate" Text='<%# Eval("StartTime", "{0:d}") %>' /> 
        </ItemTemplate> 
       </asp:TemplateColumn> 
      </Columns> 
     </asp:DataGrid> 
    </p> 
</div> 
</div> 
</td> 
<td align="left" > 
<!--Start of right column--> 
<div id="columnright"> 
<div class="rightblock"> 
    <asp:Panel ID="pnlEventsSignUpTitle" runat="server" CssClass="actionbuttons"> 
     <h2>Select an Event to Signup</h2> 
    </asp:Panel> 
    <asp:Label runat="server" ID="lblNote" ForeColor="#cc0000" Font-Bold="true" /> 
</div> 
<div class="rightblock"> 
    <asp:Panel runat="server" ID="pnlEventsSignUp" visible="false">   

     <div class="dashedline" ></div> 
     <asp:FormView ID="fvEventSignUp" runat="server" DataSourceID="ObjectDataSource1" 
      DataKeyNames="id" Width="100%" > 
      <ItemTemplate> 
       <h2> 
        <asp:HiddenField runat="server" ID="hfEventID" Value='<%# Eval("id") %>' /> 
        <asp:Label Text='<%# Eval("title") %>' runat="server" ID="titleLabel" /> 
       </h2> 
       <div class="itemdetails"> 
        <br /> 
        location: 
        <h3> 
         <asp:Label ID="locationLabel" runat="server" Text='<%# ShowLocationLink(Eval("locationname"),Eval("location")) %>' /> 
        </h3> 
        <p> 
         <asp:Label Text='<%# Eval("starttime","{0:D}") %>' runat="server" ID="itemdateLabel" CssClass="GeneralText" /> 

         <asp:Label Text='<%# ShowDuration(Eval("starttime"),Eval("endtime")) %>' runat="server" ID="Label1" CssClass="GeneralText" /> 
        </p> 
       </div> 
       <div class="downloadevent"> 
        <a href="#"> 
         <img src="images/icon_download_event.gif" alt="Download this event to your personal calendar" 
          width="15" height="26" /></a><a href='<%# "events_download.ashx?EventID=" + Convert.ToString(Eval("id")) %>'>Add 
           this event to your personal calendar</a> 
       </div> 
       <Club:ImageThumbnail ID="thumb1" runat="server" ImageSize="Large" PhotoID='<%# Eval("photo") %>' /> 
       <p> 
        <asp:Label Text='<%# Eval("description") %>' runat="server" ID="descriptionLabel" /> 
       </p> 
       <div class="dashedline" ></div> 
       <asp:Panel ID="pnlAction" runat="server" CssClass="actionbuttons" > 
        <table border="0" cellpadding="2" cellspacing="2"> 
         <tr> 
          <td> 
           <asp:Label runat="server" ID="Label2" Text="Action<br />Required" Width="80px" Font-Bold="true" 
              ForeColor="#cc0000" Font-Size="14px" /> 
          </td> 
          <td> 
           <img src="images/RedArrow.jpg" alt="Red Arrow Right" /> 
          </td> 
          <td> 
           <asp:CheckBox runat="server" ID="cbxCert" Height="30px" Text="Check to Confirm Attendance" /><br /> 
           <asp:CustomValidator runat="server" ID="rfvConfirm" 
              ErrorMessage="You must check the box to continue" Font-Bold="true" 
              ForeColor="#cc0000" ClientValidationFunction="ensureChecked" /> <br /> 
           <Club:RolloverLink ID="rlnkSignUp" runat="server" Text = "I will be attending this event" 
             OnClick="rlnkSignUp_OnClick" ToolTip="I hereby certify that I am commiting to attending this event." 
           /> 
          </td> 
         </tr> 
        </table>            
       </asp:Panel> 
       <asp:Panel runat="server" ID="pnlActionCancel" CssClass="actionbuttons" > 
        <table border="0" cellpadding="2" cellspacing="2"> 
         <tr> 
          <td> 
           <asp:Label runat="server" ID="lblDupSignup" Text="You are alredy signed up for this event" ForeColor="#cc0000" Font-Bold="true" Font-Size="14px" /> 
          </td> 
          <td> 

          </td> 
          <td> 
           <asp:CheckBox runat="server" ID="cbxCancel" Height="30px" Text="Check to Cancel Attendance" /><br /> 
           <asp:CustomValidator runat="server" ID="CustomValidator1" 
              ErrorMessage="You must check the box to continue" Font-Bold="true" 
              ForeColor="#cc0000" ClientValidationFunction="ensureChecked" /> <br /> 
           <Club:RolloverLink ID="rlnCancel" runat="server" Text="I'm cancelling my participation" 
             OnClick="rlnCancel_OnClick" /> 
          </td> 
         </tr> 
        </table>            
       </asp:Panel> 
      </ItemTemplate> 
     </asp:FormView> 
    </asp:Panel> 
</div> 

回答

0

我已经设置了ViewStateMode为 “已禁用”。我只是希望它不会在别的地方回火。

0

如果删除更新面板并将控件放入其中,则您现有的代码可能会有效。

或者你可以像

private bool myRowCount; 
protected bool HasRowsMyData 
{ 
     get { return myRowCount; } 
     set { myRowCount=value; } 
} 

那么你的selectedIndex更改事件

if (dt.Rows.Count == 1) 
{ 
    HasRowsMyData=true; 
    //DataBind your controls here 
    YourUpdatePanel.Update(); 
} 

里面里面你的aspx面板上,你可以设置每个面板的Visible属性这样所以每当建立在你的页面属性页面更新,它们将根据结果打开/关闭

Visible='<%#HasRowsMyData%>' 
Visible='<%#!HasRowsMyData%>' 

如果你喜欢做客户端我建议jQuery的切换功能 jQuey:toggle()