This is a migrated thread and some comments may be shown as answers.

[Solved] how to edit telerik mvc-3 grid records on the row click event

0 Answers 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
vikas gupta
Top achievements
Rank 1
vikas gupta asked on 12 Jul 2011, 06:29 AM

hi

i want to edit grid view record  on the row click

my below code is working fine for the edit button click

Hi..

Editing paging .sorting is working fine but filter is not working.

 

How can I add dropdown into the country columns

 

My code is here

asox page code

@(Html.Telerik().Grid<TelerikMvcApplication1.Models.tb_TestMvc>()

.BindTo((List<TelerikMvcApplication1.Models.tb_TestMvc>)ViewData["tb_TestMvc"])

        .Name("Grid")

         .DataKeys(keys =>

         {

             keys.Add(p => p.Id);

         })

                  .DataBinding(dataBinding => dataBinding.Server()

                   .Update("UpdateTest", "HOME")

                           .Insert("InsertTest", "HOME")

                                   .Delete("DeleteTest", "HOME")

                           )

              .Columns(columns =>

              {

                  columns.Bound(p => p.Id).Width(210);

                  columns.Bound(p => p.ContactTitle).Width(130).Format("{0:c}");

                  columns.Bound(p => p.ContactName).Width(130).Format("{0:N}");

                  columns.Bound(p => p.Country).Width(130).Format("{0:d}");

               

                  columns.Command(commands =>

                      {

                          commands.Edit();

                          commands.Delete();

                      });

              })

                       

                           .ToolBar(t =>

                           {

                               t.Insert();

                           })

 

          .Sortable()

         

      .Pageable(paging => paging.PageSize(5))

           .Filterable()

           

          )

 

 

On controller code

 

 

  public ActionResult Index()

        {

          

            ViewBag.Message = "Welcome to ASP.NET MVC!";

            var tme = new db_TestEntities();

            ViewData["tb_TestMvc"] = tme.tb_TestMvc.ToList();

           

            return View();

        }

 

 

       

        public ActionResult About()

        {

            return View();

        }

       

        

        [AcceptVerbs(HttpVerbs.Post)]

        public ActionResult UpdateTest(int Id)

        {

            var tst = new test

            {

                Id = Id,

                

            };

            if (TryUpdateModel(tst))

            {

                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);

                if (con.State == ConnectionState.Closed)

                {

                    con.Open();

                }

                SqlCommand cmd1 = new SqlCommand();

                cmd1.CommandText = "Update tb_TestMvc set Contacttitle=@Contacttitle,ContactName=@ContactName,Country=@country where Id=@Id";

                cmd1.Connection = con;

                cmd1.Parameters.AddWithValue("@Id", Id);

                cmd1.Parameters.AddWithValue("@Contacttitle", tst.Contacttitle);

              cmd1.Parameters.AddWithValue("@ContactName", tst.ContactName) ;

              cmd1.Parameters.AddWithValue("@Country", tst.Country);

                cmd1.ExecuteNonQuery();

                con.Close();

            }

 

            var tme = new db_TestEntities();

            ViewData["tb_TestMvc"] = tme.tb_TestMvc.ToList();

            return RedirectToAction("Index", "Home");

           // return View("Index");

           

        }

 

 

        [AcceptVerbs(HttpVerbs.Post)]

        public ActionResult InsertTest(int Id, string Contacttitle)

        {

            var tst = new test

            {

                Id = Id,

 

            };

            if (TryUpdateModel(tst))

            {

                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);

                if (con.State == ConnectionState.Closed)

                {

                    con.Open();

                }

                SqlCommand cmd1 = new SqlCommand();

                cmd1.CommandText = "Insert into tb_TestMvc (Id,Contacttitle,ContactName,Country) values (@Id,@Contacttitle,@ContactName,@Country)";

                cmd1.Connection = con;

                cmd1.Parameters.AddWithValue("@Id", Id);

                cmd1.Parameters.AddWithValue("@Contacttitle", Contacttitle);

                cmd1.Parameters.AddWithValue("@ContactName", tst.ContactName) ;

                cmd1.Parameters.AddWithValue("@Country", tst.Country);

                cmd1.ExecuteNonQuery();

                con.Close();

            }

 

            var tme = new db_TestEntities();

            ViewData["tb_TestMvc"] = tme.tb_TestMvc.ToList();

            return RedirectToAction("Index", "Home");

            // return View("Index");

 

        }

         [AcceptVerbs(HttpVerbs.Post)]

        public ActionResult DeleteTest(int Id, string Contacttitle)

        {

            var tst = new test

            {

                Id = Id,

 

            };

            if (TryUpdateModel(tst))

            {

                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);

                if (con.State == ConnectionState.Closed)

                {

                    con.Open();

                }

                SqlCommand cmd1 = new SqlCommand();

                cmd1.CommandText = "Delete from tb_TestMvc where Id=@Id";

                cmd1.Connection = con;

                cmd1.Parameters.AddWithValue("@Id", Id);

               

                cmd1.ExecuteNonQuery();

                con.Close();

            }

 

            var tme = new db_TestEntities();

            ViewData["tb_TestMvc"] = tme.tb_TestMvc.ToList();

            return RedirectToAction("Index", "Home");

            // return View("Index");

 

        }

        }


How can i edit the particular row on the row click event





Tags
Grid
Asked by
vikas gupta
Top achievements
Rank 1
Share this question
or