Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 28, 2012 06:12 PM by repeater09
Member
7 Points
69 Posts
Apr 27, 2012 06:45 AM|LINK
Hi
My drop down list has some items
if I select any item from drop down list that should have to be stored in database(selected item)
if anybody knows the answer please help me
Contributor
3230 Points
668 Posts
Apr 27, 2012 06:48 AM|LINK
hi,
use dropdownlist selected index event
String str = DropDownList1.SelectedValue;
store it in data base
Apr 27, 2012 07:05 AM|LINK
can u send me the complete answer in mvc3
All-Star
135142 Points
21676 Posts
Moderator
MVP
Apr 27, 2012 07:49 AM|LINK
chandana G if I select any item from drop down list that should have to be stored in database(selected item)
Basic question.
See tutorials from http://www.asp.net/mvc .
392 Points
127 Posts
Apr 27, 2012 11:08 AM|LINK
public class MyModel { public string DropDownNameInForm {get;set;} //other properties } In View. <input type="select" name ="DropDownNameInForm" id ="DropDownNameInForm" /> or @Html.DropDownListFor(m => m.DropDownNameInForm)
Apr 28, 2012 04:13 AM|LINK
I wrote the following code but I got 13 drop down lists with 13 items(in table name field have 13 items) but I need 1 only how to resolve this here is my controller private sampleEntities db = new sampleEntities(); public ActionResult Index() { var GenreLst = new List<string>(); var GenreQry = from d in db.emps orderby d.name select d.name; GenreLst.AddRange(GenreQry.Distinct()); ViewBag.movieGenre = new SelectList(GenreLst); return View(db.emps.ToList()); view: }<h2>Index</h2> <%:ViewBag.Title="Index" %> <p> <%: Html.ActionLink("Create New", "Create") %> </p> <table> <tr> <th> name </th> <th></th> </tr> <% foreach (var item in Model) { %> <tr> <td> <%:Html.DropDownList("movieGenre") %> </td> <td> <%: Html.ActionLink("Edit", "Edit", new { id=item.Id }) %> | <%: Html.ActionLink("Details", "Details", new { id=item.Id }) %> | <%: Html.ActionLink("Delete", "Delete", new { id=item.Id }) %> </td> </tr> <% } %> </table> </asp:Content>
asp.netmvc3
12 Points
20 Posts
Apr 28, 2012 06:12 PM|LINK
This is how i have mine:
Model:
[Required(ErrorMessage = "Whatever you would like.")] public bool? nameOfString { get; set; }
and then in the View:
@Html.DropDownListFor(x => x.ZNameOfString, new[] { new SelectListItem() {Text = "WhateverYouWouldLike", Value = bool.TrueString}, new SelectListItem() {Text = "WhateverYouWouldLike", Value = bool.FalseString} }, "ThisIsWhatTheDefaultValueWillBe")
..Hope this helps
chandana G
Member
7 Points
69 Posts
how to save a item in the database when we select that item from drop down list in mvc3 app
Apr 27, 2012 06:45 AM|LINK
Hi
My drop down list has some items
if I select any item from drop down list that should have to be stored in database(selected item)
if anybody knows the answer please help me
tusharrs
Contributor
3230 Points
668 Posts
Re: how to save a item in the database when we select that item from drop down list in mvc3 app
Apr 27, 2012 06:48 AM|LINK
hi,
use dropdownlist selected index event
String str = DropDownList1.SelectedValue;
store it in data base
( Mark as Answer if it helps you out )
View my Blog
chandana G
Member
7 Points
69 Posts
Re: how to save a item in the database when we select that item from drop down list in mvc3 app
Apr 27, 2012 07:05 AM|LINK
can u send me the complete answer in mvc3
ignatandrei
All-Star
135142 Points
21676 Posts
Moderator
MVP
Re: how to save a item in the database when we select that item from drop down list in mvc3 app
Apr 27, 2012 07:49 AM|LINK
Basic question.
See tutorials from http://www.asp.net/mvc .
ossprologix
Member
392 Points
127 Posts
Re: how to save a item in the database when we select that item from drop down list in mvc3 app
Apr 27, 2012 11:08 AM|LINK
public class MyModel { public string DropDownNameInForm {get;set;} //other properties } In View. <input type="select" name ="DropDownNameInForm" id ="DropDownNameInForm" /> or @Html.DropDownListFor(m => m.DropDownNameInForm)chandana G
Member
7 Points
69 Posts
Re: how to save a item in the database when we select that item from drop down list in mvc3 app
Apr 28, 2012 04:13 AM|LINK
I wrote the following code but I got 13 drop down lists with 13 items(in table name field have 13 items)
</div> </div>but I need 1 only how to resolve this
here is my controller
private sampleEntities db = new sampleEntities();
public ActionResult Index()
{
var GenreLst = new List<string>();
var GenreQry = from d in db.emps
orderby d.name
select d.name;
GenreLst.AddRange(GenreQry.Distinct());
ViewBag.movieGenre = new SelectList(GenreLst);
return View(db.emps.ToList());
view:
}<h2>Index</h2>
<%:ViewBag.Title="Index" %>
<p>
<%: Html.ActionLink("Create New", "Create") %>
</p>
<table>
<tr>
<th>
name
</th>
<th></th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%:Html.DropDownList("movieGenre") %>
</td>
<td>
<%: Html.ActionLink("Edit", "Edit", new { id=item.Id }) %> |
<%: Html.ActionLink("Details", "Details", new { id=item.Id }) %> |
<%: Html.ActionLink("Delete", "Delete", new { id=item.Id }) %>
</td>
</tr>
<% } %>
</table>
</asp:Content>
asp.netmvc3
repeater09
Member
12 Points
20 Posts
Re: how to save a item in the database when we select that item from drop down list in mvc3 app
Apr 28, 2012 06:12 PM|LINK
This is how i have mine:
Model:
[Required(ErrorMessage = "Whatever you would like.")] public bool? nameOfString { get; set; }and then in the View:
@Html.DropDownListFor(x => x.ZNameOfString, new[] { new SelectListItem() {Text = "WhateverYouWouldLike", Value = bool.TrueString}, new SelectListItem() {Text = "WhateverYouWouldLike", Value = bool.FalseString} }, "ThisIsWhatTheDefaultValueWillBe")..Hope this helps