Showing posts with label visualwebpart. Show all posts
Showing posts with label visualwebpart. Show all posts

Friday, September 20, 2013

Visual Webpart on Text Box Change event Append the Text box data with Check Box list and Drop down Selected Value

Below is the code in which on you type in something on text box and on tab event(On change) event of text box the slected values from Check Box list and drop down is appended with text and displayed in Multiline text box control


In your ascx page use below code


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>


<script type=text/javascript>
    function AutoFill() {
       
        var chkSelectedLang = new Array();
        var i = 0;
        $('#<%=chkList.ClientID %> input[type=checkbox]:checked').map(function () {
         
            chkSelectedLang[i] = this.value;
            i = i + 1;

        });
       
        //var string1 = "";
        //for (var i = 0; i < myLanguage.length; i++) {

        //    string1 += myLanguage[i] + ";";
        //}       
        //alert(string1);       
        //alert(drop);
        var publicationNo = "";
        var materialNo = $("#txtMaterialNo").val();
        var ddlSelectedLang = $("#ddlLang").val();
        publicationNo = materialNo + ddlSelectedLang + ',' + '\n';
        for (var i = 0; i < chkSelectedLang.length; i++) {
            publicationNo += materialNo + chkSelectedLang[i] + ',' + '\n';
        }
        $("#txtMultiLine").val(publicationNo);
    }
</script>




<div style="border:1px solid black">
    <asp:CheckBoxList ID="chkList" runat="server">
        <asp:ListItem Value="I">India</asp:ListItem>
        <asp:ListItem Value="U">USA</asp:ListItem>
        <asp:ListItem Value="E">England</asp:ListItem>
    </asp:CheckBoxList>

</div>

<div style="border:1px solid green">
    <asp:DropDownList ID="ddlLang" ClientIDMode="Static" runat="server">
        <asp:ListItem Value="I">India</asp:ListItem>
        <asp:ListItem Value="U">USA</asp:ListItem>
        <asp:ListItem Value="E">England</asp:ListItem>
    </asp:DropDownList>
</div>

<div style="border:1px solid red">
<span>Material No</span><asp:TextBox ID="txtMaterialNo" ClientIDMode="Static" runat="server" onChange="AutoFill()" ></asp:TextBox>
<asp:TextBox ID="txtMultiLine" ReadOnly="true" ClientIDMode="Static" runat="server" TextMode="MultiLine"></asp:TextBox>   
</div>


Also Find the demo at the below link
Thilosh-Fiddle




Monday, August 19, 2013

Add data to people picker in Visual webpart programatically - sharepoint 2010

Add the People picker field in the ascx file as below

 <SharePoint:PeopleEditor runat="server" ID="peoplePickerID" MultiSelect="true" 
SelectionSet="User" />

in the code behind on page load write the logic to fill teh people picker from a list having a
people/group type column.


ArrayList PickerEntities = new ArrayList(); 
SPFieldUserValueCollection fieldUserValueCollection = (SPFieldUserValueCollection)item["PeopleGroupTypeColumnDispName"];

            foreach (SPFieldUserValue spuserval in fieldUserValueCollection)
            {
                SPUser userToassign = spuserval.User;
                PickerEntity entity = new PickerEntity();
                PeopleEditor pepEditor = new PeopleEditor();
                entity.EntityData["AccountName"] = spuserval.User.LoginName;
                entity.EntityData["SPUserID"] = spuserval.User.ID;
                entity.EntityData["Email"] = spuserval.User.Email;
                entity.Key = spuserval.User.LoginName;
                entity.Description = spuserval.User.LoginName;
                entity.DisplayText = spuserval.User.Name;
                entity = pepEditor.ValidateEntity(entity);
                entity.IsResolved = true;
                PickerEntities.Add(entity);
            }

peoplePickerID.UpdateEntities(PickerEntities);

 *item["PeopleGroupTypeColumnDispName"];--> is list column of people/group type


Have a look at other post about client people picker of Sharepoint 2013
Client people picker-Sharepoint 2013 



 

Tuesday, July 30, 2013

Add data from People Picker control into people/Group column field of a list in Sharepoint Visual Webpart

The below code can be used in visual webpart where in you have a requirement to pick the data from people picker field and add the data to people or group column of any list


 SPFieldUserValueCollection customer = new SPFieldUserValueCollection();
                    foreach (PickerEntity enity in pepPickCustomer.ResolvedEntities)
                    {
                        SPUser user = SPContext.Current.Site.RootWeb.EnsureUser(enity.Key);
                       
customer .Add(new SPFieldUserValue(SPContext.Current.Site.RootWeb, user.ID, user.Name));

                    }

Later to add data to list

item["PeopleGroupColumName"] = customer;


*
pepPickCustomer is the ID of Client people picker control which is a new type of people picker control available Sharepoin 2013.