473,395 Members | 1,762 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,395 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 3159
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...

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.