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

Wiring up Radcombobox events in a RadGrid FormTemplate and retrieving values. Help Please!

5 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jared
Top achievements
Rank 1
Jared asked on 30 Sep 2010, 10:51 PM

 

 

 

I would really appreciate assistance with this one I'm have an issue to dynamically updating the dropdown in the FormTemplate. I need to wire up the events and retrieve the values.

Thanks in advance.

<

 

 

telerik:RadGrid ID="radgvLocation" runat="server" CssClass="RadGrid" GridLines="None"

 

 

 

 

 

 

 

AllowPaging="True" PageSize="15" AllowSorting="True" AutoGenerateColumns="False"

 

 

 

 

 

 

 

ShowStatusBar="true" AllowAutomaticDeletes="false" AllowAutomaticInserts="false"

 

 

 

 

 

 

 

AllowAutomaticUpdates="false" HorizontalAlign="NotSet" Skin="Vista" OnInsertCommand="radgvLocation_InsertCommand"

 

 

 

 

 

 

 

OnNeedDataSource="radgvLocation_NeedDataSource" OnUpdateCommand="radgvLocation_UpdateCommand"

 

 

 

 

 

 

 

OnDeleteCommand="radgvLocation_DeleteCommand" OnItemDataBound="radgvLocation_ItemDatabound" OnDetailTableDataBind="radgvLocation_DetailTableDataBind">

 

 

 

 

 

 

 

 

<MasterTableView CommandItemDisplay="Top" DataKeyNames="LocationID" EditMode="PopUp">

 

 

 

 

 

 

 

<CommandItemTemplate>

 

 

 

 

 

 

 

<telerik:RadToolBar ID="RadToolBar1" OnButtonClick="RadToolBar1_ButtonClick" runat="server"

 

 

 

 

 

 

 

Skin="Vista" Visible='<%# radgvLocation.EditIndexes.Count == 0 %>' CommandName="EditSelected"

 

 

 

 

 

 

 

OnClientButtonClicking="onToolBarClientButtonClicking">

 

 

 

 

 

 

 

<Items>

 

 

 

 

 

 

 

<telerik:RadToolBarButton Text="Add new" CommandName="InitInsert" ImageUrl="~/Images/AddRecord.gif"

 

 

 

 

 

 

 

Visible='<%# !radgvLocation.MasterTableView.IsItemInserted %>'>

 

 

 

 

 

 

 

</telerik:RadToolBarButton>

 

 

 

 

 

 

 

<telerik:RadToolBarButton Text="Edit selected" CommandName="EditSelected" ImageUrl="~/Images/Edit.gif">

 

 

 

 

 

 

 

</telerik:RadToolBarButton>

 

 

 

 

 

 

 

<telerik:RadToolBarButton Text="Delete" CommandName="DeleteSelected" ImageUrl="~/Images/Delete.gif">

 

 

 

 

 

 

 

</telerik:RadToolBarButton>

 

 

 

 

 

 

 

<telerik:RadToolBarButton Text="Refresh" CommandName="RebindGrid" ImageUrl="~/Images/Refresh.gif">

 

 

 

 

 

 

 

</telerik:RadToolBarButton>

 

 

 

 

 

 

 

</Items>

 

 

 

 

 

 

 

</telerik:RadToolBar>

 

 

 

 

 

 

 

</CommandItemTemplate>

 

 

 

 

 

 

 

<SortExpressions>

 

 

 

 

 

 

 

<telerik:GridSortExpression FieldName="LocationID" SortOrder="Descending" />

 

 

 

 

 

 

 

</SortExpressions>

 

<

 

 

CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>

 

 

 

 

 

 

 

<Columns>

 

 

 

 

 

 

 

<telerik:GridTemplateColumn UniqueName="SNo" HeaderText="SNo.">

 

 

 

 

 

 

 

<ItemTemplate>

 

 

 

 

 

 

 

<asp:Label ID="lblSno" runat="server"></asp:Label>

 

 

 

 

 

 

 

</ItemTemplate>

 

 

 

 

 

 

 

<HeaderStyle Width="30px" />

 

 

 

 

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

 

 

 

<telerik:GridBoundColumn UniqueName="LocationCode" HeaderText="LocationCode" DataField="LocationCode">

 

 

 

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

 

 

 

<telerik:GridBoundColumn UniqueName="LocationName" HeaderText="LocationName" DataField="LocationName">

 

 

 

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

 

 

 

<telerik:GridBoundColumn UniqueName="Address1" HeaderText="Address1" DataField="Address1">

 

 

 

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

 

 

 

<telerik:GridBoundColumn UniqueName="Address2" HeaderText="Address2" DataField="Address2">

 

 

 

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

 

 

 

<telerik:GridBoundColumn UniqueName="City" HeaderText="City" DataField="CityName">

 

 

 

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

 

 

 

<telerik:GridBoundColumn UniqueName="State" HeaderText="State" DataField="StateName">

 

 

 

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

 

 

 

<telerik:GridBoundColumn UniqueName="ZipCode" HeaderText="ZipCode" DataField="ZipCodeName">

 

 

 

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

 

 

 

<telerik:GridBoundColumn UniqueName="Phone" HeaderText="Phone" DataField="Phone">

 

 

 

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

 

 

 

<telerik:GridBoundColumn UniqueName="Fax" HeaderText="Fax" DataField="Fax">

 

 

 

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

 

 

 

</Columns>

 

 

 

 

 

 

 

<EditFormSettings InsertCaption="Add new item" CaptionFormatString="Edit Location ID: {0}"

 

 

 

 

 

 

 

CaptionDataField="LocationID" PopUpSettings-Width="560" EditFormType="Template"

 

 

 

 

 

 

 

PopUpSettings-Modal="true">

 

 

 

 

 

 

 

<FormTemplate>

 

 

 

 

 

 

 

<table id="Table1" cellspacing="1" cellpadding="1" class="popuptbl" width="520" border="0">

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

Location Code :

 

 

</td>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

 

 

<telerik:RadTextBox Width="160px" ID="radtxtLocationCode" runat="server" Text='<%# Bind( "LocationCode") %>'

 

 

 

 

 

 

 

EmptyMessage="type here" >

 

 

 

 

 

 

 

</telerik:RadTextBox>

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

Location Name :

 

 

</td>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

 

 

<telerik:RadTextBox Width="160px" ID="radtxtLocationName" runat="server" Text='<%# Bind( "LocationName") %>'

 

 

 

 

 

 

 

EmptyMessage="type here" >

 

 

 

 

 

 

 

</telerik:RadTextBox>

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

Address 1 :

 

 

</td>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

 

 

<telerik:RadTextBox Width="160px" ID="radtxtAddress1" runat="server" Text='<%# Bind( "Address1") %>'

 

 

 

 

 

 

 

EmptyMessage="type here" >

 

 

 

 

 

 

 

</telerik:RadTextBox>

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

Address 2 :

 

 

</td>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

 

 

<telerik:RadTextBox Width="160px" ID="radtxtAddress2" runat="server" Text='<%# Bind( "Address2") %>'

 

 

 

 

 

 

 

EmptyMessage="type here" >

 

 

 

 

 

 

 

</telerik:RadTextBox>

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

Country :

 

 

</td>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

 

 

<telerik:RadComboBox ID="radcmbCountry" Width="160px"

 

 

 

DataTextField="CountryName" SelectedValue='<%# Bind( "CountryID") %>'

 

 

 

 

 

 

 

DataValueField="CountryID" AppendDataBoundItems="true" DataSourceID="DsCountrySelect"

 

 

 

 

 

 

 

AllowCustomText="false" AutoCompleteSeparator="" MarkFirstMatch="true"

 

 

 

runat="server" onselectedindexchanged="radcmbCountry_SelectedIndexChanged">

 

 

 

 

 

 

 

</telerik:RadComboBox>

 

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

State :

 

 

</td>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

 

 

 

<telerik:RadComboBox ID="radcmbState" oncontextmenu="return false"

 

 

 

Width="160px" SelectedValue='<%# Bind( "StateID") %>'

 

 

 

 

 

 

 

runat="server" DataTextField="Name" DataValueField="StateID"

 

 

 

 

 

 

 

AppendDataBoundItems="true" DataSourceID="DsStateSelect" AllowCustomText="false"

 

 

 

 

 

 

 

AutoCompleteSeparator="" MarkFirstMatch="true"

 

 

 

onselectedindexchanged="radcmbState_SelectedIndexChanged" >

 

 

 

 

 

 

 

</telerik:RadComboBox>

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

City :

 

 

</td>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

 

 

 

<telerik:RadComboBox ID="radcmbCity" Width="163px" DataTextField="CityName" SelectedValue='<%# Bind( "CityID") %>'

 

 

 

 

 

 

 

DataValueField="CityID" AppendDataBoundItems="true" DataSourceID="DsCitySelect"

 

 

 

 

 

 

 

AllowCustomText="false" AutoCompleteSeparator="" MarkFirstMatch="true" runat="server">

 

 

 

 

 

 

 

</telerik:RadComboBox>

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

ZipCode :

 

 

</td>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

 

 

 

<telerik:RadComboBox ID="radcmbZipCode" Width="163px" DataTextField="ZipCodeName" SelectedValue='<%# Bind( "ZipcodeID") %>'

 

 

 

 

 

 

 

DataValueField="ZipCodeID" AppendDataBoundItems="true" DataSourceID="DsZipCodeSelect"

 

 

 

 

 

 

 

AllowCustomText="false" AutoCompleteSeparator="" MarkFirstMatch="true" runat="server">

 

 

 

 

 

 

 

</telerik:RadComboBox>

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

Phone :

 

 

</td>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

 

 

<telerik:RadTextBox Width="160px" ID="RadTextBox1" runat="server" Text='<%# Bind( "Phone") %>'

 

 

 

 

 

 

 

EmptyMessage="type here" >

 

 

 

 

 

 

 

</telerik:RadTextBox>

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

Fax :

 

 

</td>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

 

 

<telerik:RadTextBox Width="160px" ID="RadTextBox2" runat="server" Text='<%# Bind( "Fax") %>'

 

 

 

 

 

 

 

EmptyMessage="type here" >

 

 

 

 

 

 

 

</telerik:RadTextBox>

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

</table>

 

 

 

 

 

 

 

<table style="width: 100%">

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td align="right">

 

 

 

 

 

 

 

<asp:Button ID="Button1" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'

 

 

 

 

 

 

 

runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>

 

 

 

 

 

 

 

</asp:Button>&nbsp;

 

 

 

 

 

 

 

<asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">

 

 

 

 

 

 

 

</asp:Button>

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

</table>

 

 

 

 

 

 

 

</FormTemplate>

 

 

 

 

 

<

 

 

PopUpSettings Modal="True" Width="560px"></PopUpSettings>

 

 

 

 

 

 

 

</EditFormSettings>

 

 

 

 

 

 

 

</MasterTableView>

 

 

 

 

 

 

 

<ClientSettings>

 

 

 

 

 

 

 

<Selecting AllowRowSelect="True" EnableDragToSelectRows="True" />

 

 

 

 

 

 

 

</ClientSettings>

 

 

 

 

 

 

 

</telerik:RadGrid>

 

 

 

 







protected

 

 

void radgvLocation_ItemCommand(object source, GridCommandEventArgs e)

 

{

 

 

 

switch (e.CommandName)

 

{

 

 

case "UpdateCountry":

 

 

 

RadComboBox radcmbCountry = (RadComboBox)e.Item.FindControl("radcmbCountry");

 

 

 

break;

 

 

 

 

case "UpdateState":

 

 

 

RadComboBox radcmbState = (RadComboBox)e.Item.FindControl("radcmbState");

 

 

 

break;

 

 

}

radgvLocation.Rebind();

}

 

 

 

protected void radgvLocation_ItemCreated(object sender, GridItemEventArgs e)

 

{

 

 

 

// GridEditFormItem editForm = e.Item as GridEditFormItem;

 

 

 

 

if (e.Item is GridEditFormItem && e.Item.IsInEditMode)

 

{

 

 

RadComboBox radcmbCountry = (e.Item as GridEditFormItem)["radcmbCountry"].Controls[0] as RadComboBox;

 

radcmbCountry.AutoPostBack =

 

true;

 

radcmbCountry.SelectedIndexChanged +=

 

new System.EventHandler(this.radcmbCountry_SelectedIndexChanged);

 

 

 

 

 

RadComboBox radcmbState = (e.Item as GridEditFormItem)["radcmbState"].Controls[0] as RadComboBox;

 

radcmbState.AutoPostBack =

 

true;

 

radcmbState.SelectedIndexChanged +=

 

new System.EventHandler(this.radcmbState_SelectedIndexChanged);

 

 //// above line causes error

 

}

}

 

 

protected void radcmbCountry_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)

 

{

}

 

 

protected void radcmbState_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)

 

{

}

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 01 Oct 2010, 06:43 AM
Hello Aaron,

