I am having hard time getting value of RadComboBoxes in RadGrid. Here is the Javascript that I tried to write. I also don't know how to get the index of the row.
Thanks for help.
function Validate(sender, args)
{
var DataItems = $find("<%=RadGrid3.ClientID %>").get_masterTableView().get_dataItems();
var index =??????????????????????
var cb1 = $telerik.findControl(DataItems[index].get_element(), "RadComboBox1");
var cb2 = $telerik.findControl(DataItems[index].get_element(), "RadComboBox2");
}
4 Answers, 1 is accepted
I am not sure in which client event you are trying to access RadComboBox. Here is the sample code to get the selected row using the row index in the OnRowSelected client event.
ASPX:
| <ClientSettings> |
| <Selecting AllowRowSelect="True" /> |
| <ClientEvents OnRowSelected="RowSelected" /> |
| </ClientSettings> |
JS:
| function RowSelected(sender, eventArgs) |
| { |
| var dataItem = $get(eventArgs.get_id()); |
| var grid = sender; |
| var MasterTable = grid.get_masterTableView(); |
| var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()]; |
| } |
You may also go through the following help article which explains how to access a control from the grid row using findControl() method.
findControl()
Thanks
Shinu
Hi Shinu,
I have a custom validator as follow.
<asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="Validate"
ControlToValidate="RadComboBox2" ErrorMessage="error" Display="Dynamic" ></asp:CustomValidator>
Here is the function that I tried, and it works when I manually put the index. How do i fix this. It needs to be in edit mode.
function Validate(sender, args)
{
var cb1=$find("<%= RadGrid3.ClientID%>").get_masterTableView().get_dataItems()[1].findControl("RadComboBox1");
var cb2=$find("<%= RadGrid3.ClientID%>").get_masterTableView().get_dataItems()[1].findControl("RadComboBox2");
alert(cb1.get_text()+
" " + cb2.get_text());
}
Thanks,
Fatma
I don't know how it marked as answered, but I still need help on this one.
I can read radcombobox values from the grid, but I am having hard time getting the index of the row. I tried to row select event and everything else. Nothing worked!
I need to click "Edit" on a row, and get the value of coboboxes and validate their values with CustomValidator.
Please help!!
here is the code I have so far
<asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="Validate"
ControlToValidate="RadComboBox2" ErrorMessage="Invalid Entry" Display="Dynamic" ></asp:CustomValidator>
function Validate(sender, args)
{
//idx=args.get_itemIndexHierarchical();
var cb1=$find("<%= RadGrid3.ClientID%>").get_masterTableView().get_dataItems()[0].findControl("RadComboBox1");
var cb2=$find("<%= RadGrid3.ClientID%>").get_masterTableView().get_dataItems()[0].findControl("RadComboBox2");
alert(cb1.get_text()+" " + cb2.get_text());
if(cb1.get_text()=="S" & cb2.get_text()=="0.00")
{
args.IsValid=false;
}
}
In order to achieve this scenario, attach event handlers to the OnSelectedIndexChanging event of the two combo boxes and define them as follows:
| function Validate() |
| { |
| if(cb1ItemText=="S" && cb2ItemText=="0.00") |
| { |
| args.IsValid=false; |
| } |
| } |
| var cb1ItemText; |
| function selectedIndexChangingCombo1(sender, args) |
| { |
| cb1ItemText = args.get_item().get_text(); |
| } |
| var cb2ItemText; |
| function selectedIndexChangingCombo2(sender, args) |
| { |
| cb2ItemText = args.get_item().get_text(); |
| } |
I hope this helps.
All the best,
Tsvetoslav
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.