locked
Repeater then Call DataBind to Refresh and display new GridPageIndex and to Display Pagination again RRS feed

  • Question

  • User3212841 posted

    I have a problem in repeater item command, where I need to change the properties (changed the td background) of the clicked link button inside the repeater, this works without calling the data bind and display pagination again. 

    I am using mysql as a database, so here is code

    protected void Repeater_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
    
    
    if (e.CommandName == "PageNumbers") // Command Name of the Link Button inside the Repeater
    {
    GridView1.PageIndex = Convert.ToInt32(e.CommandArgument);
    
    Repeater RepeatTD = (Repeater)GridView1.TopPagerRow.FindControl("Repeater1");
    
    foreach (RepeaterItem item in RepeatTD.Items)
    {
    HtmlTableCell row = (HtmlTableCell)item.FindControl("cell");
    row.Attributes["style"] = "background-color:#F8F8F8";
    }
    RepeaterItem selectitem = (RepeaterItem)(((LinkButton)e.CommandSource).NamingContainer);
    HtmlTableCell currentrow = (HtmlTableCell)selectitem.FindControl("cell");
    currentrow.Attributes["style"] = "background-color:#ff6600";
    
    }
    
    PopulateGridView();
    bindRepeater();
    
    }


    so what do you guys think I should do? do you guys have any other suggestion to approach what I am trying to do? Please comment down below if you have any ideas on how can I achieve what I am trying to do here...

    Wednesday, April 25, 2018 2:14 AM

All replies

  • User1724605321 posted

    Hi ranielquirante,

    Do you want to change the td background as well as data bind/paging ? If possible , please show us your markups which helps us reproduce your scenario .

    Best Regards,

    Nan Yu

    Thursday, April 26, 2018 6:16 AM
  • User-1716253493 posted

    Calling databind() will refresh everyting.

    My suggestion is canging the background in itemdatabound based a value in viewstate or session, then in itemcommand set the session value then rebind the repeater

    Thursday, April 26, 2018 7:52 AM
  • User3212841 posted

    Below is my Html mark up, please take a look. Yes I am thinking of using viewstate, but I don't really know how to use it. if you provide me an example as to how to use it to implement it on the attributes for the td cell that would be great.

    <asp:GridView ID="GridView1" runat="server" PageSize="20" OnPageIndexChanging="GridView1_PageIndexChanging"
    AllowPaging="True" OnDataBound="GridView1_DataBound" 
    Style="" >
    <PagerSettings Position="Bottom" />
    <PagerStyle ForeColor="Black" HorizontalAlign="Center" Font-Underline="False" />
    <PagerTemplate>
    <table id="tablePager">
    <tr style="background-color: #F8F8F8;">
    <td>
    <asp:LinkButton ID="First" CommandName="Page" CommandArgument="First" runat="server"
    Text="&lt;&lt; First" Style="color: black" ForeColor="Black" Font-Underline="False"></asp:LinkButton>
    </td>
    <td>
    <asp:LinkButton ID="Previous" CommandName="Page" CommandArgument="Prev" runat="server"
    Text="&lt; Previous" Style="color: black" ForeColor="Black" Font-Underline="False"></asp:LinkButton>
    </td>
    <asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater_ItemCommand">
    <ItemTemplate>
    <td id="cell" runat="server">
    <asp:LinkButton ID="LinkButton1" runat="server" CommandName="PageNumbers" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"pagenumbervalue") %>'
    ForeColor="Black" Font-Underline="False"><%#Eval("pagenumbertext") %></asp:LinkButton>
    </td>
    </ItemTemplate>
    </asp:Repeater>
    <td>
    <asp:LinkButton ID="Next" CommandName="Page" CommandArgument="Next" runat="server"
    Text="Next &gt;" ForeColor="Black" Font-Underline="False"></asp:LinkButton>
    </td>
    <td>
    <asp:LinkButton ID="Last" CommandName="Page" CommandArgument="Last" runat="server"
    Text="Last &gt;&gt;" Style="color: black" ForeColor="Black" Font-Underline="False"></asp:LinkButton>
    </td>
    </tr>
    </table>
    </PagerTemplate>
    </asp:GridView>

    Friday, April 27, 2018 3:02 AM