Set 'AutoPostBack' property of RadComboBox as 'True' to  to fire its 'OnSelectedIndexChanged' event . And the following code shows how to get the selected values of RadComboBox in OnSelectedIndexChanged event.

C#:
protected void radcmbCountry_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
  {
      RadComboBox combo = (RadComboBox)o;
      string selectedvalue = combo.SelectedValue;
  }

You can use the following code snippet to retrieve the selectedvalues of RadComboBox in UpdateCommand.

protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
   {
       GridEditFormItem editItem = (GridEditFormItem)e.Item;
       RadComboBox combo = (RadComboBox)editItem.FindControl("radcmbCountry");
       string selectedvalue = combo.SelectedValue;
   }

Thanks,
Princy.
0
Jared
Top achievements
Rank 1
answered on 01 Oct 2010, 12:38 PM
Thanks Princy, 

I guess I should have asked and presented the question correctly.  How would I make this work? Thx again

     protected void radcmbCountry_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            RadComboBox combo = (RadComboBox)o;
            string selectedvalue = combo.SelectedValue;
      

 

////  Referencing alternative combobox object directly

///     rdcmbState.Items.Clear();

///     rdcmbState.DataBind();



}

        #region protected void dsState_SelectObject(object sender, Csla.Web.SelectObjectArgs e)
        protected void DsStateSelectObject(object sender, Csla.Web.SelectObjectArgs e)
        {

            Guid CountryID = Guid.Empty;

         
////  Referencing the combobox object directly
   if (radcmbCountry.SelectedValue != "")
                CountryID = Guid.Parse(radcmbCountry.SelectedValue);

           
            e.BusinessObject =
                StateList.GetStatesByCountry(SessionHelper.SessionUserObjectsInfo.ClientId, CountryID);
           
            //rdcmbState.Items.Insert(0, new RadComboBoxItem("ALL", ""));
            //rdcmbState.SelectedIndex = 0;
          
        }
        #endregion




0
Pavlina
Telerik team
answered on 07 Oct 2010, 09:40 AM
Hi Aaron,

Unfortunately I am not able to create a runnable example based on your code. Could you please send us  a small sample that demonstrates your scenario? Additionally could you provide some more details about what you are trying to accomplish?

Looking forward to your reply.

Sincerely yours,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
picnic
Top achievements
Rank 1
answered on 30 May 2012, 04:40 PM


Hi Princy,

protected void radcmbCountry_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
  {
      RadComboBox combo = (RadComboBox)o;
      string selectedvalue = combo.SelectedValue;
  }


This will be working great with just one combobox.
But what about 2(or more) related comboboxes ?

I've tried the 2 following examples from the code library :
Nice and simple, but it does not make use of the formtemplate, which I want
Even better with interraction from the client and a usercontrol, but by using a usercontrol I loose all the benefits of the automatic insert/update/delete I currently have (my grid is using an objectdatasource).

Would you see any other possibility of
- either being able to access multiple comboboxes inside a real formtemplate (server side or client side) ?
- or, alternatively, to allow automatic operations through a usercontrol ?

Thank you very much i nadvance for your help,




0
Elliott
Top achievements
Rank 2
answered on 30 May 2012, 07:54 PM
I think the NamingContainer property is the grid item of the sender object
once you get the grid item find the table cell (the Country table cell if the SelectedValue of the Continents was fired) and fill the combo box
this is a code snippet to get to controls in a Form Template
I indexed my way to the right table cell - the "right" way is to use the UniqueName

Dim geItem As GridEditableItem = Nothing
Dim tcPartNumber, tcQty As TableCell
Dim txtPartNumber As TextBox
Dim rntbQty As RadNumericTextBox
Dim btnUpdate As LinkButton
 
If e.Item.IsInEditMode Then
Else
    Exit Sub
End If
If TypeOf e.Item Is GridEditableItem Then
Else
    Exit Sub
End If
geItem = DirectCast(e.Item, GridEditableItem)
tcPartNumber = geItem.Cells(0)
txtPartNumber = DirectCast(tcPartNumber.FindControl("txtPartNumber"), TextBox)
btnUpdate = DirectCast(geItem.FindControl("btnUpdate"), LinkButton)
tcQty = geItem.Cells(1)
rntbQty = tcQty.FindControl("rntbQty")
Tags
Grid
Asked by
Jared
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Jared
Top achievements
Rank 1
Pavlina
Telerik team
picnic
Top achievements
Rank 1
Elliott
Top achievements
Rank 2
Share this question
or