13 Answers, 1 is accepted
0
Accepted
Princy
Top achievements
Rank 2
answered on 22 Nov 2010, 10:17 AM
Hello Sumanth,
You can try the following code to access the control inside NoRecordsItemTemplate.
ASPX:
C#:
Thanks,
Princy.
You can try the following code to access the control inside NoRecordsItemTemplate.
ASPX:
<
NoRecordsTemplate
>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
Text
=
"No records"
></
asp:Label
>
</
NoRecordsTemplate
>
C#:
protected
void
RadGrid1_PreRender(
object
sender, EventArgs e)
{
GridNoRecordsItem norecordItem = (GridNoRecordsItem)RadGrid1.MasterTableView.GetItems(GridItemType.NoRecordsItem)[0];
Label lbl = (Label)norecordItem.FindControl(
"Label1"
);
}
Thanks,
Princy.
0
Sumanth
Top achievements
Rank 1
answered on 25 Nov 2010, 07:15 AM
Hi Princy.
This is working fine for me. Thanks alot.
Thanks & Regards,
Sumanth
This is working fine for me. Thanks alot.
Thanks & Regards,
Sumanth
0
Brad H
Top achievements
Rank 2
answered on 22 Jan 2011, 05:08 PM
Does this have to be on Pre_Render? I get IndexOutOfRangeException when I try to use this during the NeedDataSource event.
0
Hello Sumanth,
You cannot use Princy's approach on NeedDataSource as the item is not yet created.
Another option is to handle Item created instead of PreRender:
Regards,
Nikolay
the Telerik team
You cannot use Princy's approach on NeedDataSource as the item is not yet created.
Another option is to handle Item created instead of PreRender:
protected
void
Grid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridNoRecordsItem)
{
}
}
Regards,
Nikolay
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
arubbert
Top achievements
Rank 1
answered on 25 Apr 2012, 09:03 AM
Hi all,
I need to enable a RadButton in <NoRecordsTemplate>
Over OnPreRender in the MasterTabelView
... but the debugger returned the following error message
IndexOutOfRangeException was unhandled by user code / Index was outside the bounds of the array
The RadGrid is inside a RadMultiPage/RadPageView
Any ideas ?
Best regards
Andreas
Version Q1-2012
I need to enable a RadButton in <NoRecordsTemplate>
<
NoRecordsTemplate
>
<
telerik:RadButton
ID
=
"BrokerDetailsContactNoRecordAdd"
runat
=
"server"
Text
=
"Add new Contact"
Enabled
=
"false"
OnClientClicked
=
"BrokerDetailsContactAddOnClick"
AutoPostBack
=
"false"
style
=
"margin: 10px 0 0 10px;"
>
<
Icon
PrimaryIconCssClass
=
"rbAdd"
PrimaryIconLeft
=
"4"
PrimaryIconTop
=
"4"
/>
</
telerik:RadButton
>
</
NoRecordsTemplate
>
Over OnPreRender in the MasterTabelView
protected
void
BrokerDetailsContactGridPreRender(
object
sender, EventArgs e)
{
GridNoRecordsItem gridContactAdd = (GridNoRecordsItem)BrokerDetailsContactGrid.MasterTableView.GetItems(GridItemType.NoRecordsItem)[0];
RadButton buttonContactAdd = (RadButton)gridContactAdd.FindControl(
"BrokerDetailsContactNoRecordAdd"
);
buttonContactAdd.Enabled =
true
;
}
... but the debugger returned the following error message
IndexOutOfRangeException was unhandled by user code / Index was outside the bounds of the array
The RadGrid is inside a RadMultiPage/RadPageView
Any ideas ?
Best regards
Andreas
Version Q1-2012
0
Princy
Top achievements
Rank 2
answered on 25 Apr 2012, 10:09 AM
Hi,
Try enabling the RadButton in ItemCreated event. Please take a look into the following code snippet.
C#:
Thanks,
Princy.
Try enabling the RadButton in ItemCreated event. Please take a look into the following code snippet.
C#:
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridNoRecordsItem)
{
GridNoRecordsItem item = (GridNoRecordsItem)e.Item;
RadButton Button1 = (RadButton)item.FindControl(
"BrokerDetailsContactNoRecordAdd"
);
Button1.Enabled =
true
;
}
}
Thanks,
Princy.
0
arubbert
Top achievements
Rank 1
answered on 25 Apr 2012, 10:28 AM
Hi Princy,
thx for the fast reply.
It looks like that the if clause are not working. BrokerDetailsEditButton.Enabled=false works outside the if clause.
regards
Andreas
thx for the fast reply.
protected
void
BrokerDetailsContactGridOnItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridNoRecordsItem)
{
GridNoRecordsItem gridContactAdd = (GridNoRecordsItem)e.Item;
RadButton buttonContactAdd = (RadButton)gridContactAdd.FindControl(
"BrokerDetailsContactNoRecordAdd"
);
buttonContactAdd.Enabled = true
;
BrokerDetailsEditButton.Enabled =
false
;
}
}
It looks like that the if clause are not working. BrokerDetailsEditButton.Enabled=false works outside the if clause.
regards
Andreas
0
Princy
Top achievements
Rank 2
answered on 25 Apr 2012, 11:07 AM
Hi,
From your code I could find only a RadButton in the NoRecordTemplate. Please make sure that the 'BrokerDetailsEditButton' is also inside the NoRecordTemplate.
Please provide the markup for the 'BrokerDetailsEditButton' for further assistance.
Thanks,
Princy.
From your code I could find only a RadButton in the NoRecordTemplate. Please make sure that the 'BrokerDetailsEditButton' is also inside the NoRecordTemplate.
Please provide the markup for the 'BrokerDetailsEditButton' for further assistance.
Thanks,
Princy.
0
arubbert
Top achievements
Rank 1
answered on 25 Apr 2012, 11:11 AM
Hi,
I only placed the 'BrokerDetailsEditButton' into the if clause for testing. The BrokerDetailsContactNoRecordAdd button doesn´t enable.
This is the code where my <NoRecordsTemplate> is placed.
Thx
Andreas
I only placed the 'BrokerDetailsEditButton' into the if clause for testing. The BrokerDetailsContactNoRecordAdd button doesn´t enable.
<
telerik:RadMultiPage
ID
=
"BrokerDetailsMultiPage"
runat
=
"server"
SelectedIndex
=
"0"
style
=
"margin: 0 10px 10px 10px;"
>
<
telerik:RadPageView
ID
=
"BrokerDetailsContactPageView"
runat
=
"server"
>
<
telerik:RadGrid
ID
=
"BrokerDetailsContactGrid"
runat
=
"server"
DataSourceID
=
"BrokerContactEDS"
GridLines
=
"None"
Height
=
"238px"
Width
=
"100%"
AllowPaging
=
"True"
PageSize
=
"25"
AllowSorting
=
"True"
AutoGenerateColumns
=
"False"
ShowStatusBar
=
"True"
OnItemCreated
=
"BrokerDetailsContactGridOnItemCreated"
EnableHeaderContextMenu
=
"True"
EnableHeaderContextFilterMenu
=
"True"
AllowFilteringByColumn
=
"True"
>
<
PagerStyle
AlwaysVisible
=
"true"
/>
<
ClientSettings
EnableRowHoverStyle
=
"true"
EnablePostBackOnRowClick
=
"false"
>
<
ClientEvents
OnRowContextMenu
=
"BrokerDetailsContactGridRowContextMenu"
OnRowClick
=
"BrokerDetailsContactGridOnRowClick"
OnScroll
=
"handleScrolling"
/>
<
Scrolling
AllowScroll
=
"true"
UseStaticHeaders
=
"true"
SaveScrollPosition
=
"true"
/>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
<
GroupingSettings
CaseSensitive
=
"false"
/>
<
MasterTableView
runat
=
"server"
DataSourceID
=
"BrokerContactEDS"
Width
=
"100%"
AllowFilteringByColumn
=
"true"
IsFilterItemExpanded
=
"false"
ShowHeadersWhenNoRecords
=
"false"
DataKeyNames
=
"BmsBrokerID, BmsBrokerGroupID, BmsBrokerContactID"
ClientDataKeyNames
=
"BmsBrokerID, BmsBrokerGroupID, BmsBrokerContactID"
>
<
NoRecordsTemplate
>
<
telerik:RadButton
ID
=
"BrokerDetailsContactNoRecordAdd"
runat
=
"server"
Text
=
"Add new Contact"
Enabled
=
"true"
OnClientClicked
=
"BrokerDetailsContactAddOnClick"
AutoPostBack
=
"false"
style
=
"margin: 10px 0 0 10px;"
>
<
Icon
PrimaryIconCssClass
=
"rbAdd"
PrimaryIconLeft
=
"4"
PrimaryIconTop
=
"4"
/>
</
telerik:RadButton
>
</
NoRecordsTemplate
>
<
PagerTemplate
>
<
div
style
=
"line-height: 24px; padding-right: 10px; float: right;"
>
Total records: <%# DataBinder.Eval(Container, "Paging.DataSourceCount") %>
</
div
>
</
PagerTemplate
>
<
Columns
>
This is the code where my <NoRecordsTemplate> is placed.
Thx
Andreas
0
arubbert
Top achievements
Rank 1
answered on 25 Apr 2012, 09:40 PM
Solution or Bug ?
MUST be set to "true" and than the code works :-(
regards
Andreas
ShowHeadersWhenNoRecords="false"
MUST be set to "true" and than the code works :-(
regards
Andreas
0
Princy
Top achievements
Rank 2
answered on 26 Apr 2012, 05:02 AM
Hello Andreas,
If ShowHeadersWhenNoRecords Property is set to true (the default) GridNoRecordsItem is used to display no records template. This item is the only one displayed in the GridTableView in this case. Since you set ShowHeadersWhenNoRecords to false, GridNoRecordsItem was not accessible and showed error.
Thanks,
Princy.
If ShowHeadersWhenNoRecords Property is set to true (the default) GridNoRecordsItem is used to display no records template. This item is the only one displayed in the GridTableView in this case. Since you set ShowHeadersWhenNoRecords to false, GridNoRecordsItem was not accessible and showed error.
Thanks,
Princy.
0
T. Stanley
Top achievements
Rank 1
answered on 01 Jun 2012, 04:12 PM
Hi. A followup question regarding controls in a NoRecordsTemplate. I have a RadButton inside a NoRecordsTemplate, and in its OnClick code-behind, I need it to access other controls (RadTextBoxes) also in the NoRecordsTemplate. However, they are not accessible, and I don't know how to find them in code. Can you help?
Here's my markup of the NoRecordsTemplate in the RadGrid:
and this in the code-behind:
Thanks!!
Tom Stanley
Here's my markup of the NoRecordsTemplate in the RadGrid:
<
NoRecordsTemplate
>
<
div
style
=
"padding: 20px 20px 20px 20px; height: 300px;"
>
<
div
style
=
"float: left;"
>
<
h4
>
No patient was found with the MRN
<
asp:Label
ID
=
"lblMRN"
runat
=
"server"
Text
=
"'mrn'"
Font-Bold
=
"True"
></
asp:Label
></
h4
>
Enter new patient information below:
<
br
/>
<
br
/>
<
table
>
<
tr
>
<
td
class
=
"tablelabel"
>
Last Name:
</
td
>
<
td
class
=
"tabledata"
>
<
telerik:RadTextBox
ID
=
"rtbLastName"
runat
=
"server"
SelectionOnFocus
=
"SelectAll"
TabIndex
=
"1"
>
</
telerik:RadTextBox
>
</
td
>
<
td
class
=
"tablevalidator"
>
<
asp:RequiredFieldValidator
ID
=
"rfvLastName"
runat
=
"server"
Display
=
"Dynamic"
ControlToValidate
=
"rtbLastName"
ErrorMessage
=
"Last Name is REQUIRED"
CssClass
=
"validation"
></
asp:RequiredFieldValidator
>
<
asp:RegularExpressionValidator
Display
=
"Dynamic"
ID
=
"revLastName"
runat
=
"server"
ErrorMessage
=
"Alphabetic characters only"
ControlToValidate
=
"rtbLastName"
ValidationExpression
=
"[a-zA-Z']+"
CssClass
=
"validation"
/> <%--[a-zA-Z\-'\s]+--%>
</
td
>
</
tr
>
<
tr
>
<
td
class
=
"tablelabel"
>
First Name:
</
td
>
<
td
class
=
"tabledata"
>
<
telerik:RadTextBox
ID
=
"rtbFirstName"
runat
=
"server"
TabIndex
=
"2"
>
</
telerik:RadTextBox
>
</
td
>
<
td
class
=
"tablevalidator"
>
<
asp:RequiredFieldValidator
ID
=
"rfvFirstName"
runat
=
"server"
Display
=
"Dynamic"
ControlToValidate
=
"rtbFirstName"
ErrorMessage
=
"First Name is REQUIRED"
CssClass
=
"validation"
></
asp:RequiredFieldValidator
>
<
asp:RegularExpressionValidator
Display
=
"Dynamic"
ID
=
"revFirstName"
runat
=
"server"
ErrorMessage
=
"Alphabetic characters only"
ControlToValidate
=
"rtbFirstName"
ValidationExpression
=
"[a-zA-Z']+"
CssClass
=
"validation"
/>
</
td
>
</
tr
>
<
tr
>
<
td
class
=
"tablelabel"
>
MRN:
</
td
>
<
td
class
=
"tabledata"
>
<
telerik:RadTextBox
ID
=
"rtbMRN"
runat
=
"server"
Enabled
=
"false"
>
<
DisabledStyle
Font-Bold
=
"True"
ForeColor
=
"Black"
/>
</
telerik:RadTextBox
>
</
td
>
<
td
class
=
"tablevalidator"
>
</
td
>
</
tr
>
<
tr
>
<
td
class
=
"tablelabel"
>
Date of Birth:
</
td
>
<
td
class
=
"tabledata"
>
<
telerik:RadDatePicker
ID
=
"rdpDOB"
runat
=
"server"
MinDate
=
"1912-01-01"
TabIndex
=
"3"
>
<
Calendar
UseColumnHeadersAsSelectors
=
"False"
UseRowHeadersAsSelectors
=
"False"
ViewSelectorText
=
"x"
>
</
Calendar
>
<
DateInput
DateFormat
=
"M/d/yyyy"
DisplayDateFormat
=
"M/d/yyyy"
LabelWidth
=
""
TabIndex
=
"3"
>
</
DateInput
>
<
DatePopupButton
HoverImageUrl
=
""
ImageUrl
=
""
TabIndex
=
"3"
/>
</
telerik:RadDatePicker
>
</
td
>
<
td
class
=
"tablevalidator"
>
<
asp:RequiredFieldValidator
ID
=
"rfvDOB"
runat
=
"server"
Display
=
"Dynamic"
ControlToValidate
=
"rdpDOB"
ErrorMessage
=
"Date of Birth is REQUIRED"
CssClass
=
"validation"
></
asp:RequiredFieldValidator
>
</
td
>
</
tr
>
<
tr
>
<
td
class
=
"tablelabel"
>
Phone:
</
td
>
<
td
class
=
"tabledata"
>
<
telerik:RadMaskedTextBox
ID
=
"rmtPhone"
runat
=
"server"
Mask
=
"(###) ###-####"
ShowButton
=
"true"
ButtonCssClass
=
"textboxclear"
TabIndex
=
"4"
>
<
ClientEvents
OnButtonClick
=
"ClearInput"
/>
</
telerik:RadMaskedTextBox
>
</
td
>
<
td
class
=
"tablevalidator"
>
<%--<
asp:RequiredFieldValidator
Display
=
"Dynamic"
ID
=
"rfvPhone"
runat
=
"server"
ErrorMessage
=
"Please, enter a phone number."
ControlToValidate
=
"rmtPhone"
CssClass
=
"validation"
></
asp:RequiredFieldValidator
>--%>
<
asp:RegularExpressionValidator
Display
=
"Dynamic"
ID
=
"revPhone"
runat
=
"server"
ErrorMessage
=
"Format is (###) ###-####"
ControlToValidate
=
"rmtPhone"
ValidationExpression
=
"^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$"
CssClass
=
"validation"
/>
</
td
>
</
tr
>
</
table
>
<
br
/>
<
telerik:RadButton
ID
=
"rbtnAcceptNewPatient"
runat
=
"server"
Text
=
"Accept"
OnClientClicking
=
"StandardConfirm"
OnClick
=
"rbtnAcceptNewPatient_Click"
TabIndex
=
"5"
>
<
Icon
PrimaryIconCssClass
=
"rbOk"
PrimaryIconLeft
=
"4"
PrimaryIconTop
=
"4"
/>
</
telerik:RadButton
>
<
telerik:RadButton
ID
=
"rbtnCancelNewPatient"
runat
=
"server"
Text
=
"Cancel"
OnClick
=
"rbtnCancelPatient_Click"
CausesValidation
=
"false"
TabIndex
=
"6"
>
<
Icon
PrimaryIconCssClass
=
"rbCancel"
PrimaryIconLeft
=
"4"
PrimaryIconTop
=
"4"
/>
</
telerik:RadButton
>
</
div
>
</
div
>
</
NoRecordsTemplate
>
and this in the code-behind:
protected
void
rbtnAcceptNewPatient_Click(
object
sender, EventArgs e)
{
Patient pt =
new
Patient();
pt.AddPatient(rtbMRN.Text, TaljacUtilities.NameCapitalization(rtbLastName.Text), TaljacUtilities.NameCapitalization(rtbFirstName.Text), rdpDOB.Value);
}
Thanks!!
Tom Stanley
0
Princy
Top achievements
Rank 2
answered on 04 Jun 2012, 06:10 AM
Hi,
Try the following code snippet to access the other controls in the NoRecordsTemplate on a RadButton Click.
C#:
Note: Please set the CausesValidation property of RadButton to "false". Check this help documentation for details.
Thanks,
Princy.
Try the following code snippet to access the other controls in the NoRecordsTemplate on a RadButton Click.
C#:
protected
void
rbtnAcceptNewPatient_Click(
object
sender, EventArgs e)
{
RadButton Button = (RadButton)sender;
GridNoRecordsItem item = (GridNoRecordsItem)Button.NamingContainer;
RadTextBox txtbox = (RadTextBox)item.FindControl(
"rtbLastName"
);
// accessing the RadTextBox
}
Note: Please set the CausesValidation property of RadButton to "false". Check this help documentation for details.
Thanks,
Princy.