Translate

Wednesday, 29 April 2015

how to get formatted date time like 2009-05-29 21:55:57 using javascript?




Converting Milliseconds to date formate using javascript

- for reference see below jsfiddle

(function () {
        
           var values = "/Date(1409819809000)/";

   var dt = new Date(parseInt(values.substring(6, values.length - 2)));
            var dtString1 = (dt.getMonth() + 1) + "/" + dt.getDate() + "/" + dt.getFullYear();
         alert(dtString1);
        
    })();

Add data from two tables in one view MVC 4

In model
--------

simple example 


 public class subdomain
   {

       public string Function { get; set; }
       public string SubDomain { get; set; }
       public string URL { get; set; }
       public Guid DomainId { get; set; }

   }
   public class emailserver
   {
       public string Priority { get; set; }
       public string MailExchanger { get; set; }
       public Guid DomainId { get; set; }
   }


  public class  tablevalues
   {
       public List<emailserver> emailserver { get; set; }

       public List<subdomain> subdomain { get; set; }
   }



in controller
-------------
tablevalues dto=new tablevalues();
dto.subdomain=from  p in context.tablename1  select p
dto.emailserver=from q in context.tablename2 select q
return View(dto);


in .cshtml
----------


 @model MVCDropDownlist.Models.tablevalues 

@{
    Layout = null;
}


 <table width="100%" border="0" cellspacing="0" cellpadding="0" id="tbsub" style="visibility: @(Model.subdomain.Count==0? "hidden" : "visible") " >
            <thead>
                <tr>
                    <td colspan="3">
                         <h1>Web Settings</h1>
                    </td>
                </tr>
                <tr>
                    <th>Web Sub Domain</th>
                    <th>Function</th>
                    <th>Points To</th>
                </tr>
            </thead>
            <tbody>
                @if (Model != null && Model.subdomain.Count() > 0)
                {
                    foreach (var item in Model.subdomain)
                    {
                    <tr>
                        <td>
                            @Html.DisplayFor(modelItem => item.SubDomain)
                        </td>
                        <td>@Html.DisplayFor(modelItem => item.Function)</td>
                        <td>@Html.DisplayFor(modelItem => item.URL)</td>
                    </tr>

                    }
                }
            </tbody>

        </table>
        <!--tableGrid -->
    </div>

    <!--rightSection -->
</div>

<div class="rightSection">

    <div class="tableGrid">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" id="tbess" style="visibility: @(Model.emailserver.Count==0? "hidden" : "visible") ">
            <thead>
                <tr>
                    <td colspan="2">
                         <h1>Email Server Settings</h1>
                    </td>
                </tr>
                <tr>
                    <th>Mail Exchanger</th>
                    <th>Priority</th>
                </tr>
            </thead>
            <tbody>
                @if (Model != null && Model.emailserver.Count() > 0)
                {
                    foreach (var item in Model.emailserver)
                    {

                    <tr>
                        <td>
                            @Html.DisplayFor(modelItem => item.MailExchanger)
                        </td>
                        <td>@Html.DisplayFor(modelItem => item.Priority)</td>
                    </tr>

                    }
                }

            </tbody>

        </table>

How to create a DataTable in C# and how to add rows?




Data table in Asp.net c#


DataTable dt=new DataTable();
Datacolumn Name = new DataColumn("Name",typeoff(string));

dt.Columns.Add(Name);
Datacolumn Age = new DataColumn("Age", typeoff(int));`

dt.Columns.Add(Age);

DataRow dr=dt.NewRow();

dr["Name"]="Kavitha Reddy";
dr["Age"]=24;
dt.add.rows(dr);
dr=dt.NewRow();

dr["Name"]="Kiran Reddy";
dr["Age"]=23;
dt.rows.add(dr);
Gv.DataSource=dt;
Gv.DataBind();


How to check Checkbox checked or Not using jquery(terms and conditions checkbox)




In View


<script>
    $(function () {
        $('#btnconfirm').click(function () {
            if ($("#chk").attr('checked') !== undefined ){
                return true;
            }
            else {

                alert("Please Select Checkbox ");
                return false;
            }
        });

    });
</script>
<div style="float: left">
                    <input type="checkbox" name="chk" id="chk"  />
                    I read and accept the terms and Conditions of registration
                </div>
  <input type="submit" value="Confirm"  id="btnconfirm" />