Question Confused By THe Simplest Dropdown List

BitLost

Active member
Joined
Dec 10, 2016
Messages
35
Programming Experience
Beginner
Be kind to me. What I know about C# and ASP I have only picked up in the last week or so. I am migrating from Access and think I am doing okay with my limited knowledge.

I working on a rather complex tool for work. I have been working on this off and on for over 10 years. Hence it is complex, however, in line with my personal style coding is minimised.

One aspect that is driving me nuts though...I have been developing experimental pages in razor view cshtml. Whilst this may not be the best tool for the job, for now it is fine for my purposes.

The one thing driving me nuts is how to find out hw to create and databind a drop down listbox or in access parlance a combo box. I am wanting to set up an administration portal for myself and my assistant so we can start populating the database whilst I work on the other tools. To do this I need to tie the data dropdown list to a SQL statement SELECT * FROM tblTable. This is to allow the webgrid to populate with the table being referenced. I know this is susceptible to SQL injection however for the purpose on the level we are working it is ok.

I cant even work out how to search in google to get an answer as I don't know what to ask if that makes sense

Thanks
 
If you're using Razer then you're using MVC, so qualifying a web search with that will help.

https://www.bing.com/search?q=c#+mvc+dropdown

Depending on which version you're using, you'll either use an HTML helper or a tag helper. In the case of the former, you'll call Html.DropDown or .DropDownFor. For the latter, you'll use a <select> tag with the appropriate 'asp' attributes. You specify which property of the model to bind to and you specify where to get the items from, which might be a property of the model or in ViewData/ViewBag.
 
If you're using Razer then you're using MVC, so qualifying a web search with that will help.

https://www.bing.com/search?q=c#+mvc+dropdown

Depending on which version you're using, you'll either use an HTML helper or a tag helper. In the case of the former, you'll call Html.DropDown or .DropDownFor. For the latter, you'll use a <select> tag with the appropriate 'asp' attributes. You specify which property of the model to bind to and you specify where to get the items from, which might be a property of the model or in ViewData/ViewBag.

Thanks very much. I didn't realise Razor was actually MVC. I was planning to build the SQL backend, get some of the new data populated into it and at the same time start to learn the MVC method as I thought it looks better.
 
the MVC method [...] looks better.

Web Forms was designed to make web development as much like Windows development as possible but, as someone who cut their teeth*in .NET on Windows Forms, Web Forms always felt very clunky and unnatural to me. MVC feels far more natural for the web to me and, while it may appear to require more work to begin with, it doesn't really when you get a feel for it.
 
Web Forms was designed to make web development as much like Windows development as possible but, as someone who cut their teeth*in .NET on Windows Forms, Web Forms always felt very clunky and unnatural to me. MVC feels far more natural for the web to me and, while it may appear to require more work to begin with, it doesn't really when you get a feel for it.

In my simple view...I said I have developed a technique for not coding in Access.

MVC is a little like a form in Access which has the form controls on it and code directing to another module

A module to handle the validation and processing. I.E. calculate the chemical amount to add

A separate module to save the records once the validation is completed.

Don't know if I have it right yet. But this seems to make sense to me. The biggest challenge I am finding is getting simple things done like not inlist for drop down, or populating a drop down...this is so annoying. I am working on your suggestions and appreciate your guidance very much.

Thanks once again
 

Latest posts

Back
Top Bottom