In my ASP.Net application, I have a simple dropdown (Note: this is not an ASP element).
<select id="events" name="Events" style="height: 25px;"></select>
I was previously populating this dropdown dynamically using an API and jQuery/Javascript (Note2: This application was originally a purely javascript app but was placed in ASP.Net to get server side and other desired functionality).
let dropdown = $('#events');
//Function to call Asp.Net Web Service and retrieve events list by state
var EventsData = esriRequest({
url: "RII_Service.asmx/GetListOfEventsByState",
content: {
},
dataType: "jsonp",
handleAs: "json"
});
EventsData.then(
function (response) {
events_json = response.ListEvents;
console.log(events_json);
dropdown.empty();
dropdown.append('<option selected="true" disabled>Choose Event Name</option>');
dropdown.prop('selectedIndex', 0);
//Initialize state dropdown on load
if ((document.getElementById("state").value !== null) && (document.getElementById("state").value !== undefined) && (document.getElementById("state").value !== "undefined")) {
var state_pre = document.getElementById("state");
state_name = state_pre.options[state_pre.selectedIndex].value;
filtered_events = events_json.filter(event => (event.State.trim() === state_name));
options = filtered_events.map(event => event.FullEventName);
console.log(options);
$.each(options, function (i, el) {
if ($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);
});
$.each(uniqueNames, function (i, p) {
$('#events').append($('<option></option>').val(p).html(p));
});
}
}, function (error) {
console.log("Error: ", error.message);
});
I have created a simple .mdf
SQL database inside my application to replace calling this API and using an ASP.Net WebService:
It has a table called 'Events'
that I want to use to populate my dropdown:
Although I am not connecting to an outside datasource like SQLServer
or an API, I am still confused as to how to bring in my table and populate the dropdown using my internal .mdf
table. Any suggestions on how to do this? Do I still need the WebService
file or is there an easier way?
1) first of all You have to deattach database from SQL server a) open SQL server b) connect your server c) open node of database and right-click on your database and choose task menu and then choose deattach then database will deattached
2) In the second step in the visual studio right-click on app_data folder and click on add existing item and then select database which you want to add in app_data folder it will be in In my case ( C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\accountdb.mdf) and now this database will add in app_data folder
3) Now change your connection string in the config file Collapse | Copy Code
<connectionstrings>
<add connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Accountdb.mdf;Integrated Security=True;User Instance=True " name="ConnectionASPX" providername="System.Data.SqlClient" />
</connectionstrings>