Monday, 20 April 2015

CLEAR EDITOR FOR TEXTBOX AFTER SUBMIT IN MVC ASP.NET

write this code before return

ModelState.Clear();

THATS ALL
 


GIVE BORDER TO YOUR TABLE IN INTERNET WEB APPLICATION MVC


SIMPLY COPY THIS CODE AND PASTE IT AFTER VIEWBAG IN VIEW

<style type="text/css">
    table, th, td {
        border: 1px solid black;
        margin-right:auto;
        margin-left:0px;
        color:green;
    
     
    }
    </style>
THATS ALL
THANKS FOR READING

Saturday, 18 April 2015

IMPLEMENT SEARCH USING 3 DROPDOWNLIST IN ASP.NET MVC

eg-searching of student of basis of year,section,class


1.create a CLASS ModalBussinessDataLayersave

DECLARE FETCHING METHOD FOR SECTION AND CLASS

table:-tbl_SECTION
SC_ID    nvarchar(50)    Unchecked
SC_NAME    nvarchar(50)    Checked

  public DataSet BindSection()
        {

            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);
            SqlCommand cmd = new SqlCommand("select * from tblSECTION", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds;
        }


TABLE-tblCLASS
CL_ID    nvarchar(20)    Unchecked
CL_NAME    nvarchar(100)    Checked

        public DataSet BindCLASS()
        {

            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);
            SqlCommand cmd = new SqlCommand("select * from tblCLASSNAME", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds;
        }

THEN CREATE THE all DROPDOWNLIST METHOD
YEAR:-
  public ActionResult Bindyears()
        {
            List<SelectListItem> items = new List<SelectListItem>();
            for (int i = 1980; i <= 2030; i++)
            {
                items.Add(new SelectListItem { Text = i.ToString(), Value = i.ToString() });
            }
            ViewBag.years = items;
            return View();
        }
 
 FOR section:

method-
 public ActionResult BindSections()
        {


            ModalBussinessDataLayersave stc = new ModalBussinessDataLayersave();
            DataSet ds = stc.BindSection();
            ViewBag.fname = ds.Tables[0];
            List<SelectListItem> items = new List<SelectListItem>();
            foreach (DataRow dr in ViewBag.fname.Rows)
            {
                items.Add(new SelectListItem { Text = @dr["SC_NAME"].ToString(), Value = @dr["SC_NAME"].ToString() });
            }
            ViewBag.SC_NAME = items;
            return View();
        }
FOR CLASS:
method:
 public ActionResult Bindclass()
        {

            ModalBussinessDataLayersave stc = new ModalBussinessDataLayersave();
            DataSet ds = stc.BindCLASS();
            ViewBag.fname = ds.Tables[0];
            List<SelectListItem> items = new List<SelectListItem>();
            foreach (DataRow dr in ViewBag.fname.Rows)
            {
                items.Add(new SelectListItem { Text = @dr["C_NAME"].ToString(), Value = @dr["C_NAME"].ToString() });
            }
            ViewBag.C_NAME = items;
            return View();
        }

then create method for search eg-
 [HttpGet]
        public ActionResult studentattendanceview(int? page, string years, string C_NAME, string SC_NAME, string search = "a")
        {
           
            BindSections();
            Bindclass();
            Bindyears();
            ModalBussinessDataLayersave bdl = new ModalBussinessDataLayersave();
         
            return View(bdl.scd.Where(x =>x.CD_SYEAR == years && x.CD_SCLASS == C_NAME && x.CD_SSECTION == SC_NAME ).ToList();
        
        }
Then finally in view
paste the following

@using(Html.BeginForm("studentattendanceview", "StudentClassDetail",FormMethod.Get))
{
<b>search by</b>  @Html.DropDownList("years", "Select")<text>years</text>   @Html.DropDownList("C_NAME", "Select") <text>class</text>      @Html.DropDownList("SC_NAME", "Select") <text>section</text>
   <input type="submit" value="Search" />
}

THATS ALL
thanks for reading


Friday, 17 April 2015

IMPLEMENT A CALENDER EXTENDER IN ASP.NET MVC TEXTBOXFOR



FIRST COPY AND PASTE THESE CSS AND JAVASCRIPT IN YOUR VIEW

 <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" />

<script src="//code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript">
    $("#datepicker").datepicker({
        changeMonth: true,
        changeYear: true
    });
</script>



THEN IN POSITION FOR YOUR CALENDER WRITE THE CODE

 <div class="editor-field">

   @Html.TextBoxFor(model => model.NSF_DOJ, new { id = "datepicker" })
      </div>

NOTE: here NSF_DOJ will contain your calender date
eg-  string joinDate = ntf.NSF_DOJ;
 ntf.NSF_DOJ = joinDate;

THATS ALL
thanks for reading

SAVE IMAGE IN DATABASE IN A SEQUENCE WAY LIKE 1.JPG,2.JPG..MVC

 

 SQLCOMMAND="select SF_SLNO from tbl_NONTEACHING_STAFF where SF_SLNO=(select MAX(SF_SLNO) from tbl_NONTEACHING_STAFF)";
SqlConnection con = new SqlConnection(con1);
            SqlDataAdapter sqa = new SqlDataAdapter(command, con);
            DataSet ds = new DataSet();
            sqa.Fill(ds);

            string fimg = null; string simg = null; string lastvalue;

            string fimgextension = file.FileName.ToString().Substring(file.FileName.ToString().LastIndexOf('.') + 1);

            if (ds.Tables[0].Rows.Count > 0)
            {
                lastvalue = ds.Tables[0].Rows[0][0].ToString().Substring(ds.Tables[0].Rows[0][0].ToString().LastIndexOf('/') + 1);

                string[] arr = lastvalue.Split('.');
                string fileimg = arr[0];
                string imgextension = arr[0];

                int fstimg = Convert.ToInt32(fileimg) + 1;
                int sndimg = fstimg + 1;

                file.SaveAs(Server.MapPath("~/ntfpic/") + fstimg + "." + fimgextension);

                fimg = "~/ntfpic/" + fstimg + "." + fimgextension;

            }
            else
            {
                file.SaveAs(Server.MapPath("~/ntfpic/") + "1" + "." + fimgextension);

                fimg = "~/ntfpic/" + "1" + "." + fimgextension;
            }
            return fimg;
        }
