Populate a date Label with selected value from a dropdownlist in GridView. This is not working.
ASP.NET
1
Posts
1
Posters
1
Views
1
Watching
-
Greetings again all and pray that everyone is staying safe. I have a requirement to select a value from a dropdownlist, and upon selecting a value, a label control will be automatically populated with a date value. We are using GridView control. So far, we are running into issues. When I run the code and select a value from the ddlSpeakerName1 dropdownlist control, I get the following error: System.NullReferenceException: 'Object reference not set to an instance of an object.' and the error is on this line:
txtsDateFilmed1.Text = sdr\["dateAdded"\].ToString();
This is not true. I know I am doing something wrong and would greatly appreciate the assistance as always. Here is some relevant code and select a value //MARKUP
//C#
protected void OnDataBound(object sender, EventArgs e) { DropDownList ddlSpeakerName1 = SermonDetails.FooterRow.FindControl("ddlSpeakerName1") as DropDownList; ddlSpeakerName1.DataSource = GetData("SELECT DISTINCT EmployeeID, EmployeeName FROM Employees"); ddlSpeakerName1.DataTextField = "EmployeeName"; ddlSpeakerName1.DataValueField = "EmployeeID"; ddlSpeakerName1.DataBind(); ddlSpeakerName1.Items.Insert(0, new ListItem("Select Speakers", "0")); } protected void ddlSpeakerName1\_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddlSpeakerName1 = SermonDetails.FooterRow.FindControl("ddlSpeakerName1") as DropDownList; TextBox txtsDateFilmed1 = SermonDetails.FooterRow.FindControl("txtsDateFilmed1") as TextBox; String strConnString = ConfigurationManager.AppSettings\["XPhiasResultString"\].ToString(); String strQuery = "select dateAdded from Employees where" + " EmployeeID = @employeeID AND dateAdded IS NOT NULL"; SqlConnection con = new SqlConnection(strConnString); SqlCommand cmd = new SqlCommand(); cmd.Parameters.AddWithValue("@employeeID", ddlSpeake