Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to fill two textboxes from database on the seletion of dropdownlist.

What I have tried:

can anyone give me demo on this question. i am stucking here.i tried my best.but not getting output.
Posted
Updated 25-May-16 21:57pm
Comments
Karthik_Mahalingam 25-May-16 7:42am    
try this
Asp.net MVC - call database on dropdown value change - Stack Overflow[^]
and come back if you are facing any issue.
Karthik_Mahalingam 26-May-16 1:32am    
where is the code for getting value from database ?
prakash00060 25-May-16 7:42am    
Please clear your need.

1 solution

try this

C#
public ActionResult GetValuesFromDatabase(string inputId)
      {
          int inputid = Convert.ToInt32(inputId);
          using (AccountDBEntities2 acc = new AccountDBEntities2())
          {
              var item = acc.tbl_CustomerCreation.FirstOrDefault(k => k.Account_No == inputid);
              if (item != null) return Json(item);
              else
                  return null;
          }
      }


in the ajax success method:

JavaScript
      success: function(response) {
//assign values to your textboxes.
$("#CustomerName").val(response.Customer_Name);
$("#Address").val(response.Billing_Address);
}
 
Share this answer
 
Comments
Member 12385326 26-May-16 4:12am    
@karthik still it is not working :(
Karthik_Mahalingam 26-May-16 4:18am    
ok.
Follow these steps
keep a break point in this method (GetValuesFromDatabase) and execute line by line and check whether you are getting the item
Karthik_Mahalingam 26-May-16 5:27am    
try this
int inputid = Convert.ToInt32(inputId);
AccountDBEntities2 acc = new AccountDBEntities2();
var item = acc.tbl_CustomerCreation.FirstOrDefault(k => k.Account_No == inputid);
if (item != null) return Json(item);
else
return null;
Karthik_Mahalingam 26-May-16 5:44am    
try this
var _inputID = $("#SalesOrderAccNoDropDown1").val();
var link = '@Url.Action("GetValuesFromDatabase", "Quotation")'
var args = {inputID: _inputID};

$.ajax({
type: "POST",
url: link,
data: args,
dataType: "json",
success: function (result) {
alert(response.Biliing_Address)
},
error: function (httpRequest, textStatus, errorThrown) {
alert("Error: " + textStatus + " " + errorThrown + " " + httpRequest);
}
});
Karthik_Mahalingam 26-May-16 5:51am    
ok fine. you use your old code only..
are you getting the inputID in Actionmethod ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900