473,493 Members | 4,347 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 3160
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
797
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
9639
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
1677
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
3559
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
9147
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
260
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
3726
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
8833
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
3212
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...
0
6980
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7192
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6862
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7364
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1397
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.