Does any of you know of a lightweight list control for ASP.Net where I could add badged items on a horizontal line? Something like this:
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You have to do like
function addMore()
{
$("div").append("<span>New Badge</span>");
}
span{
background-color:#7F7F7F;
padding:5px;
border-radius:10px;
margin:5px;
display:inline-block;
color:white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<span>jQuery</span>
<span>ajax</span>
<span>c#</span>
<span>Html</span>
<span>Java</span>
</div>
<input type="button" onclick="addMore();" value=" + ">
Use asp.net Literal
control that will result you in span
.
回答2:
I used RadAutoCompleteBox which has the complete functions I needed. Thanks Telerik.
http://docs.telerik.com/devtools/aspnet-ajax/controls/autocompletebox/overview
Edit: Added reference to Telerik for ASP.Net and sample code:
<telerik:RadAutoCompleteBox runat="server" ID="KeywordsAutoComplete"
Width="100%" OnLoad="KeywordsAutoComplete_Load" OnClientEntryAdding="restrictDuplicateEntry"
EmptyMessage="Type keywords..."
CssClass="autocompletebox control transition-025"
AllowCustomEntry="true" />
<script type="text/javascript">
// Restrict Duplicate Entry
function restrictDuplicateEntry(sender, eventArgs) {
var entries = sender.get_entries(),
count = entries.get_count();
for (var i = 0; i < count; i++) {
if (entries.getEntry(i).get_text() == eventArgs.get_entry().get_text())
{
eventArgs.set_cancel(true);
return;
}
}
}
</script>
C#:
protected void KeywordsAutoComplete_Load(object sender, EventArgs e)
{
DataTable dt; // Binding Data (For Lookup)
KeywordsAutoComplete.DataSource = dt;
KeywordsAutoComplete.DataBind();
}