I have a repeater with checkboxes and a dropdownlist. Depending on the value selected in the dropdownlist, I want the checkboxes to be displayed or not displayed.
Everything works fine, except for the initial display. If the repeater opens with the "non-display" dropdown value selected on any line, the checkboxes don't respond. That is, if I select a "display" dropdown value and the checkboxes are non-displayed, they remain so. However, it seems that as soon as the screen does a post-back, such as when adding a new row to the repeater, then all the dropdowns work properly. It's the initial setting that's the problem.
I'm fairly new to javascript, so maybe someone can see what I'm missing (I'm using asp.net 1.1).
This is the critical code inside the repeater ItemDataBound event:
ddlFieldTypes = CType(e.Item.FindControl("ddlFieldType"), DropDownList) 'The dropdown list
With ddlFieldTypes
.AutoPostBack = False
.EnableViewState = True
.DataSource = GetFieldTypes()
.DataValueField = "FieldTypeId"
.DataTextField = "FieldType"
.DataBind()
.SelectedValue = dtFields.Rows(e.Item.ItemIndex).Item("FieldTypeId"))
End With
' Here's the string defining the javascript function that sets the display mode of the checkbox. Note that each row of the repeater has a unique function defined by the dropdownlist ClientId. If the field type is "Note", then the checkbox should be invisible, otherwise visible.
Dim strFieldTypes As String
strFieldTypes = "<script language='javascript'> " & _
"function " & ddlFieldTypes.ClientID & "_SelectedIndexChanged()" & _
"{" & _
"var ftype = document.getElementById('" & ddlFieldTypes.ClientID & "');" & _
"var fname = ftype.options[ftype.selectedIndex].text;" & _
"var fsort1 = document.getElementById('" & chkSortField1.ClientID & "');" & _
"if (fname=='Note') {" & _
"fsort1.style.display = 'none';" & _
"} else {" & _
"fsort1.style.display = 'inline';" & _
"}" & _
"return true;" & _
"}" & _
"</script>"
' Register the startup script
If Not Page.IsStartupScriptRegistered(ddlFieldTypes.ClientID) Then
Page.RegisterStartupScript(ddlFieldTypes.ClientID, strFieldTypes)
End If
' Add the function to the dropdownlist onchange event.
ddlFieldTypes.Attributes.Add("onchange", "return " & ddlFieldTypes.ClientID & "_SelectedIndexChanged();")
THANKS!
Larry
Everything works fine, except for the initial display. If the repeater opens with the "non-display" dropdown value selected on any line, the checkboxes don't respond. That is, if I select a "display" dropdown value and the checkboxes are non-displayed, they remain so. However, it seems that as soon as the screen does a post-back, such as when adding a new row to the repeater, then all the dropdowns work properly. It's the initial setting that's the problem.
I'm fairly new to javascript, so maybe someone can see what I'm missing (I'm using asp.net 1.1).
This is the critical code inside the repeater ItemDataBound event:
ddlFieldTypes = CType(e.Item.FindControl("ddlFieldType"), DropDownList) 'The dropdown list
With ddlFieldTypes
.AutoPostBack = False
.EnableViewState = True
.DataSource = GetFieldTypes()
.DataValueField = "FieldTypeId"
.DataTextField = "FieldType"
.DataBind()
.SelectedValue = dtFields.Rows(e.Item.ItemIndex).Item("FieldTypeId"))
End With
' Here's the string defining the javascript function that sets the display mode of the checkbox. Note that each row of the repeater has a unique function defined by the dropdownlist ClientId. If the field type is "Note", then the checkbox should be invisible, otherwise visible.
Dim strFieldTypes As String
strFieldTypes = "<script language='javascript'> " & _
"function " & ddlFieldTypes.ClientID & "_SelectedIndexChanged()" & _
"{" & _
"var ftype = document.getElementById('" & ddlFieldTypes.ClientID & "');" & _
"var fname = ftype.options[ftype.selectedIndex].text;" & _
"var fsort1 = document.getElementById('" & chkSortField1.ClientID & "');" & _
"if (fname=='Note') {" & _
"fsort1.style.display = 'none';" & _
"} else {" & _
"fsort1.style.display = 'inline';" & _
"}" & _
"return true;" & _
"}" & _
"</script>"
' Register the startup script
If Not Page.IsStartupScriptRegistered(ddlFieldTypes.ClientID) Then
Page.RegisterStartupScript(ddlFieldTypes.ClientID, strFieldTypes)
End If
' Add the function to the dropdownlist onchange event.
ddlFieldTypes.Attributes.Add("onchange", "return " & ddlFieldTypes.ClientID & "_SelectedIndexChanged();")
THANKS!
Larry