here fimg will contain your image address
so save it like :
ntf.NSF_IMAGE=fimg;

 NOTE: ntfpic is here folder name where your image will be saved
THATS ALL
THANKS FOR READING

 




DYNAMICALLY BIND DROPDOWNLIST FROM DATABASE MVC


FIRST CREATE A CLASS BUSSINESSDATALAYER

CREATE THE TABLE FOR DROPDOWNLIST  FROM WHICH dropdownlist list will be fetched
eg- tblwork_nts
parameters-
NT_SLNO    int    Unchecked
NT_ID        Unchecked
NT_NAME    nvarchar(MAX)    Checked
NT_ADMIN    nvarchar(10)    Checked

DECLARE A DATASET METHOD IN THAT FOR FETCHING

1.
  public DataSet Bind2DDL()
        {

            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);
            SqlCommand cmd = new SqlCommand("select * from tblwork_nts", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds;
        }

 2. CREATE CONTROLLER eg-NTF

DECLARE A METHOD IN THAT

eg-
 public ActionResult bindntfworkddl()
        {
            BussinessDataLayer bdl = new BussinessDataLayer();
            DataSet ds = bdl.Bind2DDL();
            ViewBag.fname = ds.Tables[0];
            List<SelectListItem> item = new List<SelectListItem>();
            foreach (DataRow dr in ViewBag.fname.Rows)
            {
                item.Add(new SelectListItem { Text = @dr["NT_NAME"].ToString(), Value = @dr["NT_NAME"].ToString() });
            }
            ViewBag.NT_NAME = item;
            return View();
        }
3.then call this method in both HTTPPOST AND HTTPGET

4. THEN IN VIEW WRITE THE FOLLOWING CODE  IN THE ROW OF DROPDOWNLIST
 <td>
     Select work type
</td>
<td>
@Html.DropDownList("NT_NAME","select")

                </td>


 Note here NT_NAME will contain your selected dropdownlist value
eg-  ntf.NSF_WORK = fc["NT_NAME"].ToString();

MAKE SURE YOU CALL  bindntfworkddl() METHOD IN BOTH GET AND SET METHOD IN CONTROLLER

THATS ALL
THANKS FOR READING

 



ASP.NET + MVC

IMPLEMENT CHECKBOOK DYNAMICALLY FROM DATABASE MVC


FIRST CREATE CLASS 
eg-Faculty

1.then declare another class for checkbox in that only eg -department

demo-

 public class department
    {
        public string deptid { get; set; }
        public string deptname { get; set; }
        public bool checkedstatus { get; set; }
    }

 public class Faculty:department
    {
      public List<department> departmentlist { get; set; }
    }

2.then create a controller Faculty
then write the following list method



  public List<department> Binddepartment()
        {

            List<department> objdpartment = new List<department>();
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);
            SqlCommand cmd = new SqlCommand("select * from tblDEPARTMENT where DP_STATUS='1' OR DP_STATUS='2'", con);
            con.Open();
            SqlDataReader sdr = cmd.ExecuteReader();
            while (sdr.Read())
            {
                department DEPT = new department();
                DEPT.deptname = sdr["DP_NAME"].ToString();
                objdpartment.Add(DEPT);

            }
            return (objdpartment);

        }

3.then paste these code in your get property

  public ActionResult check()
        {
            Facultyall fa = new Facultyall();
            fa.departmentlist = new List<department>();
            fa.departmentlist = Binddepartment();
            return View(fa);
        }

4. then paste this in your post properties

  StringBuilder sb = new StringBuilder();
            foreach (var item in fa.departmentlist)
            {
                if (item.checkedstatus == true)
                {
                    sb.Append(item.deptname + ",").AppendLine();
                }
            }
            sb.Remove(sb.ToString().LastIndexOf(","), 1);

Note: here sb.tostring will contain your selected checkboxes

then in your view ,write the following code
 <div class="editor-field">
                       @for (int i = 0; i < Model.departmentlist.Count; i++)
                      {
                         
                    @Html.CheckBoxFor(m => Model.departmentlist[i].checkedstatus)
                            @Model.departmentlist[i].deptname
                
                    @Html.HiddenFor(m => Model.departmentlist[i].deptid)
                    @Html.HiddenFor(m => Model.departmentlist[i].deptname)
                        
                      }
                     
                    </div>

Note: at last again return the check method in post properties
just copy and paste the check method before return view()


thats all..thanks for reading...