Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to search a Telerik MVC Grid based on ASP.NET MVC 2.0's ListBox's selected Values?
    primarykey
    data
    text
    <p>I have a Telerik MVC Grid where there is a column Names , Gender , Age . I am going to use a ListBox which is bound to Gender ( coming from SQL 2k8 Table" Person". I am using Entity Framework, POCO classes , Repository Pattern ). Then there is a Image button as " Search " .</p> <p>When a user selects few values from ListBox and then hits the " Search" Button Telerik MVC Grid which is on the same page ( I am rendering a User control which has actual Telerik MVC Grid) should be populated . </p> <p>how to do this ? how to pass the selected ListBox values back to controller Action " SearchPerson" . There is a way of doing this using JQuery . But i dont know how to do this . Please help me </p> <p>EDIT : Code</p> <pre><code> &lt;% using (Ajax.BeginForm("SearchVouDate", "ERA", new AjaxOptions { UpdateTargetId = "ProfileList", LoadingElementId = "LoadingImage", OnSuccess = "ShowMessage" })) { %&gt; &lt;div class="SelectNPI" &gt; &lt;div class="DivSelectNPI"&gt; &lt;input name="selection1" value="NPI" id="rdNPI" type="radio" onclick="toggleLayer(this.checked);" /&gt; &lt;%:Html.Label(Resources.Strings.SelectNPI) %&gt; &lt;div id="ERANPI" style="display: none;" &gt; &lt;%:Html.ListBoxFor(m =&gt; m.Eras.NPI, new MultiSelectList(Model.GetERAs, "NPI", "NPI", Model.NPIListBox), new { ID="NPIList", style = "width: 160px; height:50px" })%&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="SelectPIN"&gt; &lt;input name="selection1" type="radio" id="rdPIN" value="PIN" onclick="toggleLayer1(this.checked);" /&gt; &lt;%:Html.Label(Resources.Strings.SelectPIN) %&gt; &lt;div id="ERAPIN" style="display: none;" &gt; &lt;%:Html.ListBoxFor(m =&gt; m.Eras.PIN, new MultiSelectList(Model.GetERAs, "PIN", "PIN", Model.PINListBox), new {ID="PINList", style = "width: 180px; height:50px" })%&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;input type="submit" class="btnSearchSubmit" id="PaySearchDateSubmit" name="PaySearchDateSubmit" value="Search" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;%} %&gt; &lt;br /&gt;&lt;br /&gt; &lt;div class="ERATopDiv" &gt; &lt;label id="Label1" class="lblSearchResult"&gt; Search By Check Number&lt;/label&gt; &lt;/div&gt; &lt;br /&gt; &lt;div class="ERATopDiv"&gt;&lt;label id="Label3" class="lblSearchResult" &gt;Search Result&lt;/label&gt; &lt;/div&gt; &lt;div id="ProfileList"&gt; &lt;%Html.RenderPartial("SearchVoucherNum"); %&gt; &lt;/div&gt; &lt;div id="results"&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="EraPopupWindow"&gt; &lt;/div&gt; </code></pre> <p>My Controller :</p> <pre><code> [HttpPost] public ActionResult SearchVouDate(ERAViewModel era, FormCollection formValues) { try { if (formValues["Eras.NPI"] != null) { era.NPIListBox = formValues["Eras.NPI"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] selectedNPI = era.NPIListBox; ERAViewModel ervm = new ERAViewModel(); foreach (string NPI in selectedNPI) { ervm = this.WorkerService.SearchByNPI(formValues); return PartialView("SearchVoucherNum", ervm); } } else { ERAViewModel eras = this.WorkerService.SearchByPIN(era.Eras.PIN); return PartialView("SearchVoucherNum", eras); } } catch (Exception ex) { bool reThrow = ExceptionPolicyWrapper.HandleException(ex, ExceptionPolicies.MVCPolicy); if (reThrow) throw; } return null; } </code></pre> <p>My PartialView which I am rendering on my main View ( Main View contains my ListBox and partialView contains my telerik MVC Grid )</p> <pre><code> &lt;% Html.Telerik().Grid(Model.GetERAs) .Name("ERA").TableHtmlAttributes(new { style = "height:20px" }) .Scrollable(scroll =&gt; scroll.Enabled(true)) .DataKeys(datakeys =&gt; datakeys.Add(m =&gt; m.EraId)) .Columns(columns =&gt; { columns.Bound(m =&gt; m.NPI).Title(Resources.Strings.NPI).Width(150) .HtmlAttributes(new { style = "text-align:center" }) .HeaderHtmlAttributes(new { style = "color:black; margin:0 0 0 0; padding-left:15px; background-color:#BDBDBD; text-align:center; border-right:grey" }); columns.Bound(m =&gt; m.PIN).Title(Resources.Strings.PIN).Width(150) .HeaderHtmlAttributes(new { style = "color:black; margin:0 0 0 0; padding-left:15px; background-color:#BDBDBD; text-align:center; border-right:grey" }) .HtmlAttributes(new { style = "text-align:center" }); columns.Bound(m =&gt; m.GroupName).Title(Resources.Strings.GroupName).Width(150) .HeaderHtmlAttributes(new { style = "color:black; margin:0 0 0 0; padding-left:15px; background-color:#BDBDBD; text-align:center; border-right:grey" }) .HtmlAttributes(new { style = "text-align:center" }); columns.Bound(m =&gt; m.CheckNo).Title(Resources.Strings.CheckNo).Width(100) .HeaderHtmlAttributes(new { style = "color:black; margin:0 0 0 0; padding-left:15px; background-color:#BDBDBD; text-align:center; border-right:grey" }) .HtmlAttributes(new { style = "text-align:center" }); columns.Bound(m =&gt; m.VoucherNo).Title(Resources.Strings.VoucherNo).Width(150) .HeaderHtmlAttributes(new { style = "color:black; margin:0 0 0 0; padding-left:15px; background-color:#BDBDBD; text-align:center; border-right:grey" }) .HtmlAttributes(new { style = "text-align:center" }); columns.Bound(m =&gt; m.VoucherDate).Title(Resources.Strings.VoucherDate).Format("{0:dd/MM/yyyy}").Width(150) .HeaderHtmlAttributes(new { style = "color:black; margin:0 0 0 0; padding-left:15px; background-color:#BDBDBD; text-align:center; border-right:grey" }) .HtmlAttributes(new { style = "text-align:center" }); columns.Bound(m =&gt; m.PaymentDate).Title(Resources.Strings.PaymentDate).Format("{0:dd/MM/yyyy}").Width(150) .HeaderHtmlAttributes(new { style = "color:black; margin:0 0 0 0; padding-left:15px; background-color:#BDBDBD; text-align:center; border-right:grey" }) .HtmlAttributes(new { style = "text-align:center" }); columns.Bound(m =&gt; m.NonHippaVoucherPath).Title(Resources.Strings.NonHippaVoucherPath).Width(150).Format(Ajax.ActionLink("View Non Hippa voucher", "GetPdffile", "ERA", new { Id = "{0}" }, new AjaxOptions() { UpdateTargetId = "EraPopupWindow", HttpMethod = "Get" }, new { Style = "color:#FF0070;" }).ToString().Replace("{", "{{").Replace("}", "}}")).Encoded(false); columns.Bound(m =&gt; m.HippaVoucherPath).Title(Resources.Strings.HippaVoucherPath).Width(150).Format(Ajax.ActionLink("View Hippa voucher", "GetPdffile", "ERA", new { Id = "{0}" }, new AjaxOptions() { UpdateTargetId = "EraPopupWindow", HttpMethod = "Get" }, new { Style = "color:#FF0070;" }).ToString().Replace("{", "{{").Replace("}", "}}")).Encoded(false); //columns.Bound(m =&gt; m.Non_hippa_voucher_path).HtmlAttributes("color:#8A2BE2").Format(Html.ActionLink("View Non Hippa voucher", "GetPdffile", "ERA", new { ID = "{0}" }, new { onclick = "return someFunction();", Style = "color:#8A2BE2" }).ToHtmlString()).Encoded(false).Title("").Width(150); //columns.Bound(m =&gt; m.Hippa_voucher_path).HtmlAttributes("color:#8A2BE2").Format(Html.ActionLink("View Hippa voucher", "GetFile/", new { ID = "{0}", Style = "color:#8A2BE2" }, "ERA/").ToHtmlString()).Encoded(false).Title("").Width(150); }) // .ClientEvents(clientEvents =&gt; clientEvents.OnDataBinding("dataBinding")) .DataBinding(databinding =&gt; databinding.Ajax().Select("AjaxERA", "ERA")) .EnableCustomBinding(true) .Pageable(paging =&gt;{paging.Enabled(true) ;paging.PageSize(5) ;}) .Sortable() .Filterable() .Footer(true) .Render(); %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload