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

[Solved] How to read Combo Box Template Values in RadGrid Update Event and also into a Label in ComboBox_SelectedIndexChanged Event.

3 Answers 184 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 28 Sep 2009, 07:50 PM

Folks,

 
I am using RadControls for ASP.NET AJAX Q2 2009 SP1 with Visual Studio 2008 SP1.


I have a   
Heirarchical Grid (

MasterTableView

  and  DetailTables  both uses FormTemplate). In DetailTables, I have a RadCombo Box. Is it possible:

 

1)    In RadGrid1_UpdateCommand/ RadGrid1_InsertCommand Events, capture the Template Values of City and ContactTitle into string Variables?  Neither City nor ContactTitle are DataTextField or  DataValueField of ComboBox?

 

2)    After the RadComboBox1_SelectedIndexChanged Event of ComboBox (autopost is set to true here), is it possible to update a label (ComboBoxContactTitle) in DetailTable Form Template?

 

 

Below is my code. Any help will be appreciated.

Thanks


GC_0620

_________

 

protected

 

void RadComboBox1_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)

 

{

}


______

<

 

telerik:RadGrid ID="RadGrid1" OnInsertCommand="RadGrid1_InsertCommand"

 

 

OnUpdateCommand = "RadGrid1_UpdateCommand" >

 

<

 

MasterTableView runat = "server" Name = "Master">

 

<!

 

Beginning Block of Child DetailTable -->

 

<

 

DetailTables>

 

 

<telerik:GridTableView runat="server" Name = "Detail"

 

 

<ParentTableRelation>

 

...

 

</ParentTableRelation>

 

 

 

<Columns>

 

....

 

<telerik:GridBoundColumn DataField="ContactName" HeaderText="ContactName" HeaderStyle-Width="50%"

 

 

SortExpression="ContactName" UniqueName="ContactName" >

 

 

</telerik:GridBoundColumn>

 

....

 

</Columns>

 

 

<

 

EditFormSettings EditFormType="Template">

 

<

 

EditColumn UniqueName="EditCommandColumn1"></EditColumn>

 

 

<FormTemplate>

 

 


<
table id="Table1">

 

 

<tr>

 

 

<td>

 

Contact Name

 

</td>

 

 

<td>

 

 

<telerik:RadComboBox runat="server"

 

 

ID="RadComboBox1"

 

 

DataTextField="ContactName"

 

 

DataValueField="ContactName"

 

 

HighlightTemplatedItems="true"

 

 

Height="190px"

 

 

Width="220px"

 

 

DropDownWidth="420px"

 

 

DataSourceID="SQLDataSource1" AutoPostBack="True"

 

 

onselectedindexchanged="RadComboBox1_SelectedIndexChanged"

 

 

SelectedValue='<%#Bind("ContactName") %>'>

 

 

 

<HeaderTemplate>

 

 

<ul>

 

 

<li class="col1">Contact Name</li>

 

 

<li class="col2">City</li>

 

 

<li class="col3">Title</li>

 

 

</ul>

 

 

</HeaderTemplate>

 

 

<ItemTemplate>

 

 

<ul>

 

 

<li class="col1"><%# DataBinder.Eval(Container.DataItem, "ContactName") %></li>

 

 

<li class="col2"><%# DataBinder.Eval(Container.DataItem, "City") %></li>

 

 

<li class="col3"><%# DataBinder.Eval(Container.DataItem, "ContactTitle") %></li>

 

 

</ul>

 

 

</ItemTemplate>

 

 

</telerik:RadComboBox>

 

 

</td>

 

 

<td colspan="2" style="font-size:small; z-index:0; font-family:Bookman Old Style; color:#669999">

 

 

<asp:Label ID="ComboBoxContactTitle" runat="server" Text="Contact Title"

 

 

Font-Underline="True">

 

 

</asp:Label>

 

 

</td>

 

 

 

</tr>

 

...

 

</table>

 

 

</FormTemplate>

 

 

</EditFormSettings>

 

 

</telerik:GridTableView>

 

</

 

DetailTables>

 

<!

 

Ending Block of Child DetailTable -->

 

<!

 

Beginning Block of MasterTableView -->

 

 

<Columns>

 

...

 

</Columns>

 

 

<EditFormSettings EditFormType="Template">

 

 

<FormTemplate>

 

...

 

 

</FormTemplate>

 

 

</EditFormSettings>

 

...

 

</

 

MasterTableView>

 

<!

 

Ending Block of MasterTableView -->

 

</

 

telerik:RadGrid>

 

<

 

asp:SqlDataSource ID="SqlDataSource1" runat="server"

 

 

ConnectionString="<%$ ConnectionStrings:SomeConnectionString %>"

 

 

SelectCommand="SELECT * FROM [Customers] ORDER BY City">

 

 

</asp:SqlDataSource>

 


______

______

3 Answers, 1 is accepted

