4 Answers, 1 is accepted
0
Accepted
Shinu
Top achievements
Rank 2
answered on 22 Jul 2008, 07:17 AM
Hi Thiago,
I tried implementing the required scenario on my end as shown below. Give a try with the following code snippet and see whether it helps.
ASPX:
CS:
JS:
Hope this helps..
Shinu.
I tried implementing the required scenario on my end as shown below. Give a try with the following code snippet and see whether it helps.
ASPX:
| <telerik:GridTemplateColumn UniqueName="TemplateCol" > |
| <ItemTemplate> |
| <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server"> |
| </telerik:RadNumericTextBox> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
CS:
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if(e.Item is GridDataItem) |
| { |
| GridDataItem item=(GridDataItem)e.Item; |
| string index = item.ItemIndex.ToString(); ; |
| RadNumericTextBox numtxtbx = (RadNumericTextBox)item["TemplateCol"].FindControl("RadNumericTextBox1"); |
| numtxtbx.Attributes.Add("onFocus", "return onFocus('"+ index +"');"); |
| } |
| } |
JS:
| function onFocus(index) |
| { |
| var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView(); |
| masterTable.selectItem(masterTable.get_dataItems()[index].get_element()); |
| } |
Hope this helps..
Shinu.
0
Rogerick
Top achievements
Rank 1
answered on 10 Mar 2009, 06:48 PM
Hi Shinu,
First please excuse my ignorance, I'm fairly new to the telerik controls. I'm trying to get this solution to work in my scenario. In my case, I have a radnumeric within a editItemTemplate as follows:
<telerik:GridTemplateColumn DataField="Z_HOURS_01" DataType="System.Decimal"
HeaderText="Wed" SortExpression="Z_HOURS_01" UniqueName="Z_HOURS_01">
<HeaderStyle Width="35px"></HeaderStyle>
<ItemTemplate>
<asp:Label ID="Z_HOURS_01Label" runat="server" Text='<%# Eval("Z_HOURS_01") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadNumericTextBox ID="RadNumeric_Z_HOURS_01" Runat="server"
Text='<%# Bind("Z_HOURS_01") %>' IncrementSettings-Step="0"
IncrementSettings-InterceptArrowKeys="False"
IncrementSettings-InterceptMouseWheel="False" Width="35px"
>
</telerik:RadNumericTextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
VB.NET code:
----------------
If TypeOf e.Item Is GridDataItem Then
Dim Item As GridEditableItem = CType(e.item, GridEditableItem)
Dim index As String = item.ItemIndex.ToString()
Dim numtxtbx As RadNumericTextBox = CType(item("Z_HOURS_01").FindControl("RadNumeric_Z_HOURS_01"), RadNumericTextBox)
Dim value As String = "return onFocus('" + index + "');"
numtxtbx.Attributes.Add("onFocus", value)
end if
I can't get a handle of the radnumericbox. I can only get a handle of the Label ID="Z_HOURS_01Label".
Please advise.
Thanks,
Roger
0
Princy
Top achievements
Rank 2
answered on 11 Mar 2009, 04:12 AM
Hello Roger,
Since the RadNumericTextBox is placed in the EditItemTemplate of a TemplateColumn in the grid, it will be accessible only during EditMode of the grid. So you would have to check for the IsInEditMode condition as well to access the numerictextbox.
cs:
Thanks
Princy.
Since the RadNumericTextBox is placed in the EditItemTemplate of a TemplateColumn in the grid, it will be accessible only during EditMode of the grid. So you would have to check for the IsInEditMode condition as well to access the numerictextbox.
cs:
| If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then |
| Dim Item As GridEditableItem = CType(e.item, GridEditableItem) |
| Dim index As String = item.ItemIndex.ToString() |
| Dim numtxtbx As RadNumericTextBox = CType(item("Z_HOURS_01").FindControl("RadNumeric_Z_HOURS_01"), RadNumericTextBox) |
| Dim value As String = "return onFocus('" & index & "');" |
| numtxtbx.Attributes.Add("onFocus", value) |
| End If |
Thanks
Princy.
0
Rogerick
Top achievements
Rank 1
answered on 01 May 2009, 03:46 PM
(Scoll down it's been resolved)
Hello,
This solution worked like a charm for the RadNumeric.
Unfortunately, I've run into another snag by adding a RadComboBox that is also, in the EditItemTemplate of a TemplateColumn in the grid. Adding the onFocus attribute, for the RadComboBox, doesn't seem to work. I get
I added the following on the serverside :
If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
Dim Item As GridEditableItem = CType(e.item, GridEditableItem)
Dim index As String = item.ItemIndex.ToString()
Dim numtxtbx As RadNumericTextBox = CType(item("Z_HOURS_01").FindControl("RadNumeric_Z_HOURS_01"), RadNumericTextBox)
Dim value As String = "return onFocus('" & index & "');"
numtxtbx.Attributes.Add("onFocus", value)
''RadCombo
Dim combobx As RadComboBox = CType(item("Z_CODE").FindControl("RadCombo_Z_CODE"), RadComboBox)
If TypeOf combobx Is RadComboBox Then
combobx.Attributes.Add("onFocus", value)
endif
End If
Please advise.
Thanks,
Roger
<><><><><><><><><><><><><><><><><><><><><><><><><><><<><><><><><><><
Solution to my question: Thanks again Telerik team!
<><><><><><><><><><><><><><><><><><><><><><><><><><><<><><><><><><><
Here is how - In ItemDataBound event of the grid add a custom attribute to the combobox:
Define the OnClientFocus event handler of the combobox as below:
I hope this helps.
Greetings,
Veselin Vasilev
the Telerik team
Hello,
This solution worked like a charm for the RadNumeric.
Unfortunately, I've run into another snag by adding a RadComboBox that is also, in the EditItemTemplate of a TemplateColumn in the grid. Adding the onFocus attribute, for the RadComboBox, doesn't seem to work. I get
I added the following on the serverside :
If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
Dim Item As GridEditableItem = CType(e.item, GridEditableItem)
Dim index As String = item.ItemIndex.ToString()
Dim numtxtbx As RadNumericTextBox = CType(item("Z_HOURS_01").FindControl("RadNumeric_Z_HOURS_01"), RadNumericTextBox)
Dim value As String = "return onFocus('" & index & "');"
numtxtbx.Attributes.Add("onFocus", value)
''RadCombo
Dim combobx As RadComboBox = CType(item("Z_CODE").FindControl("RadCombo_Z_CODE"), RadComboBox)
If TypeOf combobx Is RadComboBox Then
combobx.Attributes.Add("onFocus", value)
endif
End If
Please advise.
Thanks,
Roger
<><><><><><><><><><><><><><><><><><><><><><><><><><><<><><><><><><><
Solution to my question: Thanks again Telerik team!
<><><><><><><><><><><><><><><><><><><><><><><><><><><<><><><><><><><
Posted on on May 11
Hello Rogerick,Here is how - In ItemDataBound event of the grid add a custom attribute to the combobox:
| protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) |
| { |
| if (e.Item is GridDataItem) |
| { |
| GridDataItem item = (GridDataItem)e.Item; |
| string index = item.ItemIndex.ToString(); ; |
| RadComboBox combo = (RadComboBox)item["comboColumn"].FindControl("RadComboBox1"); |
| combo.Attributes["RowIndex"] = index; |
| } |
| } |
Define the OnClientFocus event handler of the combobox as below:
| <script type="text/javascript"> |
| function onClientFocus(sender, e) |
| { |
| alert(sender.get_attributes().getAttribute("RowIndex")); |
| } |
| </script> |
I hope this helps.
Greetings,
Veselin Vasilev
the Telerik team