0

I have displayed a SharePoint list view on visual webpart using SPview.RenderAsHtml() with Literal Control.

Is there any way to read these items ? I want to get selected items from this html view.

enter image description here

I have displayed a view on webpart with following code:

System.Text.StringBuilder sb = new System.Text.StringBuilder();
SPList list = web.Lists.TryGetList("List1");
SPView myView = list.Views["Pending"];
sb.Append("<p>" + myView.RenderAsHtml() + "</p>");
Literal1.Text = sb.ToString();
0

You can do this using javascript code.. check the below code

<script type="text/javascript" src="../../../../_layouts/15/Literal/jquery-1.12.2.min.js"></script>


<asp:Literal ID="Literal1" runat="server"></asp:Literal>

<asp:Button ID="btnGetItems" runat="server" Text="Get selected items" OnClientClick="return getItems()" />


<script type="text/javascript">
    function getItems() {
        var favorite = [];
        $.each($("input:checked"), function () {
            favorite.push(this.title);
        });
        alert("Selected values are: " + favorite.join(", "));

        return false;
    }

</script>
1

I got the Solution:

Here, selected item rows contains the <tr>with class name s4-itm-selected, So I read all those rows using JavaScript.

var selChks = document.getElementsByClassName("s4-itm-selected");
            var chk;
            for (var i = 0; i < selChks.length; i++) {
                chk = selChks[i];
                var title = chk.cells[1].textContent.trim();
                var fname = chk.cells[2].textContent.trim();
                alert("Title="+title);
                alert("First Name="+fname);
            }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.