Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Selected index of dropdownlist

  Asked By: Leon    Date: Dec 21    Category: Asp.net    Views: 1363
  

I've a dropdownlist in a dataGrid. When index of the dropdownlist change, the value is written in table "OrderTabel", column "aantal" of my DataSet...

I use the Autopostback-event for the dropdownlist. When i change index, the page postbacks and the value is been written in the paricular column.
But when rebinding, the selectedindex of the dropdown has become 0 again... So i wanna see the selectedIndex the same as i selected before posting back.

I try to do that with:
drop1.SelectedIndex = CType(myDataTable2.Rows("aantal").value, Integer)

But i get all the time the message:

Input string was not in a correct format

SomeBody knows what the problem is and how to solve it?



Public
Sub eventItemDataBound1(ByVal S As Object, ByVal e As DataGridItemEventArgs)

Dim drop1 As DropDownList = e.Item.FindControl("myDDL")

Dim IndexInDataGrid As Integer = e.Item.ItemIndex

If Not IsNothing(drop1) Then 'zeer belangrijk => drop1 moet eerste bestaan!!!

Dim myDataSet As DataSet
Dim myDataTable As DataTable
myDataSet = CType(Session("data"), DataSet)
myDataTable = myDataSet.Tables("DDLTabel")
Dim myDataView As DataView
myDataView = New DataView(myDataTable)
Dim myDataTable2 = myDataSet.Tables("OrderTabel")


drop1.SelectedIndex = CType(myDataTable2.Rows(indexInDataGrid)("aantal"), Integer)

drop1.DataSource = myDataView
drop1.DataMember = "DDLTabel"
drop1.DataTextField = "aantal"
drop1.DataValueField = "aantal"
drop1.DataBind()
End If
End Sub

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Rickey Scott     Answered On: Dec 21


drop1.SelectedIndex = drop1.Items.IndexOf(drop1.Items.FindByValue(myDataTable2.Rows("aantal")))

 
Didn't find what you were looking for? Find more on Selected index of dropdownlist Or get search suggestion and latest updates.




Tagged: