hi,
I have write a code to when dropdownList change event, according to the dropdown number i need to change the records in the same page.
See below code
View
<label> @Html.DropDownList("LeadsID", (SelectList)ViewBag.Values, new { onchange="FindLeadDetails(this.value)" })</label>
<label>Firs tname</label>
@Html.TextBoxFor(fname => fname.Firstname)
<label>Last Name</label>
@Html.TextBoxFor(lname => lname.Lastname)
<label>Comapny name</label>
@Html.TextBoxFor(cname => cname.Companyname)
<label>Address </label>
@Html.TextBoxFor(model => model.Address1)
Open in new window
Model.cs
private string connstring = ConfigurationManager.ConnectionStrings["UsersContext"].ConnectionString;
public string LeadsOwner {get;set;}
public string Title {get;set;}
public string Firstname {get;set;}
public string Lastname {get;set;}
public string Companyname {get;set;}
public string Address1 {get;set;}
public string Address2 {get;set;}
public string Address3 {get;set;}
public string Address4 {get;set;}
public string City {get;set;}
public string TelephoneNumber {get;set;}
public string Webaddress {get;set;}
public string LeadStatus {get;set;}
public string LeadsSource {get;set;}
public string Industry {get;set;}
public DateTime CreatedDate { get; set; }
public string Email { get; set; }
public SelectList LeadID { get; set; }
public List<SelectList> LeadsID { get; set; }
public IEnumerable<SelectListItem> Items { get; set; }
public void FindLeadsDetailsById(string LeadID)
{
string custTitle = string.Empty;
SqlConnection con = new SqlConnection(connstring);
con.Open();
SqlCommand Leadscommand = con.CreateCommand();
Leadscommand.CommandText = "SELECT LeadsID,Title,Firstname,Lastname,Companyname,Address1,TelephoneNumber,Webaddress,LeadStatus,LeadsSource,Industry FROM tblLeads WHERE LeadsID='"+LeadID+"'";
SqlDataReader rdrReadr = Leadscommand.ExecuteReader();
while (rdrReadr.Read())
{
Firstname = rdrReadr["Firstname"].ToString();
}
rdrReadr.Close();
Leadscommand.Dispose();
con.Close();
//tblLeads
}
public List<SelectListItem> pupulateLeadsID()
{
string strLeadID = string.Empty;
SqlConnection con = new SqlConnection(connstring);
List<SelectListItem> itemsID = new List<SelectListItem>();
con.Open();
SqlCommand cmdLeadsID = con.CreateCommand();
cmdLeadsID.CommandText = "SELECT LeadsID FROM tblLeads";
SqlDataReader rdrLeadID = cmdLeadsID.ExecuteReader();
while (rdrLeadID.Read())
{
itemsID.Add(new SelectListItem { Text = rdrLeadID[0].ToString(), Value = rdrLeadID[0].ToString() });
}
rdrLeadID.Close();
cmdLeadsID.Dispose();
con.Close();
return itemsID;
}
Open in new window
Controler
public ActionResult UpdateLeads()
{
Leads ldl = new Leads();
ViewBag.LeadsID = ldl.pupulateLeadsID();
return View();
}
public ActionResult FindLeadDetails(string LeadID)
{
Leads ld = new Leads();
ld.FindLeadsDetailsById(LeadID);
return View(ld);
}
Open in new window
//keep exisiting below code as it is
Open in new window
Open in new window