13 Answers, 1 is accepted
Check out the following help document link.
Focus the text boxes in the edit control
Thanks
Princy.
I'm not able to set focus to the first field of the textbox when i click on "add new items" link during inline edit mode in radgid.
Can you give me more clear example?
Thanks alot.
Regards,
Soo
Try the following code snippet to set the Focus for the TextBox in Insert mode.
CS:
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if ((e.Item is GridEditFormInsertItem) && (e.Item.OwnerTableView.IsItemInserted)) |
{ |
GridEditFormInsertItem insertitem = (GridEditFormInsertItem)e.Item; |
TextBox txtbx = (TextBox)insertitem["ProductName"].Controls[0]; |
txtbx.Focus(); |
} |
} |
Thanks
Princy.
You can use code like the one below to achieve your task:
.cs
protected void RadGrid1_ItemDataBound1(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridDataInsertItem && e.Item.OwnerTableView.IsItemInserted) |
{ |
GridDataInsertItem insertItem = (GridDataInsertItem)e.Item; |
(insertItem["LastName"].Controls[0] as TextBox).Focus(); |
} |
} |
I hope this helps.
Best wishes,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Thanks of your help. I had tried your both solution but i'm not able to set focus to the textbox using txtBox.focus()
Finally, I get this done by trying to set the radgrid.enabledAjax = false first. Then manually add ajax to the radgrid using radajaxmanager.
Then, inside the itemdatabound, i put this code
RadAjaxManager1.FocusControl(txtBox)
Anyway, your both code really help alots. Thanks again.
Regards,
Soo
I am having this problem.
Could you please give more detailed code?
Thanks.
Andy.
Here is the code
Protected
Sub
dgList_ItemCreated(
ByVal
sender
As
System.
Object
,
ByVal
e
As
Telerik.Web.UI.GridItemEventArgs)
Handles
dgList.ItemCreated
If
(
TypeOf
e.Item
Is
GridDataInsertItem
And
e.Item.IsInEditMode)
Then
Dim
txtCarNumberFocus
As
RadTextBox = e.Item.FindControl(
"your_RadTextboxId"
)
RadAjaxManager1.FocusControl(txtCarNumberFocus.ClientID +
"_text"
)
e.Item.Selected =
True
End
If
End
Sub
Andy.
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
{
if ((e.Item is GridEditFormInsertItem) && (e.Item.OwnerTableView.IsItemInserted))
{
GridEditFormInsertItem insertitem = (GridEditFormInsertItem)e.Item;
TextBox txtbx = (TextBox)insertitem["ProductName"].Controls[0];
txtbx.Focus();
}
}
I get this error:
Item in insert mode does implement indexer only when the edit form is autogenerated
Any ideas how I can get past this? I am trying to set focus to an item when in edit mode.
Unfortunately I couldn't replicate the issue at my end. Please check the following code snippet I tried.
ASPX:
<
telerik:RadGrid
ID
=
"Radgrid1"
runat
=
"server"
OnItemDataBound
=
"Radgrid1_ItemDataBound"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"OrderID"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
C#:
protected
void
Radgrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
((e.Item
is
GridEditFormInsertItem) && (e.Item.OwnerTableView.IsItemInserted))
{
GridEditFormInsertItem insertitem = (GridEditFormInsertItem)e.Item;
TextBox txtbx = (TextBox)insertitem[
"OrderID"
].Controls[0];
txtbx.Focus();
}
}
Please provide your code snippet if it doesn't help.
Thanks,
Shinu.
http://www.telerik.com/community/forums/aspnet-ajax/grid/need-scrollbars-enabled-while-radgrid-is-disabled.aspx
http://www.telerik.com/community/forums/aspnet-ajax/grid/697008-need-scrollbars-enabled-while-radgrid-is-disabled.aspx
Not able to set focus in Batch edit mode.
ASPX:
<telerik:GridTemplateColumn UniqueName="OPR_COUNT" DataField="OPR_COUNT" HeaderText="OPR_COUNT" Visible="TRUE" HeaderStyle-Width="20px" >
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "OPR_COUNT")%>
</ItemTemplate>
<EditItemTemplate >
<Telerik:radTextBox ID="TextBox1" Text='<%# Bind("OPR_COUNT")%>' BackColor ="Black" ForeColor="White" runat="server" Width="70px"
Font-Size="Large" >
<ClientEvents />
</Telerik:radTextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="<b>*REQUIRED<b>" ControlToValidate="TextBox1" ForeColor="Aqua">
</asp:RequiredFieldValidator>
</EditItemTemplate>
</telerik:GridTemplateColumn>
VB:
Protected Sub rgRtnDetail_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles rgRtnDetail.ItemDataBound
If TypeOf e.Item Is GridDataItem Then
Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
Dim value = DataBinder.Eval(item.DataItem, "OPR_COUNT")
If value = 0 Then
item.ForeColor = Color.Red
Else
item.ForeColor = Color.Lime
End If
End If
'If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
' Dim item As GridEditableItem = TryCast(e.Item, GridEditableItem)
' Dim tbox As RadTextBox = TryCast(item("OPR_COUNT").Controls(0), RadTextBox)
' tbox.Focus()
'End If
'If TypeOf e.Item Is GridDataItem AndAlso e.Item.IsInEditMode Then
' Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
' Dim txtb As RadTextBox = DirectCast(item("OPR_COUNT").Controls(0), RadTextBox)
' txtb.Focus()
'End If
If (TypeOf e.Item Is GridEditFormInsertItem) AndAlso (e.Item.OwnerTableView.IsItemInserted) Then
Dim insertitem As GridEditFormInsertItem = CType(e.Item, GridEditFormInsertItem)
Dim txtbx As TextBox = CType(insertitem("OPR_COUNT").Controls(0), TextBox)
txtbx.Focus()
End If
End Sub
I can see that you have opened a formal support ticket for this issue. I advise that we discuss the details in that ticket and once we have the solution, we will share it in this thread, for the community.
Thread related to: RadComboBox focus retained when clicking other control
Kind regards,
Attila Antal
Progress Telerik