First item in a DropDownList
-
When i create a DropDownList normaly the selected item event fires when a new item is selected. But when i choose the first item it doenst fire so i never can choose the first item in a DDL. Anny solution.
This problem is quit common but actually it is not any problem it is just a logic the event in code behind is associated with the selected index change of DDL when the index is same there is no need to fire the event. anyway the solution is : have you ever notice the status bar when your mouse is over the link button. :) that is actually java script which postback the page simple do one thing with the use of javascript find an event which fires accorfing to your wish. Since javascript have many events :). and at that specific event dopostback to the server and call you desire method For posting the page back from java script http://www.codeproject.com/aspnet/jsnopostback.asp [^] read this article I wish my participation in your problem will be helpfull 4 you if you solve the problem in some other way do let me know Best Regards
-
This problem is quit common but actually it is not any problem it is just a logic the event in code behind is associated with the selected index change of DDL when the index is same there is no need to fire the event. anyway the solution is : have you ever notice the status bar when your mouse is over the link button. :) that is actually java script which postback the page simple do one thing with the use of javascript find an event which fires accorfing to your wish. Since javascript have many events :). and at that specific event dopostback to the server and call you desire method For posting the page back from java script http://www.codeproject.com/aspnet/jsnopostback.asp [^] read this article I wish my participation in your problem will be helpfull 4 you if you solve the problem in some other way do let me know Best Regards
The problem is that a user after having eneterded a name and hitting the backspace gest a dropdowlist with choices. if his coice is the first name on the list than that choice should be honored. The page you refered to doenst say me anything becourse i am a simpley guy just building a simple page and not a java programmer. Yet another piece of magic to learn :-)
-
The problem is that a user after having eneterded a name and hitting the backspace gest a dropdowlist with choices. if his coice is the first name on the list than that choice should be honored. The page you refered to doenst say me anything becourse i am a simpley guy just building a simple page and not a java programmer. Yet another piece of magic to learn :-)
-
Dear that is javascript not java :) anyway .. can you show me that page so that i can know what exactly you want .
Sorry but cant show the page becourse it is behind a secure company website running ISS. The outside websites running Apache so not asp.net able. But i am trying a other aproach adding a extra row on the dataset.table. This code: Else 'Found many Rows and place them in a DropDownList Dim dataRow As DataRow dataRow = dataSet.Tables("Horses").NewRow() dataRow.Item("Horse_name") = "--Select a Horse--" dataRow.Item("Horse_NF") = "--Select a Horse--" dataRow.Item("FEI_Pass_No") = "--Select a Horse--" dataRow.Item("Sex") = "--Select a Horse--" dataRow.Item("Horse_DOB") = "--Select a Horse--" dataSet.Tables(0).Rows.Add(dataRow) dataListHorses.DataSource = dataSet.Tables("Horses").DefaultView dataListHorses.DataBind() HorseName.Visible = "false" dataListHorses.Visible = "true" End If But something goes wrong. It wil insert a new row but it contains no data. Dont know why
-
Sorry but cant show the page becourse it is behind a secure company website running ISS. The outside websites running Apache so not asp.net able. But i am trying a other aproach adding a extra row on the dataset.table. This code: Else 'Found many Rows and place them in a DropDownList Dim dataRow As DataRow dataRow = dataSet.Tables("Horses").NewRow() dataRow.Item("Horse_name") = "--Select a Horse--" dataRow.Item("Horse_NF") = "--Select a Horse--" dataRow.Item("FEI_Pass_No") = "--Select a Horse--" dataRow.Item("Sex") = "--Select a Horse--" dataRow.Item("Horse_DOB") = "--Select a Horse--" dataSet.Tables(0).Rows.Add(dataRow) dataListHorses.DataSource = dataSet.Tables("Horses").DefaultView dataListHorses.DataBind() HorseName.Visible = "false" dataListHorses.Visible = "true" End If But something goes wrong. It wil insert a new row but it contains no data. Dont know why
Don't create new record in dataset. Just create a new listitem in your dropdownlist after binding the data.
DropDownList1.DataSource=.... DropDownList1.DataBind() Dim LItem as New ListItem("---Select a Horse---"); DropDownList1.Items.Insert(0,LItem);
Regards R.Arockiapathinathan -
Don't create new record in dataset. Just create a new listitem in your dropdownlist after binding the data.
DropDownList1.DataSource=.... DropDownList1.DataBind() Dim LItem as New ListItem("---Select a Horse---"); DropDownList1.Items.Insert(0,LItem);
Regards R.Arockiapathinathan -
Sorry but that dit not work, this is the code is use: dataListRiders.DataSource = dataSet.Tables("Riders").DefaultView dataListRiders.DataBind() Dim LItem As New ListItem("---Select a Horse---") dataListRiders.Items.Insert(0, LItem)
i couldn't identify ur exact problem. Normally from the dropdownlist box, first item is selected in default. after that if u changing the item(selected item) to different item then the selecteditemchanged event will fire. otherwise it will not fire. from the above solution , in default the empty ("---select a horse---") string is the first item and at the time the event will not execute. I think you r using the dropdown list as a help window (for searching the text, that is in default it is invisible, and the user editing the text from the textbox, it should show - is it correct?), in this put empty string " " instead of "--select a horse--" and it should work. otherwise post ur code to identify the problem. Regards R.Arockiapathinathan
-
i couldn't identify ur exact problem. Normally from the dropdownlist box, first item is selected in default. after that if u changing the item(selected item) to different item then the selecteditemchanged event will fire. otherwise it will not fire. from the above solution , in default the empty ("---select a horse---") string is the first item and at the time the event will not execute. I think you r using the dropdown list as a help window (for searching the text, that is in default it is invisible, and the user editing the text from the textbox, it should show - is it correct?), in this put empty string " " instead of "--select a horse--" and it should work. otherwise post ur code to identify the problem. Regards R.Arockiapathinathan
Please find the problem subroutine down here: Sub BindDataRiders(ByVal strSwitch As String, ByVal strValue As String) 'Object vars Dim sqlConnection As SqlConnection Dim sqlDataAdaptor As SqlDataAdapter Dim sqlCommand As SqlCommand Dim dataSet As DataSet Try 'First construct connectionstring and open connection sqlConnection = New SqlConnection("server=localhost;uid=sa;pwd=secret;database=EventMngt") sqlConnection.Open() 'Then construct SELECT string including a extra Column named Combi for the DropDownList DataTextField ──┐ Dim sqlString As String = "SELECT Rider_Family_Name, Rider_Given_Name, Rider_NF, FEI_Rider_ID_No, Gender, Rider_DOB, Rider_Family_Name + ', ' + Rider_Given_Name + '-'+ Rider_NF As Combi FROM C_Registered_riders WHERE " & strSwitch sqlCommand = New SqlCommand(sqlString, sqlConnection) Response.Write(sqlString & "
") 'Put the result in a DataSet named Riders sqlDataAdaptor = New SqlDataAdapter(sqlCommand) dataSet = New DataSet() sqlDataAdaptor.Fill(dataSet, "Riders") dataSet.Tables(0).DefaultView.Sort = "rider_family_name ASC" 'Check for none, one or many row If (dataSet.Tables(0).Rows.Count) = 1 Then 'Found only one Row Rider_Family_Name.Text = dataSet.Tables("Riders").Rows(0)("Rider_Family_Name").ToString() Rider_Given_Name.Text = dataSet.Tables("Riders").Rows(0)("Rider_Given_Name").ToString() Rider_NF.Text = dataSet.Tables("Riders").Rows(0)("Rider_NF").ToString() Rider_NFFull.Text = getNF(Rider_NF.Text) Rider_FEIID.Text = dataSet.Tables("Riders").Rows(0)("FEI_Rider_ID_no").ToString() Rider_Gender.Text = dataSet.Tables("Riders").Rows(0)("Gender").ToString() Rider_DOB.Text = dataSet.Tables("Riders").Rows(0)("Rider_DOB").ToString() Response.Write("
Date:" & Replace(Rider_DOB.Text, ".", "-")) Rider_Age.Text = Age(Rider_DOB.Text) dataListRiders.Visible = "false" ElseIf (dataSet.Tables(0).Rows.Count) > 1 Then 'Found many Rows and place them in a DropDownList dataListRiders.DataSource = dataSet.Tables("Riders").DefaultView dataListRiders.DataBind() 'Add extra listItem at the start of the list dataListRiders.Items.Insert(1, New ListItem("")) RiderFamilyName.Visible = "false" dataListRiders.Visible = "true" Else 'Found no records lbl -
When i create a DropDownList normaly the selected item event fires when a new item is selected. But when i choose the first item it doenst fire so i never can choose the first item in a DDL. Anny solution.
-
Please find the problem subroutine down here: Sub BindDataRiders(ByVal strSwitch As String, ByVal strValue As String) 'Object vars Dim sqlConnection As SqlConnection Dim sqlDataAdaptor As SqlDataAdapter Dim sqlCommand As SqlCommand Dim dataSet As DataSet Try 'First construct connectionstring and open connection sqlConnection = New SqlConnection("server=localhost;uid=sa;pwd=secret;database=EventMngt") sqlConnection.Open() 'Then construct SELECT string including a extra Column named Combi for the DropDownList DataTextField ──┐ Dim sqlString As String = "SELECT Rider_Family_Name, Rider_Given_Name, Rider_NF, FEI_Rider_ID_No, Gender, Rider_DOB, Rider_Family_Name + ', ' + Rider_Given_Name + '-'+ Rider_NF As Combi FROM C_Registered_riders WHERE " & strSwitch sqlCommand = New SqlCommand(sqlString, sqlConnection) Response.Write(sqlString & "
") 'Put the result in a DataSet named Riders sqlDataAdaptor = New SqlDataAdapter(sqlCommand) dataSet = New DataSet() sqlDataAdaptor.Fill(dataSet, "Riders") dataSet.Tables(0).DefaultView.Sort = "rider_family_name ASC" 'Check for none, one or many row If (dataSet.Tables(0).Rows.Count) = 1 Then 'Found only one Row Rider_Family_Name.Text = dataSet.Tables("Riders").Rows(0)("Rider_Family_Name").ToString() Rider_Given_Name.Text = dataSet.Tables("Riders").Rows(0)("Rider_Given_Name").ToString() Rider_NF.Text = dataSet.Tables("Riders").Rows(0)("Rider_NF").ToString() Rider_NFFull.Text = getNF(Rider_NF.Text) Rider_FEIID.Text = dataSet.Tables("Riders").Rows(0)("FEI_Rider_ID_no").ToString() Rider_Gender.Text = dataSet.Tables("Riders").Rows(0)("Gender").ToString() Rider_DOB.Text = dataSet.Tables("Riders").Rows(0)("Rider_DOB").ToString() Response.Write("
Date:" & Replace(Rider_DOB.Text, ".", "-")) Rider_Age.Text = Age(Rider_DOB.Text) dataListRiders.Visible = "false" ElseIf (dataSet.Tables(0).Rows.Count) > 1 Then 'Found many Rows and place them in a DropDownList dataListRiders.DataSource = dataSet.Tables("Riders").DefaultView dataListRiders.DataBind() 'Add extra listItem at the start of the list dataListRiders.Items.Insert(1, New ListItem("")) RiderFamilyName.Visible = "false" dataListRiders.Visible = "true" Else 'Found no records lblwhere this BindDataRiders sub called? I think, this is from the textbox changed event, is it? if this is, what is the need of extra item in ddl? still, i couldn't understand ur exact problem. Regards R.Arockiapathinathan
-
where this BindDataRiders sub called? I think, this is from the textbox changed event, is it? if this is, what is the need of extra item in ddl? still, i couldn't understand ur exact problem. Regards R.Arockiapathinathan
The first time it is called from the textbox changed event, it then does a search in the database on names starting with the textbox content. It then produces either no record, a single record or a list of records. If it has a list of records the user should be able to pick any name in that dropdownlist, either the first or any other. And the problem is the first record, so there must be a extra first record.
-
The first time it is called from the textbox changed event, it then does a search in the database on names starting with the textbox content. It then produces either no record, a single record or a list of records. If it has a list of records the user should be able to pick any name in that dropdownlist, either the first or any other. And the problem is the first record, so there must be a extra first record.
so this (
dataListRiders.Items.Insert(0, New ListItem(""))
) will solve the problem. Regards R.Arockiapathinathan