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

Getting DataKeys value server side

4 Answers 160 Views
MultiColumnComboBox
This is a migrated thread and some comments may be shown as answers.
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
SSirica asked on 27 Feb 2020, 06:42 PM
I downloaded the latest version today and it looks like you finally gave this thing an engine and some nice rims, but no tires.  I can include DataKeyNames but I can't get the DataKeyValues from the server side.  A GetDataKeyValue option would be nice.  I see there's functionality to get the values on the client side, but not the server side.  A little short sighted...unless I'm missing something then I apologise.  

4 Answers, 1 is accepted

Sort by
0
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
answered on 27 Feb 2020, 08:58 PM

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

0
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
answered on 02 Mar 2020, 02:32 PM
Good to see such a timely response to issues.
0
Accepted
Peter Milchev
Telerik team
answered on 03 Mar 2020, 10:28 AM

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

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
answered on 06 Mar 2020, 03:18 PM

Thanks.

Tags
MultiColumnComboBox
Asked by
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
Peter Milchev
Telerik team
Share this question
or