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

Using DataSource to add data attributes

4 Answers 775 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Matthias
Top achievements
Rank 1
Matthias asked on 21 May 2014, 03:26 PM
I see that you can set the text and value of list items with dataValueField and dataTextField, but is there any way to set custom attributes with DataSource (ie: data-*)?

4 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 23 May 2014, 10:35 AM
Hi Matthias,

In general you can create custom fields in the dataSource that you can access via the dataItem, however they are not directly related to the data attributes of the element, and this cannot be achieved out of the box. But as I am not really sure that I understand your question correctly, would it be possible to elaborate a bit more on this matter?

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bruce
Top achievements
Rank 1
answered on 10 Jul 2019, 09:21 PM

I had the same question tonight and came across this post. So even though its a really old post, I'm going to answer it.

You have to specify data_ instead of data- as part of the HtmlAttributes collection.

So for example:

Html.Kendo().Button().Name("btnProgressLeadValidation")
    .Content("Promote to Lead")
    .HtmlAttributes(new { type = "button", @class = "k-primary progress-button", data_label = "Lead Validation" })
    .Events(events => events.Click("onProgressClick"))
    .Render();

Note the data_lead bit in the HtmlAttributes

That will render at the below Html:

<button class="k-primary progress-button" data-label="Lead Validation" id="btnProgressLeadValidation" type="button">Promote to Lead</button>

 

Hope this helps someone.

0
Dimitar
Telerik team
answered on 12 Jul 2019, 10:36 AM
Hi Bruce,

Thank you for sharing this solution with the community.

Best regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Jason
Top achievements
Rank 1
answered on 08 Oct 2020, 01:06 PM
This helped so much. I needed the data attribute and it wasnt clear how to add.
Tags
DropDownList
Asked by
Matthias
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Bruce
Top achievements
Rank 1
Dimitar
Telerik team
Jason
Top achievements
Rank 1
Share this question
or