473,216 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,216 software developers and data experts.

SelectedIndex set in ItemDataBound Method but always index(0) set

Hi All,

I am beffudeled to say the least ...

I have code that dynamically populates drop down boxes (in a datagrid - edit
itme template) and sets the selectedindex in the dropdown to the equivalent
value in a DB.

For teams it works (I get the data from the DB) but or designation (game,
practice, exhibition) which I create as follows:

Dim drpD As DropDownList
drpD = CType(e.Item.FindControl("drpD"), DropDownList)
drpD.Items.Insert(0, "Game")
drpD.Items.Item(0).Value = "g"
drpD.Items.Insert(1, "Practice")
drpD.Items.Item(1).Value = "p"
drpD.Items.Insert(2, "Exhibition")
drpD.Items.Item(2).Value = "x"

If Trim(dsGame.Tables("Table").Rows(0).Item("Des").To String()) =
"g" Then
drpD.SelectedIndex = 0
ElseIf
Trim(dsGame.Tables("Table").Rows(0).Item("Des").To String()) = "p" Then
drpD.SelectedIndex = 1
Else
drpD.SelectedIndex = 2
End If
drpD.DataBind()

It always sets the selectedindex to 0. I have set some debug statemetns and
verrified that for an "x" game I go into the else statement. This should
mean that selected index is set to 2 but this does NOT happen.

Any help would be greatly appreciated.

Thank you,

--
Phil Lamey, EIT
CGI Consultant
Jul 21 '05 #1
2 3150
Are you using this pattern?

If Not Page.IsPostBack
' BindData()
End If
--
Ibrahim ULUDAG
www.ibrahimuludag.com
"Phil Lamey" <Ph*******@discussions.microsoft.com> wrote in message
news:0A**********************************@microsof t.com...
Hi All,

I am beffudeled to say the least ...

I have code that dynamically populates drop down boxes (in a datagrid -
edit
itme template) and sets the selectedindex in the dropdown to the
equivalent
value in a DB.

For teams it works (I get the data from the DB) but or designation (game,
practice, exhibition) which I create as follows:

Dim drpD As DropDownList
drpD = CType(e.Item.FindControl("drpD"), DropDownList)
drpD.Items.Insert(0, "Game")
drpD.Items.Item(0).Value = "g"
drpD.Items.Insert(1, "Practice")
drpD.Items.Item(1).Value = "p"
drpD.Items.Insert(2, "Exhibition")
drpD.Items.Item(2).Value = "x"

If Trim(dsGame.Tables("Table").Rows(0).Item("Des").To String())
=
"g" Then
drpD.SelectedIndex = 0
ElseIf
Trim(dsGame.Tables("Table").Rows(0).Item("Des").To String()) = "p" Then
drpD.SelectedIndex = 1
Else
drpD.SelectedIndex = 2
End If
drpD.DataBind()

It always sets the selectedindex to 0. I have set some debug statemetns
and
verrified that for an "x" game I go into the else statement. This should
mean that selected index is set to 2 but this does NOT happen.

Any help would be greatly appreciated.

Thank you,

--
Phil Lamey, EIT
CGI Consultant

Jul 21 '05 #2
Are you using this pattern?

If Not Page.IsPostBack
' BindData()
End If
--
Ibrahim ULUDAG
www.ibrahimuludag.com
"Phil Lamey" <Ph*******@discussions.microsoft.com> wrote in message
news:0A**********************************@microsof t.com...
Hi All,

I am beffudeled to say the least ...

I have code that dynamically populates drop down boxes (in a datagrid -
edit
itme template) and sets the selectedindex in the dropdown to the
equivalent
value in a DB.

For teams it works (I get the data from the DB) but or designation (game,
practice, exhibition) which I create as follows:

Dim drpD As DropDownList
drpD = CType(e.Item.FindControl("drpD"), DropDownList)
drpD.Items.Insert(0, "Game")
drpD.Items.Item(0).Value = "g"
drpD.Items.Insert(1, "Practice")
drpD.Items.Item(1).Value = "p"
drpD.Items.Insert(2, "Exhibition")
drpD.Items.Item(2).Value = "x"

If Trim(dsGame.Tables("Table").Rows(0).Item("Des").To String())
=
"g" Then
drpD.SelectedIndex = 0
ElseIf
Trim(dsGame.Tables("Table").Rows(0).Item("Des").To String()) = "p" Then
drpD.SelectedIndex = 1
Else
drpD.SelectedIndex = 2
End If
drpD.DataBind()

It always sets the selectedindex to 0. I have set some debug statemetns
and
verrified that for an "x" game I go into the else statement. This should
mean that selected index is set to 2 but this does NOT happen.

Any help would be greatly appreciated.

Thank you,

--
Phil Lamey, EIT
CGI Consultant

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ashish Sharma | last post by:
I have a DropDownList inside a DataList on a page. I want to set the selectedindex property of the DropDownList to some value. I bind the DropDownList on the ItemCreated Event of the DataList. ...
4
by: Emil | last post by:
Can somebody tell me what would be the syntax for having an if statement and setting the selected index of a radiobuttonlist? This is my first project using ASP.net and I use C#. I have a repeater...
3
by: Angel | last post by:
I have a problem I placed a DropDown list control on my .NET page. I do not want to perform a postback when something is selected. When I want to get what was selected in the Client Script I do not...
7
by: Joel Reinford | last post by:
I am looking for a way to set the selectedindex of a datagrid based on the datakey value. For example given this grid with a datakey of OrderID: OrderID Item 54 A 98 ...
5
by: Eric A. Johnson | last post by:
Hi Everyone, I am at my wit's end here. I have a combobox (combyQueryTitle) that I need to use in order to select a query for my database project. Therefore, I am using the...
1
by: Phil Lamey | last post by:
Hi All, I am beffudeled to say the least ... I have code that dynamically populates drop down boxes (in a datagrid - edit itme template) and sets the selectedindex in the dropdown to the...
5
by: Nathan Sokalski | last post by:
I have a control that I want displayed in all items except the last one. I figured the best way to do this was to determine whether the current item was the last from within the ItemDataBound event...
1
by: pleaseexplaintome | last post by:
Hi all, I have a datagrid with a dropdownlist and would like to have the dropdownlist display a database value correctly while the grid is in edit mode. I have a templatecolumn as follows: ...
1
by: marcbb | last post by:
Hi all, I have a really strange problem working with Dropdownlists in a DataGrid. I'm trying to preselect some values from the DropDownlist for each row in the DataGrid, but it seems that...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.