user35
user35

Reputation: 468

SelectedItem column name in asp.net

I have a datalist called mymenu which is populated with data from database.

 <asp:DataList ID="dl_menu" runat="server">
 </asp:DataList>

In the codebehind I am able to find the value of selected item as mymenu.SelectedValue or the parent of selected item as mymenu.SelectedItem.Parent.Text.Is there a way to find the column name of the selected item rather then its value.

For example when i do mymenu.selectedvalue I get value 3 of column ccID.What should i do if i want to get the value as ccID?

Upvotes: 0

Views: 115

Answers (1)

j.f.
j.f.

Reputation: 3949

Well the SelectedValue of a DataList is actually the value of the DataKeyField for the selected DataListItem. So I imagine your DataList must look something like this:

<asp:DataList ID="dl_menu" runat="server" DataKeyField="ccID">
</asp:DataList>

If you want to get the string value of "ccID", just use the DataList's DataKeyField property.

string dkf = dl_menu.DataKeyField;

You can't actually find a single column name for a selected item in a DataList. The DataList could contain multiple columns and you are actually selecting the entire DataListItem (the row) when you select it.

Upvotes: 1

Related Questions