Monday, 30 July 2018

QS


ASP.Net Page Method using jQuery AJAX Example
function ShowCurrentTime() {
    $.ajax({
        type: "POST",
        url: "CS.aspx/GetCurrentTime",
        data: '{name: "' + $("#<%=txtUserName.ClientID%>")[0].value + '" }',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnSuccess,
        failure: function(response) {
            alert(response.d);
        }
    });
}
function OnSuccess(response) {
    alert(response.d);
}

[System.Web.Services.WebMethod]
public static string GetCurrentTime(string name)
{
    return "Hello " + name + Environment.NewLine + "The Current Time is: "
        + DateTime.Now.ToString();
}



How to select second div using jQuery in a webpage?

If a webpage has 2 div tags like
<div>hello</div>
<div>hello</div>

$("div:eq(1)");


How do I get the value of a selected item of a radio button list 
with jquery
$('#btnTest').click(function()
    {
        alert($('#<%=RadioButtonList1.ClientID %> input[type=radio]:checked').val());
    });
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
            <asp:ListItem Text="Yes" Value="1"></asp:ListItem>
            <asp:ListItem Text="No" Value="2"></asp:ListItem>
 </asp:RadioButtonList>
<input type="button" id="btnTest" value="Uncheck" /> 


Difference between document.getElementById and document.getElementsByClassName

document.getElementById  returns a single DOM element whose ID matches your query.
 document.getElementsByClassName  returns an HtmlCollection - an array-like structure containing the DOM elements that matched your query

<div class="move">add padding</div>
<div class="move">add padding</div>
<button type="button" onclick="movefun()">Set left padding</button>
<script>
    function movefun() {
        var elements = document.getElementsByClassName("move");
        for (var i = 0; i < elements.length; i++) {
            elements[i].style.paddingLeft = "50px";
        }
    }
</script>

OUTPUT:add padding
                add padding

Display Data In Table Format In MVC

Add Employee Class in Model folder.
  1. class Employee  
  2. {  
  3.   
  4.     public int EmployeeId { getset; }  
  5.   
  6.     public string FirstName { getset; }  
  7.   
  8.     public string LastName { getset; }  
  9.   
  10.     public string Email { getset; }  
  11.   
  12.     public int Salary { getset; }  
  13.   
  14.     public string Company { getset; }  
  15.   
  16.     public string Dept { getset; }  
  17.   
  18. }  
Home Controller Code
  1. public class HomeController : Controller  
  2. {  
  3.     private List<Employee> emp;  
  4.     public HomeController()  
  5.     {  
  6.         emp = new List<Employee>()  
  7.         {  
  8.             new Employee()  
  9.             { EmployeeId =1,FirstName="Rakesh",LastName="Kalluri", Email="raki.kalluri@gmail.com", Salary=30000, Company="Summit", Dept="IT" },  
  10.             new Employee()  
  11.             { EmployeeId =2,FirstName="Naresh",LastName="C", Email="Naresh.C@gmail.com", Salary=50000, Company="IBM", Dept="IT" },  
  12.             new Employee()  
  13.             { EmployeeId =3,FirstName="Madhu",LastName="K", Email="Madhu.K@gmail.com", Salary=20000, Company="HCl", Dept="IT" },  
  14.             new Employee()  
  15.             { EmployeeId =4,FirstName="Ali",LastName="MD", Email="Ali.MD@gmail.com", Salary=26700, Company="Tech Mahindra", Dept="BPO" },  
  16.             new Employee()  
  17.             { EmployeeId =5,FirstName="Chithu",LastName="Raju", Email="Chithu.Raju@gmail.com", Salary=25000, Company="Dell", Dept="BPO" },  
  18.             new Employee()  
  19.             { EmployeeId =6,FirstName="Nani",LastName="Kumar", Email="Nani.Kumar@gmail.com", Salary=24500, Company="Infosys", Dept="BPO" },  
  20.   
  21.         };  
  22.     }  
  23.     public ActionResult Index()  
  24.     {  
  25.   
  26.         return View(emp);  
  27.     }  
Table Format Data Displaying in ForEach
Index.Cshtml
  1. @model IEnumerable<List_Data_Binding_in_MVC.Models.Employee>  
  2.   
  3. @{  
  4.     ViewBag.Title = "Index";  
  5. }  
  6. <div><b>Table Format Data Displaying in ForEach</b><br /></div>  
  7. <table class="table table-bordered table-responsive table-hover">  
  8.     <tr>  
  9.         <th>Employee Id </th>  
  10.         <th>First Name </th>  
  11.         <th>Last Name </th>  
  12.         <th>Email</th>  
  13.         <th>Salary</th>  
  14.         <th>Company</th>  
  15.         <th>Department</th>  
  16.     </tr>  
  17.     @foreach (var d in Model)  
  18.     {  
  19.         <tr>  
  20.             <td>@d.EmployeeId</td>  
  21.             <td>@d.FirstName</td>  
  22.             <td>@d.LastName</td>  
  23.             <td>@d.Email</td>  
  24.             <td>@d.Salary</td>  
  25.             <td>@d.Company</td>  
  26.             <td>@d.Dept</td>  
  27.   
  28.         </tr>  
  29.     }  
  30. </table>  
Output

run


No comments:

Post a Comment