This question is locked. New answers and comments are not allowed.
hello telerik
i have tried my level best but i'll be u nable to insert a dropdownlist to telerik grid .if you have any solution regarding this then provide me
code will be like this:
@(Html.Telerik().Grid<TelerikMvcApplication3.Models.tb_TestMvc>()
.BindTo((List<TelerikMvcApplication3.Models.tb_TestMvc>)ViewData["db_Test"])
.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).ReadOnly();
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.Bound(p => p.Product).Width(130).Format("{0:d}");
columns.Bound(p => p.ProDetail).Width(130).Format("{0:d}");
columns.Bound(p => p.ProPrice).Width(130).Format("{0:d}");
columns.Bound(p => p.OrderDate).Width(130).Format("{0:d}");
columns.Bound(p => p.country_Id).Width(130).Format("{0:d}");
columns.Bound(p => p.Id)
.ClientTemplate("<img width='100' height='110' alt='<#=Id #>' src='"
+ Url.Content("../../Images/")
+ "<#=Id #>.jpg' />")
.Title("Picture");
//columns.Bound(p => p.country).ClientTemplate(
// Html.Telerik().DropDownList()
// .Name("ddlcnt")
// .BindTo(new SelectList(UserController.GetRoles()))
// .ToHtmlString()
//).Title("CountryName");
//columns.Bound(p => p.Country);
columns.Command(commands =>
{
commands.Edit();
commands.Delete();
});
})
.ToolBar(t =>
{
t.Insert();
})
.Sortable()
.Filterable()
.Pageable(paging=>paging.PageSize(5))
)
on controller it will be like this:
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
var tme = new db_TestEntities1();
ViewData["db_Test"] = 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_TestEntities1 ();
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_TestEntities1();
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_TestEntities1();
ViewData["tb_TestMvc"] = tme.tb_TestMvc.ToList();
return RedirectToAction("Index", "Home");
// return View("Index");
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult _TemplatesClientSide(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 = "Select country_img from tb_Country where country_Id=@country_Id";
cmd1.Connection = con;
cmd1.Parameters.AddWithValue("@country_Id", tst.country_Id);
cmd1.Parameters.AddWithValue("@country_img", tst.country_img);
cmd1.ExecuteNonQuery();
con.Close();
}
var tme = new db_TestEntities1();
ViewData["tb_TestMvc"] = tme.tb_Country.ToList();
return RedirectToAction("Index", "Home");
}
}
}
i have tried my level best but i'll be u nable to insert a dropdownlist to telerik grid .if you have any solution regarding this then provide me
code will be like this:
@(Html.Telerik().Grid<TelerikMvcApplication3.Models.tb_TestMvc>()
.BindTo((List<TelerikMvcApplication3.Models.tb_TestMvc>)ViewData["db_Test"])
.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).ReadOnly();
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.Bound(p => p.Product).Width(130).Format("{0:d}");
columns.Bound(p => p.ProDetail).Width(130).Format("{0:d}");
columns.Bound(p => p.ProPrice).Width(130).Format("{0:d}");
columns.Bound(p => p.OrderDate).Width(130).Format("{0:d}");
columns.Bound(p => p.country_Id).Width(130).Format("{0:d}");
columns.Bound(p => p.Id)
.ClientTemplate("<img width='100' height='110' alt='<#=Id #>' src='"
+ Url.Content("../../Images/")
+ "<#=Id #>.jpg' />")
.Title("Picture");
//columns.Bound(p => p.country).ClientTemplate(
// Html.Telerik().DropDownList()
// .Name("ddlcnt")
// .BindTo(new SelectList(UserController.GetRoles()))
// .ToHtmlString()
//).Title("CountryName");
//columns.Bound(p => p.Country);
columns.Command(commands =>
{
commands.Edit();
commands.Delete();
});
})
.ToolBar(t =>
{
t.Insert();
})
.Sortable()
.Filterable()
.Pageable(paging=>paging.PageSize(5))
)
on controller it will be like this:
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
var tme = new db_TestEntities1();
ViewData["db_Test"] = 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_TestEntities1 ();
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_TestEntities1();
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_TestEntities1();
ViewData["tb_TestMvc"] = tme.tb_TestMvc.ToList();
return RedirectToAction("Index", "Home");
// return View("Index");
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult _TemplatesClientSide(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 = "Select country_img from tb_Country where country_Id=@country_Id";
cmd1.Connection = con;
cmd1.Parameters.AddWithValue("@country_Id", tst.country_Id);
cmd1.Parameters.AddWithValue("@country_img", tst.country_img);
cmd1.ExecuteNonQuery();
con.Close();
}
var tme = new db_TestEntities1();
ViewData["tb_TestMvc"] = tme.tb_Country.ToList();
return RedirectToAction("Index", "Home");
}
}
}