Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdown and between clause

Status
Not open for further replies.

adugenet

Technical User
Feb 24, 2007
48
US
I have a dropdown list for the users to select operators like ">", "<".... and there is a textbox where the user enter the dollar value so far so good but when the user select "between" clause from the operator dropdown list I would like to add another text box and enter two values.I am just wondering how i could do this and I really appreciate if you provide me a clue or a tutorial site.
thank you
 
To dynamically add a TextBox, you can create an instance of one and then use the Controls.Add method of the container. Alternativly, you could create a TextBox at design time nad just toggle it's Visibile property on the SelectedIndexChanged event of the DropDownList.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thank you ca8msm for your response.I will work with second alternative and come back if i encounter any problem. thanks
 
Below is the code i am using and It is supposed to show the second dropdown which is DollarValue1 when i select between caluse. Even if I select Between clause the second dropdown is not showing up. any help would be appreciated


Partial Class financialRpt_financeRpt
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
OperatorSelector()
Year()
GetDollarValue()

End If
If drOperator.SelectedIndex.ToString = "Between" Then
GetDollarValue1()
lblTo.Visible = True
lblDoll2.Visible = True
End If
End Sub

Sub OperatorSelector()

drOperator.Items.Insert(0, New ListItem("<", 0))
drOperator.Items.Insert(1, New ListItem("<=", 1))
drOperator.Items.Insert(2, New ListItem("<>", 2))
drOperator.Items.Insert(3, New ListItem("=", 3))
drOperator.Items.Insert(4, New ListItem(">", 4))
drOperator.Items.Insert(5, New ListItem(">=", 5))
drOperator.Items.Insert(6, New ListItem("Between", 6))

End Sub
Sub Year()
drYearCont.Items.Insert(0, New ListItem("--Date--", 0))
drYearCont.Items.Insert(1, New ListItem("1999", 1))
drYearCont.Items.Insert(2, New ListItem("2000", 2))
drYearCont.Items.Insert(3, New ListItem("2001", 3))
drYearCont.Items.Insert(4, New ListItem("2002", 4))
drYearCont.Items.Insert(5, New ListItem("2003", 5))
drYearCont.Items.Insert(6, New ListItem("2004", 6))
drYearCont.Items.Insert(7, New ListItem("2005", 7))
drYearCont.Items.Insert(8, New ListItem("2006", 8))
drYearCont.Items.Insert(9, New ListItem("2007", 9))
End Sub
Sub GetDollarValue()

Dim myDollar As SortedList
myDollar = New SortedList
myDollar.Add("1000000", "1 Million")
myDollar.Add("5000000", "5 Million")
myDollar.Add("10000000", "10 Million")
myDollar.Add("15000000", "15 Million")
myDollar.Add("20000000", "20 Million")
myDollar.Add("25000000", "25 Million")
myDollar.Add("0", "----Select----")
ddlDollarValue.DataSource = myDollar
ddlDollarValue.DataValueField = "Key"
ddlDollarValue.DataTextField = "Value"
ddlDollarValue.DataBind()

End Sub

Sub GetDollarValue1()

Dim myDollar1 As SortedList
myDollar1 = New SortedList
myDollar1.Add("1000000", "1 Million")
myDollar1.Add("5000000", "5 Million")
myDollar1.Add("10000000", "10 Million")
myDollar1.Add("15000000", "15 Million")
myDollar1.Add("20000000", "20 Million")
myDollar1.Add("25000000", "25 Million")
myDollar1.Add("0", "----Select----")
ddlDollarValue1.DataSource = myDollar1
ddlDollarValue1.DataValueField = "Key"
ddlDollarValue1.DataTextField = "Value"
ddlDollarValue1.DataBind()

End Sub

End Class
 
thank you for your reply.yes i set the dropdown to true. the problem is this line is never be true and I do not know why

If drOperator.SelectedValue.Equals("Between") Then
GetDollarValue1()
lblTo.Visible = True
lblDoll2.Visible = True
End If
 
The comparison is case sensitive.. make sure "Between" is being comepare with "Between" and not "between" or "BETWEEN" etc.
 
thank you jbenson001 for your reply agin. I took your suggestions I checked Between clasue and it is spelled the same in both places and yet it is still not executing this line.
it is a bit strange...any other clue? thanks a bunch
If drOperator.SelectedValue.Equals("Between") Then
GetDollarValue1()
lblTo.Visible = True
lblDoll2.Visible = True
End If
 
Step through your code. Put a stop at the IF statment and step through line by line from there.
 
thank you jbenson001 again for your reply.I added one line to see the value selected from the drOperator and found out that instead of "Between" the value is "6" I think i am getting close to make it work. thank you

Dim test As String = drOperator.SelectedValue.ToString
If drOperator.SelectedValue.Equals("6") Then
 
finally I resolve it ....somehow an additional space was added to drOperator.SelectedItem.ToString and I trimmed it and now it worked for me.thank you for your tips

Dim test2 As String = drOperator.SelectedItem.ToString
Dim test3 As String = Trim(test2)
 
how can I make sure this line executes once when the operator selected is "between" I was just going to put between If Not IsPostBack but if I do this it won't execute when the selection is between clause. any idea?
thanks
I have the below code in the page_load event section

If Trim(drOperator.SelectedItem.ToString) = "Between" Then
lblTo.Visible = True
lblDoll2.Visible = True
ddlDollarValue1.Visible = True
GetDollarValue1()
Else
lblTo.Visible = False
lblDoll2.Visible = False
ddlDollarValue1.Visible = False
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top