I agree with what F-ES Sitecore. What you can do is to add an optione "Others" in your
DropDownList
and once that option is selected, then you can place a
TextBox
and a
Button
in a
Panel
/
Div
to group them and then trigger that
Div
to be shown in the page. You have two options to do that if you are working on ASP.NET WebForms.
First option is using Server-side implementation, and that is to handle the
DropDownList_SelectedIndexChanged
event and on that event, you can check for the "Others" value and show your
TextBox
to the page where users can input data and then at
Button_Click
event, you can write a code to insert that data into your database. You don't need a Web API to implement this not unless if your data is coming from different server.
The second option is using Client-side implementation, could be plain
JavaScript
or
jQuery
. And you need to create a Web API or Page Method or Web Service to access your data via AJAX call. Here's a quick example using plain
JavaScript
:
HTML:
<select name="color" onchange='checkvalue(this.value)'>
<option>Select Authors</option>
<option value="1">You</option>
<option value="2">Me</option>
<option value="others">Others</option>
</select>
<div id="divNewEntry" style='display:none'>
<input type="text" id="txtNewAuthor" />
<input type="button" id="btnSave" value="Save" />
</div>
JavaScript:
function checkvalue(val)
{
if(val==="others")
document.getElementById('divNewEntry').style.display='block';
else
document.getElementById('divNewEntry').style.display='none';
}
Once you've done that, you can then use jQuery AJAX to communicate with your server (API) to insert the database at Button's Click event something like this:
$(document).ready(function () {
$('#btnSave').click(function () {
$.ajax({
type: 'GET',
url: 'api/Author',
dataType: 'json',
success: function (data) {
}
});
});
});
Here's a great article that talks about how to access your data using jQuery AJAX:
Many ways to communicate with your database using jQuery AJAX and ASP.NET[
^]