Sort by
0
Helen
Telerik team
answered on 02 Oct 2009, 11:10 AM
Hello,

Please find attached a sample project how to achieve both things.

Hope this helps.

Regards,
Helen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
gc_0620
Top achievements
Rank 1
answered on 02 Oct 2009, 01:13 PM

 

Thanks Helen,

 

But one small change I had to make. In RadComboBox1_SelectedIndexChanged event, the label labelToUpdate.Text updated value

should not be combo.SelectedItem.Text but comboItem.Attributes["ContactTitle"]; That was my desire.

 

Any way is working now. Changes are in this color.

 

Sincerely

 

gc_0620

 

------------------

protected void RadComboBox1_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)

    {

        RadComboBox combo = (RadComboBox)o;

        RadComboBoxItem comboItem = combo.SelectedItem;

        string contactTitle = comboItem.Attributes["ContactTitle"];

        Label labelToUpdate = (Label)combo.NamingContainer.FindControl("ComboBoxContactTitle");

        labelToUpdate.Text =  contactTitle.ToString();

               

     

     //     labelToUpdate.Text = combo.SelectedItem.Text;

 

    }

 

<telerik:RadComboBox runat="server" ID="RadComboBox1" DataTextField="ContactName"

                                        DataValueField="ContactName" HighlightTemplatedItems="true" Height="190px" Width="220px"

                                        DropDownWidth="420px" DataSourceID="SqlDataSource1"

                                        AutoPostBack="True" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged"

                                        SelectedValue='<%#Bind("ContactName") %>'

                                        onitemdatabound="RadComboBox1_ItemDataBound">

                                        <HeaderTemplate>

                                        ....

                                       </HeaderTemplate>

                                        <ItemTemplate>

                                        <table cellpadding="0" cellspacing="0" style="width: 400px">

                                                    <tr>

                                                        <td style="width: 100px;">

                                                            <%# DataBinder.Eval(Container.DataItem, "ContactName")%>

                                                        </td>

                                                        <td style="width: 150px;">

                                                            <%# DataBinder.Eval(Container.DataItem, "City")%>

                                                        </td>

                                                        <td style="width: 150px;">

                                                            <%# DataBinder.Eval(Container.DataItem, "ContactTitle")%>

                                                        </td>

                                                    </tr>

                                                </table>

                                            

                                        </ItemTemplate>

                                    </telerik:RadComboBox>

0
Freddy Beltran
Top achievements
Rank 1
answered on 23 Oct 2009, 05:39 AM

Hello..

Thanks..

 

protected

 

void RadComboBox2_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)  

 

 

 

 

 

 

 

RadComboBox combo = (RadComboBox)o;  

 

RadComboBoxItem comboItem = combo.SelectedItem;  

 

Label labelToUpdate = (Label)combo.Items[comboItem.Index].FindControl("LblTipo");  

LblTipo.Text = labelToUpdate.Text; //  I need get this value

}

 

 

 

<

 

telerik:RadComboBox ID="RadComboBox2" runat="server" Width="260px" HighlightTemplatedItems="True"

 

 

 

 

 

 

 

Height="90px" EmptyMessage="Choose a movement of inventory"

 

 

 

 

EnableLoadOnDemand="True"

 

 

onselectedindexchanged="RadComboBox2_SelectedIndexChanged">

 

 

 

<HeaderTemplate>

 

 

 

<table style="width: 225px" cellspacing="0" cellpadding="0">

 

 

 

<tr>
<td style="width: 50px; height: 18px;">

 

 

 

 

 

Código

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

<td style="width: 165px; height: 18px;">

 

 

 

 

 

 

 

Entrada/Salida 

 

 

 

 

 

</td 

 

 

 

</tr>

 

 

</table>

 

 

 

 

 

</HeaderTemplate>

 

 

 

<ItemTemplate>

 

 

 

<table cellpadding="0" cellspacing="0" style="width: 225px">

 

 

<tr>

 

 

 

 

 

 

 

<td style="width: 50px; height: 18px;">

 

 

<%

 

 

 

# DataBinder.Eval(Container.DataItem, "CodigoMovimiento")%>

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

<td style="width: 165px; height: 18px;">  

 

 

<%

 

 

 

# DataBinder.Eval(Container.DataItem, "DescMovimiento")%>

 

 

 

 

 

 

<asp:Label ID="LblTipo" runat="server" Text='<%# Eval("Tipo")%>'

 

 

 

 

 

 

Visible="true"></asp:Label>

 

 

 

 

 

</td

 

 

 

</tr>

 

 

</table>

 

</ItemTemplate>

 

</telerik:RadComboBox>

 

 

 

 

 

 

 

 

 

El Salvador - Centro America Forever....!!!

Tags
ComboBox
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Helen
Telerik team
gc_0620
Top achievements
Rank 1
Freddy Beltran
Top achievements
Rank 1
Share this question
or