How to add an AjaxControlToolkit Gravatar control before or after a checkbox in a checkboxlist

I have a CheckBoxList control that contains dynamically generated checkbox elements. This checkboxlist will contain usernames. I use Gravatar control from AjaxControlToolkit so that users can have their own profile images. I want that when adding a flag with the username to the text in the CheckBoxList, the Gravatar control must also be added before or after the flag, showing the corresponding displayed image of the user. An alternative way, in my opinion, is to have a user control with a flag and gravitator. But if you have another lightweight and affordable solution, please offer me. Below is the code:

<table class="style1"> <tr> <td align="right" style="padding: 5px" width="25%"> Username/Email:</td> <td style="padding: 5px"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> &nbsp;<asp:Button ID="Button1" runat="server" CssClass="newButton" onclick="Button1_Click" Text="Search" /> </td> </tr> <tr> <td align="right" style="padding: 5px" valign="top" width="25%"> Results:</td> <td style="padding: 5px"> <asp:CheckBoxList ID="CheckBoxList1" runat="server" onselectedindexchanged="CheckBoxList1_SelectedIndexChanged" AutoPostBack="True"> </asp:CheckBoxList> </td> </tr> <tr> <td align="right" style="padding: 5px" width="25%" valign="top"> Selected People:</td> <td style="padding: 5px"> <asp:ListBox ID="ListBox1" runat="server" Height="149px" Width="260px"> </asp:ListBox> </td> </tr> </table> 

As you can see, it also has a list containing the selected item from the checkboxlist. If possible, offer me the same for the list.

+6
source share
1 answer

The Repeater element is suitable for this. This allows you to bind to a data source and create a template for displaying elements.

 <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="act" %> ... <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <asp:CheckBox ID="checkBox" runat="server" /> <act:Gravatar runat="server" ID="gravatar" Email='<%# DataBinder.Eval(Container, "DataItem.useremail")%>' Size="50" Rating="G" DefaultImageBehavior="Identicon" DefaultImage="http://tinyurl.com/3bpsaac" /> <asp:Label ID="userName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.username")%>'></asp:Label> <br /> </ItemTemplate> </asp:Repeater> 

I have this Repeater associated with the following DataTable :

 System.Data.DataTable GetRepeaterData() { DataTable dt = new DataTable(); dt.Columns.Add("username", typeof(string)); dt.Columns.Add("useremail", typeof(string)); dt.Rows.Add("user_one", " test@superexpert.com "); dt.Rows.Add("user_two", " test@superexpert.com "); dt.Rows.Add("user_three", " test@superexpert.com "); return dt; } 
+3
source

Source: https://habr.com/ru/post/949372/


All Articles