|
Return Values |
Return Type |
Description |
|
data |
Object | string[] |
It denotes the Selected Item dataSource JSON object.
Here We can retire id, text etc. |
|
Item |
HTMLElement | Element |
It denotes the Selected Item list element. |
|
text |
string |
It denotes the Selected Item text. |
|
Return Values |
Return Type |
Description |
|
Data |
Object | Object[] | string[] |
It denotes the Selected Item dataSource JSON object or object collection.
Here We can retire id, text etc. |
|
Item |
HTMLElement | Element[] | HTMLCollection |
It denotes the Selected Item list element or element collection. |
|
text |
string | string[] |
It denotes the Selected Item text data or collection. |
|
// Accessing selected item from listview object using getSelectedItems method
var values = listObj.getSelectedItems();
// Accessing selected values text
var textValues = values.text;
document.getElementsByClassName(‘text’)[0].textContent = '';
for (var i = 0; i < length; i++) {
document.getElementsByClassName(‘text’)[0].textContent += textValues[i] + ', ';
}
// Selected Elements count
document.getElementsByClassName(‘count’)[0].textContent = values.item.length;
|
|
<form asp-controller="MyList" method="post">
<ejs-listview id="list" dataSource="@ViewBag.dataSource" showCheckBox="true" showHeader="true" headerTitle="Types Of Art"></ejs-listview>
<br />
<label for="art">Type of art you are in to: </label>
<input id="art" type="hidden" name="art" />
<br />
<input type="submit" id="button" value="Submit" formaction="GetValues" />
</form>
<h2 style="color:crimson; background-color:darksalmon; padding:10px;">
@ViewBag.Result
</h2>
<script>
document.getElementById('button').addEventListener('click', function () {
// Obtaining Listview Instance
var listviewInstance = document.getElementById('list').ej2_instances[0];
var texts = "";
for (var i = 0; i < listviewInstance.getSelectedItems().text.length; i++) {
// Assigning each value selected in the listview
texts = texts + listviewInstance.getSelectedItems().text[i] + ", ";
}
// Removes extra comma
texts = texts.replace(/(^,)|(, $)/g, "");
// Assigning listview value to text box
var textbox = document.getElementById('art');
textbox.value = texts;
})
</script>
|
|
// GET: /<controller>/
public IActionResult Lists()
{
//define the array of JSON
List<object> data = new List<object>();
data.Add(new { text = "Artwork", id = "01" });
data.Add(new { text = "Abstract", id = "02" });
data.Add(new { text = "Modern Painting", id = "03" });
data.Add(new { text = "Oil Painting", id = "04" });
ViewBag.dataSource = data;
return View();
}
[HttpPost]
public IActionResult GetValues()
{
string value = HttpContext.Request.Form["art"];
ViewBag.Result = value;
return View("Values");
}
} |