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

Custom attributes not rendering

1 Answer 175 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Scott Bedard
Top achievements
Rank 1
Scott Bedard asked on 06 Jan 2009, 04:14 PM
I am using a RadComboBox and would like to create some attributes that I can 'read' in Javascript later. This technique is working with the RadDatePicker so I can't understand why it won't work with the comb box. I'm using Q3 build.

Page behind code ->

using

 

System;

 

using

 

System.Collections.Generic;

 

using

 

System.Data;

 

using

 

System.Web.UI;

 

using

 

System.Web.UI.WebControls;

 

using

 

Telerik.Web.UI;

 

namespace

 

ITemplateTest

 

{

 

public partial class _Default : Page

 

{

 

private bool isInserting = false;

 

 

protected void Page_Load(object sender, EventArgs e)

 

{

 

 

var dict = new DataTable();

 

dict.Columns.Add(

"Region");

 

dict.Rows.Add(

"Region1");

 

dict.Rows.Add(

"Region2");

 

TestGrid.DataSource = dict;

TestGrid.DataBind();

}

 

protected void TestGrid_ItemCommand(object source, GridCommandEventArgs e)

 

{

 

switch (e.CommandName)

 

{

 

case RadGrid.InitInsertCommandName:

 

 

var dateTemplate = new DatePickerTemplate();

 

 

var dateColumn = new GridTemplateColumn { EditItemTemplate = dateTemplate, HeaderText = "Test Date" };

 

TestGrid.Columns.AddAt(TestGrid.Columns.Count, dateColumn);

 

var comboTemplate = new ComboBoxTemplate();

 

 

var comboColumn = new GridTemplateColumn { EditItemTemplate = comboTemplate, HeaderText = "Test Combo" };

 

TestGrid.Columns.AddAt(TestGrid.Columns.Count, comboColumn);

TestGrid.ShowHeader =

false;

 

isInserting =

true;

 

 

break;

 

 

case RadGrid.CancelCommandName:

 

isInserting =

false;

 

TestGrid.Columns.RemoveAt(1);

TestGrid.ShowHeader =

true;

 

 

break;

 

}

 

}

 

protected void TestGrid_ItemDataBound(object sender, GridItemEventArgs e)

 

{

 

if (e.Item == null) return;

 

 

if (isInserting && e.Item is GridDataItem)

 

{

 

//Merge the cells that have been inserted with the name cell.

 

 

var numOfRequired = 1;

 

e.Item.Cells[0].ColumnSpan = numOfRequired + 1;

 

for (var i = 1; i <= numOfRequired; i++)

 

{

e.Item.Cells.RemoveAt(e.Item.Cells.Count - 1);

}

}

 

if (!isInserting && e.Item is GridDataItem)

 

{

 

//Set the column span to the correct value since it may have been altered by an insert

 

e.Item.Cells[0].ColumnSpan = 1;

}

}

}

 

class DatePickerTemplate : ITemplate

 

{

 

public void InstantiateIn(Control container)

 

{

 

var ctl = new RadDatePicker

 

{

SelectedDate =

DateTime.Now

 

};

ctl.Attributes.Add(

"FactID", "FactIDValue");

 

ctl.Attributes.Add(

"HiddenFieldID", "HiddenFieldIDValue");

 

ctl.DateInput.ClientEvents.OnError =

"DatePicker_Error";

 

ctl.DateInput.ClientEvents.OnValueChanged =

"DatePicker_Changed";

 

container.Controls.Add(ctl);

}

}

 

public class ComboBoxTemplate : ITemplate

 

{

 

public void InstantiateIn(Control container)

 

{

 

var ctl = new RadComboBox()

 

{

ID =

"RadComboBox"

 

};

ctl.Attributes.Add(

"FactID", "SomeID");

 

ctl.Attributes.Add(

"HiddenFieldID", "SomeOtherID");

 

container.Controls.Add(ctl);

}

}

}


ASPX Page ->

 

<%

@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestPage.aspx.cs" Inherits="ITemplateTest._Default" %>

 

<%

@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

 

 

 

 

<!

 

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<

 

html xmlns="http://www.w3.org/1999/xhtml" >

 

<

 

head runat="server">

 

 

 

 

 

 

<title>Sample Page</title>

 

</

 

head>

 

<

 

body>

 

 

 

 

 

 

<form id="form1" runat="server">

 

 

