c# - Storing element from repeater for use again -
I have a list that I am using as a discussion board. It has a box next to each user in which it has color and its initials, I basically want to show a color random (from a list) in the box, but use the same color again if that person first I've got boxes working with colored colors coming from random colors, but I can learn how to use an item from repeaters. Whether they should re-use of color rather than show random colors. / P>
HTML:
& lt; ASP: Repeater runat = "server" id = "rptThread" OnItemDataBound = "rptThread_ItemDataBound" & gt; & Lt; ItemTemplate & gt; & Lt; Li class = "media" & gt; & Lt; One class = "pull-left" href = "#" & gt; & Lt; Div class = "foo hidden-xs" runat = "server" id = "divColour" & gt; & Lt; Center & gt; & Lt; Span & gt; & Lt; ASP: label runat = "server" id = "lbl initial" & gt; & Lt; / Asp: label & gt; & Lt; / Span & gt; & Lt; / Center & gt; & Lt; / Div & gt; & Lt; / A & gt; & Lt; Div class = "media-body" & gt; & Lt; Ul class = "list-inline meta-text-mute" & gt; & Lt; Li & gt; & Lt; I class = "fa-calendar" & gt; & Lt; / I & gt; & Lt; Asp: label runat = "server" id = "lbldate" & gt; & Lt; / Asp: label & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; I class = "fa fa-user" & gt; & Lt; / I & gt; & Lt; A href = "#" & gt; ASP: label runat = "server" id = "lbl name" & gt; Esp: Labels & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; P & gt; & Lt; ASP: label runat = "server" id = "lbltext" & gt; & Lt; / Asp: label & gt; & Lt; / P & gt; & Lt; / Div & gt; & Lt; / Li & gt; & Lt; / ItemTemplate & gt; & Lt; / ASP: Repeater & gt;
ItemDatabase:
Datashow view nRow = null; ActiveDirectory AD = New ActiveDirectory (); General Functions G = New General Function (); Array color = G.getColours (); Random rnd = new random (); Int r = rnd Next (color.); Switch (id. Intet type) {case list itam type. ITEM: Case Write Type. Alternating ITEM: NRO = (Datarao View) E. ITEM Datatoms; (Label) e.Item.FindControl ("lbl initial")). Text = AD.getInitialsFromAD (nRow ["ThreadPerson"]. ToString ()); ((Label) e.Item.FindControl ("lblDate")). Text = nRow ["threaded"]. ToString (); ((Label) e.Item.FindControl ("lblName")). Text = AD.getFullNameFromSID (nRow ["ThreadPerson"]. ToString ()); (Label) e.Item.FindControl ("lblText")). Text = nRow ["thread text"]. ToString (); ("HtmlGenericControl") e.Item.FindControl ("divColour") Add Attributes ("style", "background color:" + (string) color [R]); breakdown;}
< P> List of colors is just: public arraylists getColours () {ArrayList Colors = new ArrayList (); Colors.Add ("# 22447a"); Colorss.Add ("# 761e10" ); Colors.Add ("# 256,908"); Colors.Add ("# 422,562"); etc. (redacted) ..... Return color;}
Create Dictionary Cache of Users of Color. When processing data for motherland events, check to see that users If the color is in the cache or not, if it is used, otherwise a color is chosen for them and it pastes it in the cache the next time.
// It is declared at the page level and started CollarCache = New Dictionary & lt; String, String & gt; (); Detrave View nRow = Faucet; ActiveDirectory AD = New ActiveDirectory (); General Functions G = New Generalfunction (); Array color = G.getColours (); Random rnd = new random (); Switch (id. Intet type) {case list itam type. ITEM: Case Write Type. Alternating ITEM: NRO = (Datarao View) E. ITEM Datatoms; Var person initial = AD.getInitialsFromAD (nRow ["ThreadPerson"]. ToString ()); String user caller = null; If (userColorCache.ContainsKey (person initial)) {userColor = userColorCache [person initial]; } Else {int r = rnd.ext (Colours.Count); UserColor = (string) color [R]; UserColorCache.Add (person initial, user call)} ((label) e.Item.FindControl ("lblInitials")). Text = personInitials; ((Label) e.Item.FindControl ("lblDate")). Text = nRow ["threaded"]. ToString (); ((Label) e.Item.FindControl ("lblName")). Text = AD.getFullNameFromSID (nRow ["ThreadPerson"]. ToString ()); (Label) e.Item.FindControl ("lblText")). Text = nRow ["thread text"]. ToString (); Add ("style", "background color:" + user caller); breakdown;}
Edit: ("HtmlGenericControl" e.Item.FindControl ("divColour"). To move the local variable to the cache logic below the assignment of DataItem.
Comments
Post a Comment