471,357 Members | 1,087 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,357 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 3054
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ashish Sharma | last post: by
3 posts views Thread by Angel | last post: by
7 posts views Thread by Joel Reinford | last post: by
5 posts views Thread by Eric A. Johnson | last post: by
1 post views Thread by pleaseexplaintome | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.