Changing property of ItemTemplate controls in ListView

Posted by arturito on Stack Overflow See other posts from Stack Overflow or by arturito
Published on 2010-05-07T10:13:36Z Indexed on 2010/05/07 10:18 UTC
Read the original article Hit count: 253

Filed under:
|
|

I have ListView containig LinkButtons in ItemTemplate. ListView is inside UpdatePanel so it is not doing page refresh. When users click on one the LinkButtons it changes its css property in order to mark the selection:

    protected void ListView1_ItemCommand1(object sender, ListViewCommandEventArgs e)
    {
            ((LinkButton)e.CommandSource).CssClass = "selected";  
    }

That allows multiple selections. But once the page is refreshed the selection disappears, meaning that css property of control goes back to default.

               <ItemTemplate>
                            <asp:LinkButton ID="local" 
                                            Text='<%#Eval("Local.Name")%>' 
                                            runat="server"
                                            CommandName="selectLocal"
                                            CommandArgument='<%#Eval("Local.Id") %>'
                                             CssClass="notSelected"                                                          
                                                      >
                                      </asp:LinkButton>

                            <asp:LinkButton ID="guest" 
                                            Text='<%#Eval("Guest.Name")%>' 
                                            runat="server"
                                            CommandName="selectGuest"
                                            CommandArgument='<%#Eval("Guest.Id") %>'
                                             CssClass="notSelected"                                                          
                                                      >
                                      </asp:LinkButton>                                       
                </ItemTemplate>

How can I select them programatically on page reload? (I'm mainating selection list in session)

© Stack Overflow or respective owner

Related posts about c#4.0

Related posts about listview