4 Answers, 1 is accepted
So I thought I'd be slick and go the route of using attributes instead of DataKey/values. It's like a Black Flag Roach Motel...data goes in but it don't come out.
Here's my ItemDataBound
Private
Sub
cbAcctType2_ItemDataBound(sender
As
Object
, e
As
RadMultiColumnComboBoxItemEventArgs)
Handles
cbAcctType2.ItemDataBound
Dim
drv
As
DataRowView =
CType
(e.Item.DataItem, DataRowView)
e.Item.Attributes.Add(
"disc_id"
, IIf(drv.Item(
"disc_id"
)
Is
DBNull.Value, 0, drv.Item(
"disc_id"
)))
e.Item.Attributes.Add(
"acct_min_exempt_days"
, IIf(drv.Item(
"acct_min_exempt_days"
)
Is
DBNull.Value, 0, drv.Item(
"acct_min_exempt_days"
)))
End
Sub
then to access I'm using
cbAcctType2.Attributes(
"disc_id"
).ToString
comes back as Nothing
Hello SSirica,
You are very close to the solution, as the DataItem is available only in ItemDataBound, the way to go is via Attributes.
The accessed value is Nothing because the snippet accesses the Attribute of the control itself instead of the item. Here is an example that shows how the attribute of the selected item can be accessed:
<asp:Label Text="Label1" ID="Label1" runat="server" />
<telerik:RadButton runat="server" ID="RadButton1" Text="Postback" AutoPostBack="true" OnClick="RadButton1_Click" />
<telerik:RadMultiColumnComboBox ID="RadMultiColumnComboBox1" DataKeyNames="Additional" runat="server" DropDownWidth="Auto" OnItemDataBound="RadMultiColumnComboBox1_ItemDataBound">
<ColumnsCollection>
<telerik:MultiColumnComboBoxColumn Field="ID"></telerik:MultiColumnComboBoxColumn>
<telerik:MultiColumnComboBoxColumn Field="Name"></telerik:MultiColumnComboBoxColumn>
<telerik:MultiColumnComboBoxColumn Field="Additional"></telerik:MultiColumnComboBoxColumn>
</ColumnsCollection>
</telerik:RadMultiColumnComboBox>
public class MyClass
{
public int ID { get; set; }
public string Name { get; set; }
public string Additional { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RadMultiColumnComboBox1.DataSource = Enumerable.Range(1, 20).Select(x => new MyClass()
{
ID = x,
Name = "Item " + x,
Additional = "DataKey#" + x
});
RadMultiColumnComboBox1.DataTextField = "Name";
RadMultiColumnComboBox1.DataValueField = "ID";
RadMultiColumnComboBox1.DataBind();
}
}
protected void RadButton1_Click(object sender, EventArgs e)
{
var selectedItem = RadMultiColumnComboBox1.Items.FindChildByValue(RadMultiColumnComboBox1.Value);
var additional = selectedItem.Attributes["Additional"];
Label1.Text = additional;
}
protected void RadMultiColumnComboBox1_ItemDataBound(object sender, Telerik.Web.UI.RadMultiColumnComboBoxItemEventArgs e)
{
e.Item.Attributes.Add("Additional", (e.Item.DataItem as MyClass).Additional);
}
Regarding the response time, this is an open forum we try to cover as many threads as possible we cannot always guarantee a quick answer. That is why for issues that require quick and guaranteed answer you can submit official support tickets with the respective response time during the working weekdays.
Regards,
Peter Milchev
Progress Telerik
Thanks.