<script type="text/javascript">

 

 

 

 

 

 

 

function DatePicker_Error(sender, eventArgs)

 

{

window.alert(

"date error");

 

}

 

 

function DatePicker_Changed(sender, eventArgs)

 

{

window.alert(

"date changed");

 

}

 

 

</script>

 

 

<div runat="server" id="TestGridDiv">

 

 

 

 

 

 

<telerik:RadScriptManager ID="RadScriptManager1" Runat="server">

 

 

 

 

 

 

</telerik:RadScriptManager>

 

 

 

 

 

 

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">

 

 

 

 

 

 

<AjaxSettings>

 

 

 

 

 

 

<telerik:AjaxSetting AjaxControlID="TestGrid">

 

 

 

 

 

 

<UpdatedControls><telerik:AjaxUpdatedControl ControlID="TestGrid" /></UpdatedControls>

 

 

 

 

 

 

</telerik:AjaxSetting>

 

 

 

 

 

 

</AjaxSettings>

 

 

 

 

 

 

</telerik:RadAjaxManager>

 

 

 

 

 

 

</div>

 

 

 

 

 

 

<telerik:RadTabStrip ID="RadTabStrip1" runat="server" SelectedIndex="0" MultiPageID="RadMultiPage1">

 

 

 

 

 

 

<Tabs>

 

 

 

 

 

 

<telerik:RadTab runat="server" Text="Root RadTab1" Selected="True" PageViewID="RadPageView1">

 

 

 

 

 

 

</telerik:RadTab>

 

 

 

 

 

 

<telerik:RadTab runat="server" Text="Root RadTab2" PageViewID="RadPageView2">

 

 

 

 

 

 

</telerik:RadTab>

 

 

 

 

 

 

</Tabs>

 

 

 

 

 

 

</telerik:RadTabStrip>

 

 

 

 

 

 

 

<telerik:RadMultiPage ID="RadMultiPage1" Runat="server">

 

 

 

 

 

 

<telerik:RadPageView ID="RadPageView2" Runat="server" Width="100%">

 

 

 

 

 

 

<telerik:RadDatePicker ID="RadDatePicker1" Runat="server">

 

 

 

 

 

 

</telerik:RadDatePicker>

 

 

 

 

 

 

</telerik:RadPageView> <telerik:RadPageView ID="RadPageView1" Runat="server" Width="100%">

 

 

 

 

 

 

<div id="TestGridPanel">

 

<

 

telerik:RadGrid ID="TestGrid" runat="server" AutoGenerateColumns="False"

 

 

GridLines="None" onitemcommand="TestGrid_ItemCommand"

 

 

onitemdatabound="TestGrid_ItemDataBound">

 

<

 

mastertableview commanditemdisplay="Top" editmode="EditForms">

 

<

 

norecordstemplate>

 

 

 

 

 

 

<asp:Label ID="ProcessFilterLabel" runat="server" Text="No processes found." />

 

 

 

 

 

 

</norecordstemplate>

 

 

 

 

 

 

<Columns>

 

 

 

 

 

 

<telerik:GridTemplateColumn HeaderText="Region" UniqueName="region">

 

 

 

 

 

 

<EditItemTemplate>

 

 

 

 

 

 

<asp:ListBox ID="RegionListBox" runat="server"><asp:ListItem Text="Region" Value="Value"></asp:ListItem></asp:ListBox>

 

 

 

 

 

 

</EditItemTemplate>

 

 

 

 

 

 

<ItemTemplate>Hello</ItemTemplate>

 

 

 

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

 

 

</Columns>

 

 

 

 

 

 

<editformsettings>

 

 

 

 

 

 

<popupsettings scrollbars="None" />

 

 

 

 

 

 

</editformsettings>

 

</

 

mastertableview>

 

</

 

telerik:RadGrid>

 

</

 

div>

 

 

 

 

 

 

</telerik:RadPageView>

 

 

 

 

 

 

</telerik:RadMultiPage>

 

 

 

 

 

 

</form>

 

</

 

body>

 

</

 

html>

 

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 06 Jan 2009, 05:03 PM
Hi Scott Bedard,

This is for compatibility reasons with the older combobox versions. You can access the custom attributes via the get_attributes() collection:

var attribute = comboBox.get_attributes().getAttribute("myAttribute");

Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
ComboBox
Asked by
Scott Bedard
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or