This is a migrated thread and some comments may be shown as answers.

[Solved] Retrieve other columns in the datasource for the selected item

1 Answer 133 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Polaris431
Top achievements
Rank 1
Polaris431 asked on 24 Jun 2009, 11:07 AM
Is it possible to retrieve the value of other columns in the underlying datasource when an item is selected in the combobox? If so, how?

Thanks
Johann

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Jun 2009, 01:03 PM
Hi Jahann,

You can add Custom Attributes to RadComboBoxItem in order to store the extra column value, and it is possible to retrieveit later. See the example shown below.

ASPX:
 
<telerik:RadComboBox ID="RadComboBox1" DataSourceID="SqlDataSource1" runat="server" DataTextField="CompanyName" DataValueField="CustomerID" OnItemDataBound="RadComboBox1_ItemDataBound"
</telerik:RadComboBox> 
 
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ConnectionStrings:NorthwindConnectionString2 %>" SelectCommand="SELECT * FROM [Customers]"
</asp:SqlDataSource> 
 
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Get ContactName" /> 

CS:
 
protected void Button1_Click(object sender, EventArgs e) 
    Response.Write(RadComboBox1.SelectedItem.Attributes["ContactName"]); // Display Contact Name retrieved using Attributes 
protected void RadComboBox1_ItemDataBound(object sender, RadComboBoxItemEventArgs e) 
    DataRowView dataSourceRow = (DataRowView)e.Item.DataItem; 
    //set custom attributes from the datasource:   
    e.Item.Attributes["ContactName"] = dataSourceRow["ContactName"].ToString();   

Shinu
Tags
ComboBox
Asked by
Polaris431
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or