How do I ensure Repeater rows remain visible when adding a new blank row?
-
I have 2 dropdowns, DroDownList1 and DropDownList2. To insert records into the database, I select a value from DropDownList1 and based on specified condition, a value is automatically inserted into DropDownList2. Then when I select a value, say 1, from DropDownList2, one row is automatically created in Repeater control. If I select 2, two rows are automatically created. Finally, if I select 3 again from DropDownList2, three rows are automatically created in Repeater control. Three rows is the maximum number of rows that can be created because 3 values (1,2,3) are the maximum that can be populated into DropDownList2. Then we insert the records into the database. This entire operation works great. Then to retrieve the records we just inserted based on the description above, I use the following method:
Protected Sub btnSearch(ByVal sender As Object, ByVal e As EventArgs) Dim address As String = Request.Form(txtSearch.UniqueID) 'get the results and fill in the form Dim sqlStatement As String = "Select ad.returnonly, ad.Assets,ad.NoOfItemsToReplace,ap.MailAddress,o.PrimaryFirst, o.Phone, o.AltPhone,o.Email,o.PrimaryLast, o.ownerID, ap.applicant, FORMAT(ap.DateReceived, 'd','us') as DateReceived,ad.InstallAddress,ad.InstallCity, ad.InstallState, ad.InstallZip from Applications ap " sqlStatement += "inner Join Addresses ad on ap.WaterAccountNo = ad.WaterAcctNo inner join Owner o on ap.OwnerCode = o.OwnerID Where ad.Installation = 1 and ad.InstallAddress Like '%" & address.Replace("'", "''").Trim() & "%'" Dim sqlCmd As SqlCommand = New SqlCommand(sqlStatement, myConnection) Dim reader As SqlDataReader = sqlCmd.ExecuteReader() If reader.HasRows Then While reader.Read() DropDownList1.Text = reader("Assets").ToString() DropDownList1\_SelectedIndexChanged(Nothing, Nothing) DropDownList2.Text = reader("NoOfItemsToReplace").ToString() End While Else End If reader.Close() sqlCmd.Dispose() End Sub
The above method populates DropdownList1 values and selects the inserted value by default. For instance, if 2 is selected from the list and inserted into the database, during select statements, 2 will be selected as the default value for DropDownList1. Same is the case with DropDownList2 but more importantly, the below method
-
I have 2 dropdowns, DroDownList1 and DropDownList2. To insert records into the database, I select a value from DropDownList1 and based on specified condition, a value is automatically inserted into DropDownList2. Then when I select a value, say 1, from DropDownList2, one row is automatically created in Repeater control. If I select 2, two rows are automatically created. Finally, if I select 3 again from DropDownList2, three rows are automatically created in Repeater control. Three rows is the maximum number of rows that can be created because 3 values (1,2,3) are the maximum that can be populated into DropDownList2. Then we insert the records into the database. This entire operation works great. Then to retrieve the records we just inserted based on the description above, I use the following method:
Protected Sub btnSearch(ByVal sender As Object, ByVal e As EventArgs) Dim address As String = Request.Form(txtSearch.UniqueID) 'get the results and fill in the form Dim sqlStatement As String = "Select ad.returnonly, ad.Assets,ad.NoOfItemsToReplace,ap.MailAddress,o.PrimaryFirst, o.Phone, o.AltPhone,o.Email,o.PrimaryLast, o.ownerID, ap.applicant, FORMAT(ap.DateReceived, 'd','us') as DateReceived,ad.InstallAddress,ad.InstallCity, ad.InstallState, ad.InstallZip from Applications ap " sqlStatement += "inner Join Addresses ad on ap.WaterAccountNo = ad.WaterAcctNo inner join Owner o on ap.OwnerCode = o.OwnerID Where ad.Installation = 1 and ad.InstallAddress Like '%" & address.Replace("'", "''").Trim() & "%'" Dim sqlCmd As SqlCommand = New SqlCommand(sqlStatement, myConnection) Dim reader As SqlDataReader = sqlCmd.ExecuteReader() If reader.HasRows Then While reader.Read() DropDownList1.Text = reader("Assets").ToString() DropDownList1\_SelectedIndexChanged(Nothing, Nothing) DropDownList2.Text = reader("NoOfItemsToReplace").ToString() End While Else End If reader.Close() sqlCmd.Dispose() End Sub
The above method populates DropdownList1 values and selects the inserted value by default. For instance, if 2 is selected from the list and inserted into the database, during select statements, 2 will be selected as the default value for DropDownList1. Same is the case with DropDownList2 but more importantly, the below method
Can someone please help? I have attached two screenshots to help explain the issue I am having. The first screenshot shows what happens when I value is selected from DropDownList2. It automatically displays the row with 5 columns with values. https://www.kenig-dev.tech/wp-content/uploads/2023/03/1.png[^] The second screenshot shows when the user changes the value of DropDownList2 from 1 to 2. Rather than retain the first row with values and add a second black row, the first row was reset and replaced with 2 blank rows. https://www.kenig-dev.tech/wp-content/uploads/2023/03/2.png[^] How can we retain the first row with its values while adding a second blank row that allows user to enter values into that second row?