473,385 Members | 1,893 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,385 software developers and data experts.

Drop Down List returns the wrong Index

I'm having problems with the DDL in the datalist below when adding an
item.

The list binds properly and lists the correct values (up to about 350).

The code successfully finds a ddl and loads the value into the
sortedlist & the datalist. However, the selected index returned does
not (always) match that shown on the web page. The first few items are
ok, then the selection comes from an item earlier in the list.
Can anyone explain the problem?
---------------------------------------------------------------------------*------------------------

<asp:DataList ID="dlsSkills" runat="server" SelectedIndex="-1">

<HeaderTemplate>
<table border="1">
<tr align="center" style="font-weight: bold; color:

#f7f7f7;
background-color: #4a3c8c;"
valign="top">
<td colspan="6">
Skill List
</td>
</tr>
<tr align="left" style="font-weight: bold; color:
#f7f7f7;
background-color: #4a3c8c;">
<td>
Skill
</td>
<td>
Level
</td>
<td colspan="2">
Options
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr align="left" style="background-color:
lightsteelblue;" valign="top">
<td>
<asp:Label ID="lblSkill" runat="server"
Text='<%# Container.DataItem.Skill %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblLevel" runat="server"
Text='<%# Container.DataItem.Level %>'></asp:Label>
</td>
<td>
<asp:Button ID="btnEditSkill" runat="server"
CommandName="EditSkill" Text="Edit" />
</td>
<td>
<asp:Button ID="btnDeleteSkill" runat="server"
CommandName="DeleteSkill" Text="Delete" />
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr align="left" style="background-color: linen;"
valign="top">
<td>
<asp:Label ID="lblSkill" runat="server"
Text='<%# Container.DataItem.Skill %>'></asp:Label>
<asp:DropDownList ID="ddlSkill" runat="server"
DataSource="<%# SkillDDLDataSource() %>"
DataTextField="Skill"
DataValueField="Type">
</asp:DropDownList>
</td>
<td>
<asp:TextBox ID="txtLevel" runat="server"
Text='<%# Container.DataItem.Level %>'
Width="50px"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnConfirmEdit" runat="server"
CommandName="ConfirmEdit" Text="Confirm" />
</td>
<td>
<asp:Button ID="btnCancelEdit" runat="server"
CommandName="CancelEdit" Text="Cancel" />
</td>
</tr>
</EditItemTemplate>
<FooterTemplate>
<tr align="center" style="font-weight: bold; color:
#f7f7f7;
background-color: #4a3c8c;"
valign="top">
<td colspan="6">
<asp:Button ID="btnAdd" runat="server"
CommandName="AddSkill" Text="Add Skill" />
</td>
</tr>
</table>
</FooterTemplate>
</asp:DataList>
---------------------------------------------------------------------------*--------------------------

Protected Sub dlsSkills_ItemCommand(ByVal source As Object, ByVal e

As
System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
dlsSkills.ItemCommand
SkillTable = GetSkillList()
If Not IsNothing(SkillTable(" ")) Then
SkillTable.Remove(" ")
End If
If e.CommandName = "CancelEdit" Then
dlsSkills.SelectedIndex = -1
dlsSkills.EditItemIndex = -1
dlsSkills.DataSource = SkillTable.GetValueList
dlsSkills.DataBind()
End If
If e.CommandName = "ConfirmEdit" Then
Dim SkillLbl As Label =
dlsSkills.Items(e.Item.ItemIndex).FindControl("lbl Skill")
Dim SkillDdl As DropDownList =
dlsSkills.Items(e.Item.ItemIndex).FindControl("ddl Skill")
Dim LevelLbl As TextBox =
dlsSkills.Items(e.Item.ItemIndex).FindControl("txt Level")
AddSkill(SkillDdl.SelectedItem.Text, LevelLbl.Text)
dlsSkills.SelectedIndex = -1
dlsSkills.EditItemIndex = -1
dlsSkills.DataSource = SkillTable.GetValueList
dlsSkills.DataBind()
End If
If e.CommandName = "AddSkill" Then
dlsSkills.SelectedIndex = -1
AddSkill(" ", 0)
dlsSkills.EditItemIndex = 0
dlsSkills.DataSource = SkillTable.GetValueList
dlsSkills.DataBind()
Dim SkillLbl As Label =
dlsSkills.Items(0).FindControl("lblSkill")
Dim SkillDdl As DropDownList =
dlsSkills.Items(0).FindControl("ddlSkill")
Dim ConfirmBtn As Button =
dlsSkills.Items(0).FindControl("btnConfirmEdit")
Dim CancelBtn As Button =
dlsSkills.Items(0).FindControl("btnCancelEdit")
SkillLbl.Visible = False
SkillDdl.Visible = True
ConfirmBtn.CommandArgument = "Add"
CancelBtn.CommandArgument = "Add"
End If
Session("Skills") = SkillTable
End Sub
Protected Sub AddSkill(ByVal Skill As String, ByVal Level As
Integer)
Dim SkillEntry As New SkillDetails
SkillEntry.Skill = Skill
SkillEntry.Level = Level
SkillTable.Add(SkillEntry.Skill, SkillEntry)
End Sub
Private Function GetSkillList() As SortedList
If Session("Skills") Is Nothing Then
Session.Add("Skills", New SortedList)
End If
Return CType(Session("Skills"), SortedList)
End Function
Public Function SkillDDLDataSource() As DataSet
SkillTable = GetSkillList()
Dim cmd As String = "SELECT [Skill], [Type] FROM [Action] WHERE

[Skill] not in ("
For i As Integer = 0 To SkillTable.Count - 1
cmd += "'" & SkillTable.GetKey(i) & "',"
Next
cmd = cmd.Substring(0, cmd.Length - 1) & ")"
Dim RMconn1 As New
SqlConnection(ConfigurationManager.ConnectionStrin gs("RMDb").ConnectionStri*ng)

RMconn1.Open()
Dim cmdAllSkills As New SqlCommand(cmd, RMconn1)
Dim sadAllSkills As New SqlDataAdapter
sadAllSkills.SelectCommand = cmdAllSkills
Dim dstAllSkills As New Data.DataSet
sadAllSkills.Fill(dstAllSkills)
RMconn1.Close()
RMconn1 = Nothing
Return dstAllSkills
End Function

May 6 '06 #1
0 1260

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

Similar topics

6
by: Greg Scharlemann | last post by:
I am attempting to populate a drop down menu based on the selection of a different drop down menu. However, it is not working correctly, I cannot figure out for the life of me what exactly happens...
13
by: Leszek Taratuta | last post by:
Hello, I have several drop-down lists on my ASP.NET page. I need to keep data sources of these lists in Session State. What would be the most effective method to serialize this kind of data...
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
6
by: Joey Liang via DotNetMonster.com | last post by:
Hi all, I have a drop down list which store all the different brands of product.When i selected the particular brand from the drop down list, it will display all the products with the selected...
0
by: dutone | last post by:
I have searched high and low for a solution to this and I dont think its possible.... but I hope not. What I have is a list of items with various values that can be changed via a drop down. Each...
3
by: John Walker | last post by:
Hi, On an ASP.NET page I have a drop down list control. When the user pulls down the list and makes a selection, I perform validation, and if the validation fails I want the selected item in...
3
by: Mike Collins | last post by:
I'm not feeling too smart right now, but I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. Can someone show...
5
by: Ajith Menon | last post by:
I need to select multiple entries in the drop down list. E.g. Search a string in languages like C#, VB, Java etc. These entries are in drop down. So i need to multi select to search in multiple...
4
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.