2012-04-02 105 views
-1

我有Repeater控制如下所示。需要幫助的Css問題

<asp:Repeater ID="rptCategory" runat="server"> 
    <HeaderTemplate> 
     <h2 class="art-logo-text" style="margin-bottom: 5px; color: #008752!important;font-size:16pt;"> 
      Course Categories</h2> 
    </HeaderTemplate> 
    <ItemTemplate> 
     <table cellpadding="2px" cellspacing="2px" style="margin-left:0px"> 
      <tr> 
       <td> 
        <div id="divleft"> 
         <asp:LinkButton ID="lnkCategory" runat="server" Text='<%# Eval("CategoryDescription")%>' 
          CommandArgument='<%# Eval("CourseLibraryCategoryID") %>' OnClick="lnkCategory_Click" 
          CssClass="courseLink"> 
         </asp:LinkButton> 

        </div> 

       </td> 
      </tr> 
     </table> 
    </ItemTemplate> 
    <FooterTemplate> 
    </FooterTemplate> 
</asp:Repeater> 

我想做的事情,當我的鼠標移到LinkBut​​ton的div的背景「divleft的背景應該是綠色和鼠標了背景顏色應該刪除意味着白色....當我點擊的LinkBut​​ton在那個時候在那個perticular DIV的背景應該是綠色的意思應該選....什麼是做這個plz幫助我的最佳途徑....

+0

你試過了嗎:懸停和:選中? – PraveenVenu 2012-04-02 13:02:13

+0

不,我沒有嘗試過,但這是中繼器控制,所以我很害怕,它是工作懸停和選定.....我不知道這個...你可以告訴我這個想法..... – 2012-04-02 13:05:45

+0

我曾嘗試#divleft:hover { background-color:Green; } #divleft:selected { background-color:Green; }在這一個懸停工作正常,但選定的CSS不工作 – 2012-04-02 13:10:33

回答

1

您可以使用這些樣式:

<style type="text/css"> 
    .courseLink 
    { 
     display:block; 
     height:100%; 
     width:100%; 
     background-color:Green; 
    } 
    .courseLink:hover 
    { 
     background:none; 
    } 
    .courseLink:active 
    { 
     background-color:Green; 
    } 
</style> 

既然你說過你想要它顯示父div的背景,我已經添加高度和寬度屬性

+0

你好,請你檢查? .courseLink:選中的css無法正常工作............. – 2012-04-02 13:14:47

+0

@KartikPatel「:active」樣式不能完成你所問的內容嗎?它使用Chrome和IE9。 – 2012-04-02 13:33:57

+0

不能在任何瀏覽器中工作...我認爲這可能是由於點擊linkbutton回發後發生.... – 2012-04-02 13:35:44

0

CSS:

#divleft:hover, .selected 
{ 
    background-color:green; 
} 

對於LinkBut​​ton的,加入這個JavaScript(jQuery的):

$('#<%# lnkCategory.ClientID %>').click(function(){ 
    // First remove all other rows which was selected before 
    // and you dont want those to remain selected if another 
    // row is selected. Otherwise, remove the following line 
    $("#divleft").removeClass("selected"); 
    $(this).closest('div').addClass("selected"); 
    return false; 
}); 

[這會,如果您的實際加價就如你顯示工作]

編輯: 這裏是更新的解決方案(回發補救):

ASPX(添加一個ScriptManager,對LinkBut​​ton的加OnClientClick的事件時,中繼器添加OnItemCreated事件,包括jQuery的):

<script type="text/javascript"> 
     function highlight(lb) { 
      $(".divleft").removeClass("selected"); 
      $(lb).closest('div').addClass('selected'); 
     }  
</script> 


<asp:ScriptManager ID="ScriptManager1" runat="server"> 
    </asp:ScriptManager> 
    <asp:Repeater ID="rptCategory" runat="server" OnItemCreated="rptCategory_ItemCreated"> 
     <HeaderTemplate> 
      <h2 class="art-logo-text" style="margin-bottom: 5px; color: #008752!important; font-size: 16pt;"> 
       Course Categories</h2> 
     </HeaderTemplate> 
     <ItemTemplate> 
      <table cellpadding="2px" cellspacing="2px" style="margin-left: 0px"> 
       <tr> 
        <td> 
         <div class="divleft"> 
          <asp:LinkButton ID="lnkCategory" ClientIDMode="Predictable" runat="server" Text='<%# Eval("CategoryDescription")%>' 
           CommandArgument='<%# Eval("CourseLibraryCategoryID") %>' OnClientClick="highlight(this)" 
           OnClick="lnkCategory_Click" CssClass="courseLink"> 
          </asp:LinkButton> 
         </div> 
        </td> 
       </tr> 
      </table> 
     </ItemTemplate> 
     <FooterTemplate> 
     </FooterTemplate> 
    </asp:Repeater> 

在服務器端添加此方法:

protected void rptCategory_ItemCreated(object sender, RepeaterItemEventArgs e) 
{ 
      if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
      { 
       ScriptManager1.RegisterAsyncPostBackControl(e.Item.FindControl("lnkCategory")); 
      } 
    } 

希望它幫助。 (對不起,遲到了,我在玩遊戲:p)

+0

不工作選定的CSS .... – 2012-04-02 13:19:15

+0

您是否注意到您的網頁在點擊後是否導致回發? – mshsayem 2012-04-02 13:20:39

+0

是的,這是回傳.....這就是爲什麼我需要這個解決方案..... – 2012-04-02 13:26:16