conditional Alternating Item Style

5 posts, 0 answers
  1. DANA
    DANA avatar
    19 posts
    Member since:
    Dec 2010

    Posted 01 Feb 2012 Link to this post

    hi,

    just like james in this thread, I need to mark certain rows according to a condition.
    every time the user opens and watch an idea, the row of the watched idea should be in lightblue.
    that for itself works great.
    My problem is, that when I click a row it gets lightblue, but then- when I  click another row, the previous row change color to white.
    How can I keep the condition working for alternating item style too?

    that my code :

    <telerik:RadGrid Skin="innovation" EnableEmbeddedSkins="false" ID="RadGrid1" 
                  dir="rtl" HeaderStyle-ForeColor="White" AllowFilteringByColumn="True"  
        AllowSorting="True" AllowPaging="True"  BorderColor="#74ABAE" BackColor="White"
        BorderWidth="2px" runat="server" HeaderStyle-Font-Size="Small"  ItemStyle-Font-Size="Small"
        AlternatingItemStyle-Font-Size="Small" ItemStyle-BackColor="White" ItemStyle-ForeColor="Black"
         PageSize="7" AutoGenerateColumns="False" PagerStyle-Font-Size="Small" 
         AlternatingItemStyle-ForeColor="Black"
       Culture="Hebrew" GridLines="Vertical" Width="666px" 
          style="margin-right: 30px">
        <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Black">
        </HeaderContextMenu>
            <ItemStyle BackColor="White" Font-Size="Small" ForeColor="Black" />
        <PagerStyle mode="NumericPages" ShowPagerText="false"></PagerStyle>
        <MasterTableView>
        <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
               <Columns>
                     <telerik:GridBoundColumn CurrentFilterFunction="Contains"
                         DataField="IDEA_CODE" UniqueName="IDEA_CODE" HeaderText="ideanum"
                          AutoPostBackOnFilter="true" DataType="System.Int32"
                        </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn UniqueName="LINK" DataField="LINK" HeaderText="" 
                        DataType="System.String" Display="false"
                        </telerik:GridBoundColumn>
                     <telerik:GridBoundColumn DataField="ROWNUM" HeaderText="#" Visible="false"
                     AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"
                        DataType="System.Int32">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="SENDER_ID" HeaderText="id"
                    UniqueName="SENDER_ID" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"
                        DataType="System.String">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="FULLNAME" HeaderText="namef"
                    AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"
                        DataType="System.String">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="SUBJECT" HeaderText="sub"
                    AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"
                        DataType="System.String">
                    </telerik:GridBoundColumn>
                     <telerik:GridBoundColumn DataField="DESCRIPTION" HeaderText="status"
                     AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"
                        DataType="System.String">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="SEND_DATE" HeaderText="sdate"
                    AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"
                        DataType="System.DateTime" DataFormatString="{0:dd/MM/yy}">
                    </telerik:GridBoundColumn>                 
                      <telerik:GridImageColumn HeaderText="comments" UniqueName="FBIMG">
                    </telerik:GridImageColumn>    
             
         </Columns>
            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
            <HeaderStyle Width="20px">
            </HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
            <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            <EditFormSettings>
            <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
            </EditFormSettings>
            </MasterTableView>
                  <SelectedItemStyle BackColor="LightBlue" />
            <HeaderStyle ForeColor="White"></HeaderStyle>
                   <ClientSettings>
                   <Selecting AllowRowSelect="true" />
                   <ClientEvents OnRowSelected="OpenIdea" />                   
                    </ClientSettings>
            <FilterMenu EnableImageSprites="False"></FilterMenu>
        </telerik:RadGrid>
    Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
            Try
                If TypeOf e.Item Is GridDataItem Then
                    Dim item As GridDataItem = CType(e.Item, GridDataItem)
                    Dim idea_code As Integer = CInt(item("IDEA_CODE").Text)
                    If (StoredProcedures.Is_Watched_Idea(idea_code, userID) = True) Then 'if the ideas was watched then
                        item.BackColor = Drawing.Color.LightBlue 'color the row
                         End If
    ….
    End sub

    by the way- I tried disable alternating row in client settings but all I got is a transparent back color for the alternative rows.

    can anyone help with that?
    kind regards, Dana
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 01 Feb 2012 Link to this post

    Hello Dana,

    RadGrid loses its current selection when the data is sorted, a new group or filter is added, or when the current page changes. Check the following help documentation which explains more about this.
    Persisting the Selected Rows Server-side on Sorting/Paging/Filtering/Grouping.

    -Shinu.
  3. DANA
    DANA avatar
    19 posts
    Member since:
    Dec 2010

    Posted 01 Feb 2012 Link to this post

    Hi ,
    I still don't get it- I'm not sorting or changing anything, I simply click on an other row, and I want to keep the previous style for rows that are watched.
    there's no postback or anything and I'm not
    example:
    if I load the grid and my first 3 rows are blue (meaning I watched these ideas before according to my condition) and than the next 3 are white, by clicking a blue row and then a white row, the blue row - as an alternate row- becomes white (and the white becomes blue because of the condition I added)
    Is there a way to store my style for each row? or maybe there's an event I can use that I can rebind my grid after every row click so it'll check my condition everytime?

  4. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 06 Feb 2012 Link to this post

    Hi Dana,

    Possible approach in your scenario is to loop through all rows in the RadGrid PreREnder event , change the item values and set the needed colors there.
    This should keep the row color even after the postback of the selection.
    Give it a try and let me know if this helps.

    Greetings,
    Maria Ilieva
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  5. yasmin Ahmad
    yasmin Ahmad avatar
    3 posts
    Member since:
    Jan 2019

    Posted 05 Mar 2019 Link to this post

    you can remove the alternative row style from your grid 

    adding this code 

      <ClientSettings EnableAlternatingItems="false">

    that what i was  did .

Back to Top