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

How to change and get value from a dropdownlist in a RadGrid column?

4 Answers 1068 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DanYeung
Top achievements
Rank 1
DanYeung asked on 08 Jul 2016, 03:20 PM

I am using a RadGrid and have some controls in columns. A DropDownList  is in ItemTemplate (see code below). For example, when the grid was first bind with a dataset, "HI" was selected. I changed the selection to "AZ" and click another control in another column to call the Javascript function "showCityList" (see code below). Then I use Google F12 to step into the function. I have two questions.

1. I can see the var cell that has all states in the dropdownlist and "HI" is selected. <option selected="selected" value="HI">HI</option>. I changed the selection to "AZ". Why the initial state was still be selected?

2. How do I get the selected state? Please provide the syntax. 

I CANNOT use OnSelectedIndexChanged and it is a long story to explain.  

<telerik:GridTemplateColumn HeaderText=" State" SortExpression="State_Code" UniqueName="State_Code">
  <ItemTemplate>
    <asp:DropDownList ID="cboState" Width="105px" CssClass="State_Code" runat="server" ></asp:DropDownList>
  </ItemTemplate>
</telerik:GridTemplateColumn>

 

function showCityList() {
                var row = Telerik.Web.UI.Grid.GetFirstParentByTagName(button, "tr");
                var rowIndex = row.id.split("__")[1];
                                
                debugger; 
                var MasterTable = $find("<%=gridSites.ClientID%>").get_masterTableView();
                var selectedRows = MasterTable.get_dataItems();
                if (selectedRows != null)
                {
                    var row = selectedRows[rowIndex];
                    var cell = MasterTable.getCellByColumnUniqueName(row, "State_Code")
               }
             return false;
}

 

Thanks.

4 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 13 Jul 2016, 06:40 AM
Hello DanYeung,

Generally, you can use the $telerik.findControl or findElement methods. You can examine the RadGridEditComboClientHideModified.zip web site sample provided in the following post for a similar implementation:
http://www.telerik.com/forums/find-control-in-insert-item-grid-client-side#2tgx6AugyU6c562P--mIIg


If you are using using EditForms or PopUp mode, the correct way to get the container edit form is using the following method:
Copy Code
Copy Code
for (var i = 0; i < editItems.length; i++) {
    setHiddenFieldIds(editItems[i].get_editFormItem());
}
...
function selectedIndexChanged(sender, args, index, tableViewID) {
    var tableView = $find(tableViewID);
    var editForm = index >= 0 ? tableView.get_dataItems()[index].get_editFormItem() : tableView.get_insertItem();
    setHiddenFieldIds(editForm);
}

I hope this will prove helpful.


Regards,
Eyup
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Kiran
Top achievements
Rank 1
answered on 24 Apr 2019, 03:49 PM

Can you please provide sample code for this?

I have a radcombobox inside itemtemplate of gridtemplatecolumn of a radgrid. On slectedindexchanged event I want to update record by grabbing few values from other columns of the same record. 

 

Thank you.

0
Kiran
Top achievements
Rank 1
answered on 24 Apr 2019, 03:55 PM

I figured this out. If anyone is trying to access radgrid other column values in radcombobox selectedindexchanged via radcombox within radgrid in the item template, see the following:

 

Protected Sub radLocID_SelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs)

        Dim cmbLocId As RadComboBox = CType(sender, RadComboBox)
        Dim item As GridDataItem = CType(cmbLocId.NamingContainer, GridDataItem)
        Dim strLocID As String = (TryCast(sender, RadComboBox)).SelectedValue

        Dim strSYSID As String = item.GetDataKeyValue("IB_MAIN_ID").ToString



    End Sub

 

 

strLocID is the value that comes from radcombox within the radgrid but I also want the value of IB_MAIN_ID which is in another column. 

0
Eyup
Telerik team
answered on 29 Apr 2019, 07:47 AM
Hi Kiran,

Thank you for sharing your specific approach with our community. I hope it will prove to other developers as well.

Regards,
Eyup
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.
Tags
Grid
Asked by
DanYeung
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Kiran
Top achievements
Rank 1
Share this question
or