Reputation: 1500
<asp:ObjectDataSource ID="sourceGroups" runat="server"
TypeName="Kurs4.Code.GroupDB" SelectMethod="GetGroups">
</asp:ObjectDataSource>
<asp:ListBox ID="lstGroups" runat="server" DataSourceID="sourceGroups"
DataTextField="GroupName"></asp:ListBox>
<asp:Button ID="btnDeleteGroup" runat="server" Text="Delete"
onclick="btnDeleteGroup_Click"/>
I have a list of Group which is populated in the ListBox. Group class has a GUID id. I need to delete selected Group from the ListBox and datasource upon Button click.
How is it possible? The problem is to get the ID of the selected item in the ListBox, because many groups can have the same GroupName.
Upvotes: 0
Views: 190
Reputation: 5737
Cant you add an DataValueField
aswell?
<asp:ListBox ID="lstGroups" runat="server" DataSourceID="sourceGroups"
DataTextField="GroupName" DataValueField="GUID"></asp:ListBox>
Like that you can get the selected value like this
string value = lstGroups.SelectedValue
Upvotes: 1