Asp.Net Multiple List Box Move List Item Using Jquery

 

 

To move List Item from one List Item to another using Jquery use below Code

List Box
Add two listbox on ASP.Net Page

<div>
Primary Collection
<asp:ListBox ID=”lstPrimary” runat=”server”>
<asp:ListItem Value=”one”>One</asp:ListItem>
<asp:ListItem Value=”Two”>Two</asp:ListItem>
<asp:ListItem Value=”Three”>Three</asp:ListItem>
<asp:ListItem Value=”Four”>Four</asp:ListItem>
<asp:ListItem Value=”Five”>Five</asp:ListItem>
</asp:ListBox>
</div>
<div >
<asp:ListBox ID=”lstAllTags” runat=”server” Height=”149px” SelectionMode=”Multiple”
Width=”113px”>
<asp:ListItem Value=”1″>1</asp:ListItem>
<asp:ListItem Value=”2″>2</asp:ListItem>
<asp:ListItem Value=”3″>3</asp:ListItem>
<asp:ListItem Value=”4″>4</asp:ListItem>
<asp:ListItem Value=”5″>5</asp:ListItem>
<asp:ListItem Value=”6″>6</asp:ListItem>
<asp:ListItem Value=”7″>7</asp:ListItem>
<asp:ListItem Value=”8″>8</asp:ListItem>
<asp:ListItem Value=”9″>9</asp:ListItem>
<asp:ListItem Value=”10″>10</asp:ListItem>
</asp:ListBox>
</div>

Put Button or Link on which we need to move Listitem

<a class=”btn gray” id=”lnkPrimaryAdd” href=”#” >Add To Primary</a>

Add Jquery to move list item

<script type=”text/javascript”>
$(document).ready(function () {

//Primary Add Button Click event
$(“#lnkPrimaryAdd”).click(function () {

var selectedOpts = $(‘[id$=lstAllTags] option:selected’);

if (selectedOpts.length == 0) {
alert(“Please select Tag.”);
e.preventDefault();
}
else {

$(‘[id$=lstPrimary]’).append($(selectedOpts).clone());
$(selectedOpts).remove();
e.preventDefault();
}

});

});
</script>

Asp.Net Repeater Radio Button Selection Problem

When we put Radio Button controls  within a Repeater control. , repeater gives it same name for all generated or multiple radio button. We can solve this issue by assigning a unique name to that radio button using  Jquery. Below is the Code and script for Radio button unique name in Repeater Control.

Put Radio button in Repeater

Code:
<asp:RadioButton ID=”rbMyRadioButton” runat=”server” GroupName=”rbtSelect” />

Call Script From Code to assign unique name in repeater Itemdatabound evennt

Code :
protected void rptContractType_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
System.Web.UI.WebControls.RadioButton rbMyRadioButton = (System.Web.UI.WebControls.RadioButton)e.Item.FindControl(“rbSelect”);

if (rbMyRadioButton != null)
{
rbMyRadioButton.Attributes.Add(“onclick”, “SetUniqueRadioButton(‘rbtSelect’,this)”);
}
}

Code :

Jquery which actually sets radiobutton unique name

<script type=”text/javascript” language=”javascript”>
function SetUniqueRadioButton(strGroupName, current) {
$(“input[name$='” + strGroupName + “‘]”).attr(‘checked’, false);
current.checked = true;
}
</script>

 

How to get Active Directory (LDAP) User Details with C #

To get Active Directory user details form ASP.Net

Add DLL Reference  :  System.DirectoryServices;

C#  Code :

////Domain Name or DomainPath
string path = “LDAP://Domain.local”;

string username = String.Format(“{0}”, Request.Form[“username”]);
string password =String.Format(“{0}”, Request.Form[“password”]);

DirectoryEntry de = new DirectoryEntry(path, username, password, AuthenticationTypes.Secure);

DirectorySearcher ds = new DirectorySearcher(de);

ds.Filter = “(&(objectCategory=person)(samAccountName=”+ username +”))”;

SearchResult result = ds.FindOne();

if (result != null)
{
string firstName = string.Empty;
string lastname = string.Empty;

if (result.Properties[“givenName”].Count > 0)
{
firstName = result.Properties[“givenName”][0].ToString();
}

if (result.Properties[“sn”].Count > 0)
{
lastname = result.Properties[“sn”][0].ToString();
}

Session[“Username”] = firstName + ” ” + lastname;

return true;
}

Asp.Net Debug IE opens Forms in IE 7 compatibility mode

When I debug an ASP.NET web forms application it opens with IE 7 document standards and also gives me Jquery error.

This occurs because localhost site is added Compatibility View in IE and because of that it by default opens all debug forms in IE 7 Mode. To resolve this problem please follow below steps

1. Open IE
2. Press Alt and click Tools from IE menu bar
3. Select Compatibility View Settings
4. Remove localhost from Websites you added to Compatibility View