SelectedIndexChanged with data bound DropDownList
-
Hi, I have a DropDownList that is using one of my business objects as the DataSource.
meetingDateDdl.DataSource = room.Meetings; // == List<MeetingInfo>
meetingDateDdl.DataBind();However, when I get the details in the SelectedIndexChanged event handler the meetingDataDdl.SelectedItem shows the display text for the Text and Value properties. The problem is that another user could updated the data so that the item has a different display text or that someother data could be added or deleted making the index invalid which means I cannot use SelectedIndex. What I want is to put the unique Id, which is just the primary key from the database, into the DropDownList somehow so that when I check the SelectedItem I can see from the Value what the unique id is so I can find the correct business object again. Any ideas? BTW, I'm using ASP.NET 2.0
-
Hi, I have a DropDownList that is using one of my business objects as the DataSource.
meetingDateDdl.DataSource = room.Meetings; // == List<MeetingInfo>
meetingDateDdl.DataBind();However, when I get the details in the SelectedIndexChanged event handler the meetingDataDdl.SelectedItem shows the display text for the Text and Value properties. The problem is that another user could updated the data so that the item has a different display text or that someother data could be added or deleted making the index invalid which means I cannot use SelectedIndex. What I want is to put the unique Id, which is just the primary key from the database, into the DropDownList somehow so that when I check the SelectedItem I can see from the Value what the unique id is so I can find the correct business object again. Any ideas? BTW, I'm using ASP.NET 2.0
[Message Deleted]
-
[Message Deleted]
Pankaj Kulkarni wrote:
Because u haven't stated the use of ur DropDownList.
I don't understand what you mean by that. My use of the DropDownList is to display a list of existing meeting date/times that come from a MeetingInfo object.
Pankaj Kulkarni wrote:
Asssuming that using for the Storing Data to Database
The UI knows nothing about the database. The UI is binding to the business objects, in this case MeetingInfo.
class MeetingInfo
{
public int MeetingID{ get; set; } // This is what I want as the value
public string Description { get; set; } // This is what I want displayed to the user
}Pankaj Kulkarni wrote:
dd.SelectedIndex = dd.IndexOf(dd.FindByValue(Variable))
That won't work for me as it is assigning the selected index. The item is already selected, I want to be able to find out the exact MeetingInfo object that was used to generate the item. Therefore, I want to be able to assign to each DropDownList item the MeetingID while displaying to the user the Description. Does this make more sense that my original post? Cheers, Andy.
-
Hi, I have a DropDownList that is using one of my business objects as the DataSource.
meetingDateDdl.DataSource = room.Meetings; // == List<MeetingInfo>
meetingDateDdl.DataBind();However, when I get the details in the SelectedIndexChanged event handler the meetingDataDdl.SelectedItem shows the display text for the Text and Value properties. The problem is that another user could updated the data so that the item has a different display text or that someother data could be added or deleted making the index invalid which means I cannot use SelectedIndex. What I want is to put the unique Id, which is just the primary key from the database, into the DropDownList somehow so that when I check the SelectedItem I can see from the Value what the unique id is so I can find the correct business object again. Any ideas? BTW, I'm using ASP.NET 2.0
hi there you should bind DropDown control like this...
meetingDateDdl.DataSource = room.Meetings; meetingDateDdl.DataTextField = "MeetingID"; meetingDateDdl.DataValueField = "Description"; meetingDateDdl.DataBind(); //the following line gives u the exact selected MeetingID string selectedMeetingID = meetingDateDdl.SelectedValue;
:)
Confidence comes not from always being right, but from not fearing to be wrong. Mihir..
-
hi there you should bind DropDown control like this...
meetingDateDdl.DataSource = room.Meetings; meetingDateDdl.DataTextField = "MeetingID"; meetingDateDdl.DataValueField = "Description"; meetingDateDdl.DataBind(); //the following line gives u the exact selected MeetingID string selectedMeetingID = meetingDateDdl.SelectedValue;
:)
Confidence comes not from always being right, but from not fearing to be wrong. Mihir..