I have a radGrid with Add a Record turned on and the edit is turned on for each row. How do I validate in the code behind if the user selected Add a Record or Edit an Existing?
I have a drop down list in the Insert and Edit modes. If the user selects add a new record, I want to populate the drop dwon list with all the values and the first one should be selected. If the user selects edit a record, I want the current value to display. I am getting the latter one to work.
| Protected Sub RadGrid1_EditCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.EditCommand |
| editSelected = True |
| Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem) |
| Dim statusLabel As Label |
| statusLabel = item.FindControl("lblStatus") |
| Session("updatedStatusValue") = statusLabel.Text.ToString() |
| Dim priorityLabel As Label |
| priorityLabel = item.FindControl("lblPriorityDesc") |
| Session("updatedPriorityValue") = priorityLabel.Text.ToString() |
| End Sub |
| Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound |
| If "matter".Equals(e.Item.OwnerTableView.Name) Then |
| If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then |
| Dim item As GridEditableItem = e.Item |
| Dim ddlStatusList As DropDownList = item.FindControl("ddlStatus") |
| ddlStatusList.DataSource = GetStatusList() |
| ddlStatusList.DataBind() |
| If (Not Session("updatedStatusValue") Is Nothing) Or editSelected Then |
| For Each ddlItems As ListItem In ddlStatusList.Items |
| If ddlItems.Text = Session("updatedStatusValue") And editSelected Then |
| ddlStatusList.SelectedValue = ddlItems.Value |
| End If |
| Next |
| Else |
| ddlStatusList.SelectedValue = 1 |
| End If |
| Dim ddlPriorityList As DropDownList = item.FindControl("ddlPriorityDesc") |
| ddlPriorityList.DataSource = GetPriorityList() |
| ddlPriorityList.DataBind() |
| If (Not Session("updatedPriorityValue") Is Nothing) Or editSelected Then |
| For Each ddlItems As ListItem In ddlPriorityList.Items |
| If ddlItems.Text = Session("updatedPriorityValue") And editSelected Then |
| ddlPriorityList.SelectedValue = ddlItems.Value |
| End If |
| Next |
| Else |
| ddlPriorityList.SelectedValue = 1 |
| End If |
| End If |
| End If |
| End Sub |
Thanks,
Randy
I have a program that needs to call ajaxRequest from client side.
When I use this code in any aspx page, it works fine.
But when I put it into a DNN module,the $find method always return null.
Is there any difference in DNN module?
| var ajaxManager = null; |
| function pageLoad() { |
| if (ajaxManager == null) { |
| ajaxManager = $find("<%= RadAjaxManager1.ClientID %>"); |
| } |
| } |
| function SuccessHandler(privateToken, alias, message) { |
| var datetime = new Date(); |
| ajaxManager.ajaxRequest("(" + datetime.toLocaleTimeString() + ")"); |
| } |
| <telerik:RadComboBox ID="market" Runat="server" Width="205px" DataSourceID="market_ds" DataTextField="Code" DataValueField="MainCodeID"> |
| <Items> |
| <telerik:RadComboBoxItem runat="server" Text="-- all --" Value="all" Selected="true"/> |
| </Items> |
| </telerik:RadComboBox> |
| <telerik:RadGrid ID="RadGridCV" runat="server" Skin="Office2007" GridLines="None" Width="98%" AllowMultiRowSelection="True" AllowMultiRowEdit="True"> |
| <MasterTableView AutoGenerateColumns="False" DataKeyNames="Person_Id" Width="100%" EditMode="InPlace"> |
| <Columns> |
| <telerik:GridBoundColumn DataField="Person_Id" SortExpression="Person_Id" ReadOnly="True" UniqueName="Person_Id" Visible="False"></telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Person_FirstNameEng" HeaderText="First Name" ReadOnly="True" SortExpression="Person_FirstNameEng" UniqueName="Person_FirstNameEng"> |
| <ItemStyle VerticalAlign="Top" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Person_LastNameEng" HeaderText="Last Name" ReadOnly="True" SortExpression="Person_LastNameEng" UniqueName="Person_LastNameEng"> |
| <ItemStyle VerticalAlign="Top" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridTemplateColumn UniqueName="ListOfPublicationsFile" HeaderText="List Of Publications File" DefaultInsertValue=""> |
| <ItemTemplate> |
| <asp:Label ID="Label1" runat="server" Text='<%#Bind("ListOfPublicationsFile") %>'></asp:Label> |
| </ItemTemplate> |
| <EditItemTemplate><asp:FileUpload ID="FileUploadListOfPublications" runat="server" /></EditItemTemplate> |
| <ItemStyle VerticalAlign="Top" /> |
| </telerik:GridTemplateColumn> |
| <telerik:GridEditCommandColumn><ItemStyle ForeColor="Green" VerticalAlign="Top" /></telerik:GridEditCommandColumn> |
| </Columns> |
| <DetailTables> |
| <telerik:GridTableView Enabled="false" Name="AcademiclBackground" EditMode="InPlace" CommandItemDisplay="Bottom" runat="server" Caption="A. Academic Background" Width="100%" AutoGenerateColumns="False" DataKeyNames="ACBG_ItemNum"> |
| <ParentTableRelation> |
| <telerik:GridRelationFields |
| DetailKeyField="ACBG_PersonId" |
| MasterKeyField="Person_Id" /> |
| </ParentTableRelation> |
| <Columns> |
| <telerik:GridBoundColumn DataField="ACBG_OrderBy" ColumnEditorID="myTextBoxEditor30px" HeaderText="Row No." SortExpression="ACBG_OrderBy" UniqueName="ACBG_OrderBy"> |
| <ItemStyle Width="30px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="ACBG_FromTo" ColumnEditorID="myTextBoxEditor70px" HeaderText="Date From To" SortExpression="ACBG_FromTo" UniqueName="ACBG_FromTo"> |
| <ItemStyle Width="80px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="ACBG_Institute" ColumnEditorID="myTextBoxEditor130px" HeaderText="Institute" SortExpression="ACBG_Institute" UniqueName="ACBG_Institute"> |
| <ItemStyle Width="150px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="ACBG_Degree" ColumnEditorID="myTextBoxEditor50px" HeaderText="Degree" SortExpression="ACBG_Degree" UniqueName="ACBG_Degree"> |
| <ItemStyle Width="60px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="ACBG_Area" ColumnEditorID="myTextBoxEditor100px" HeaderText="Area" SortExpression="ACBG_Area" UniqueName="ACBG_Area"> |
| <ItemStyle Width="120px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridEditCommandColumn ButtonType="ImageButton" CancelImageUrl="~/Images/cancel.gif" |
| EditImageUrl="~/Images/edit.gif" InsertImageUrl="~/Images/update.gif" UpdateImageUrl="~/Images/update.gif"><ItemStyle ForeColor="#007E00" /></telerik:GridEditCommandColumn> |
| <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="column" ButtonType="ImageButton" ImageUrl="~/Images/delete.gif"><ItemStyle ForeColor="#E40000" /></telerik:GridButtonColumn> |
| </Columns> |
| <CommandItemSettings AddNewRecordText="Add Academic Background Item" /> |
| <EditFormSettings><EditColumn UniqueName="EditCommandColumn1"></EditColumn></EditFormSettings> |
| </telerik:GridTableView> |
| <telerik:GridTableView Name="PreviousEmployment" EditMode="InPlace" CommandItemDisplay="Bottom" runat="server" Caption="B. Previous Employment<br/><span class=HeaderText>Begin with present position (do not include tutoring, memberships in scientific associations or guest lectures)</span>" Width="100%" AutoGenerateColumns="False" DataKeyNames="PE_ItemNum" AllowPaging="True"> |
| <ParentTableRelation> |
| <telerik:GridRelationFields |
| DetailKeyField="PE_PersonId" |
| MasterKeyField="Person_Id" /> |
| </ParentTableRelation> |
| <Columns> |
| <telerik:GridBoundColumn DataField="PE_OrderBy" ColumnEditorID="myTextBoxEditor30px" HeaderText="Row No." SortExpression="PE_OrderBy" UniqueName="PE_OrderBy"> |
| <ItemStyle Width="30px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="PE_FromTo" ColumnEditorID="myTextBoxEditor70px" HeaderText="Date From To" SortExpression="PE_FromTo" UniqueName="PE_FromTo"> |
| <ItemStyle Width="80px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="PE_Institute" ColumnEditorID="myTextBoxEditor130px" HeaderText="Institute" SortExpression="PE_Institute" UniqueName="PE_Institute"> |
| <ItemStyle Width="150px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="PE_Title" ColumnEditorID="myTextBoxEditor50px" HeaderText="Title" SortExpression="PE_Title" UniqueName="PE_Title"> |
| <ItemStyle Width="60px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="PE_Area" ColumnEditorID="myTextBoxEditor100px" HeaderText="Research Area" SortExpression="PE_Area" UniqueName="PE_Area"> |
| <ItemStyle Width="120px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridEditCommandColumn ButtonType="ImageButton" CancelImageUrl="~/Images/cancel.gif" EditImageUrl="~/Images/edit.gif" InsertImageUrl="~/Images/update.gif" UpdateImageUrl="~/Images/update.gif"><ItemStyle ForeColor="#007E00" /></telerik:GridEditCommandColumn> |
| <telerik:GridButtonColumn CommandName="Delete" UniqueName="column" ButtonType="ImageButton" ImageUrl="~/Images/delete.gif"><ItemStyle ForeColor="#E40000" /></telerik:GridButtonColumn> |
| </Columns> |
| <CommandItemSettings AddNewRecordText="Add Previous Employment Item" /> |
| <EditFormSettings> |
| <EditColumn UniqueName="EditCommandColumn1"></EditColumn> |
| </EditFormSettings> |
| </telerik:GridTableView> |
| <telerik:GridTableView Name="GrantsAndAwards" CommandItemDisplay="Bottom" runat="server" Caption="C. Grants and Awards Received Within the Past Five Years<br/><span class=HeaderText>Please indicate the date of receiving the grant/award and the funding period in the comments box.</span>" Width="100%" AutoGenerateColumns="False" DataKeyNames="GAA_Id" AllowPaging="True"> |
| <ParentTableRelation> |
| <telerik:GridRelationFields |
| DetailKeyField="GAA_PersonId" |
| MasterKeyField="Person_Id" /> |
| </ParentTableRelation> |
| <Columns> |
| <telerik:GridBoundColumn DataField="GAA_OrderBy" HeaderText="Row No." SortExpression="GAA_OrderBy" UniqueName="GAA_OrderBy"> |
| <ItemStyle Width="30px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="GAA_ResearchTopics" HeaderText="Research Topics" SortExpression="GAA_ResearchTopics" UniqueName="GAA_ResearchTopics"> |
| <ItemStyle Width="200px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="GAA_FundingAgency" HeaderText="Funding Organization" SortExpression="GAA_FundingAgency" UniqueName="GAA_FundingAgency"> |
| <ItemStyle Width="150px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="GAA_TotalGrant" HeaderText="Total (in $)" SortExpression="GAA_TotalGrant" UniqueName="GAA_TotalGrant"> |
| <HeaderStyle Wrap="False" /> |
| <ItemStyle Wrap="False" Width="60px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridEditCommandColumn ButtonType="ImageButton" CancelImageUrl="~/Images/cancel.gif" EditImageUrl="~/Images/edit.gif" InsertImageUrl="~/Images/update.gif" UpdateImageUrl="~/Images/update.gif"><ItemStyle ForeColor="#007E00" /></telerik:GridEditCommandColumn> |
| <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="column" ButtonType="ImageButton" ImageUrl="~/Images/delete.gif"><ItemStyle ForeColor="#E40000" /></telerik:GridButtonColumn> |
| </Columns> |
| <CommandItemSettings AddNewRecordText="Add Grant and Award Item" /> |
| <EditFormSettings UserControlName="~/Controls/ucGrantsAndAwardsDetails.ascx" EditFormType="WebUserControl"><EditColumn UniqueName="EditCommandColumn1"></EditColumn></EditFormSettings> |
| </telerik:GridTableView> |
| </DetailTables> |
| <ExpandCollapseColumn Visible="True"></ExpandCollapseColumn> |
| <EditFormSettings> |
| <EditColumn UniqueName="EditCommandColumn1"> |
| </EditColumn> |
| </EditFormSettings> |
| </MasterTableView> |
| </telerik:RadGrid> |
Hi,
I have created a grid at runtime and have set properties as follows:
| MainGrid.ClientSettings.AllowKeyboardNavigation = true; |
| MainGrid.ClientSettings.Selecting.AllowRowSelect = true; |
| MainGrid.ClientSettings.ClientEvents.OnRowSelected = "OnRowSelected"; |
| <script type="text/javascript" language="javascript"> |
| function OnRowSelected(sender, args) |
| { |
| //My code |
| } |
| </script> |
this code works perfectly fine when i use 'SPACE' key for selecttion
I dont want 'ENTER' key to get into Edit mode instead what i want is to use 'ENTER' key for selection
What this means is,whatever currently happening using 'SPACE' bar it should happen on pressing 'ENTER' key
Regards,
Mangesh
NeedDataSource event handler.
Other people have run into this issue:
http://www.telerik.com/community/forums/aspnet-ajax/grid/page-count-inaccurate-after-new-search.aspx#0
http://www.telerik.com/community/forums/aspnet-ajax/grid/rebind-not-updating-pager.aspx
However, the suggestion of setting EnableLinqExpressions to false did not work for me. Does anyone have any other suggestions to try? I'm running on .NET 3.5 and using RadControls for ASP.NET AJAX Q3 2009 NET3.5.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SearchPersonControl.ascx.cs" Inherits="SearchPersonControl" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<%@ Register assembly="System.Web.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" namespace="System.Web.UI.WebControls" tagprefix="asp" %>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
<asp:Table ID="tblMainLayout" runat="server">
<asp:TableRow>
<asp:TableCell>
<asp:Label ID="lblPerson" runat="server" Text="Persoon:"></asp:Label>
</asp:TableCell>
<asp:TableCell>
<telerik:RadTextBox ID="txtPersonSearch" Runat="server" Width="200px"></telerik:RadTextBox>
</asp:TableCell>
<asp:TableCell>
<asp:Button ID="btnSearch" runat="server" onclick="btnSearch_Click" Text="Search" />
</asp:TableCell>
<asp:TableCell>
<asp:Button ID="btnAdvancedSearch" runat="server" onclick="btnAdvancedSearch_Click" Text="Show Advanced Search" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="tblrAdvancedSearch1" runat="server" Visible="false">
<asp:TableCell>
<asp:Label ID="lblID" runat="server" Text="ID nummer: "></asp:Label>
</asp:TableCell>
<asp:TableCell>
<telerik:RadTextBox ID="txtID" Runat="server"></telerik:RadTextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="tblrAdvancedSearch2" runat="server" Visible="false">
<asp:TableCell>
<asp:Label ID="lblName" runat="server" Text="Naam:"></asp:Label>
</asp:TableCell>
<asp:TableCell>
<telerik:RadTextBox ID="txtName" Runat="server" Width="200px"></telerik:RadTextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ColumnSpan="4">
<telerik:RadGrid ID="grdPersons" runat="server" AllowPaging="True"
DataSourceID="HECINA_DEV_M_SearchPersonEntities" GridLines="None"
AllowSorting="True" AllowFilteringByColumn = "true" OnNeedDataSource="grdPersons_NeedDataSource"
EnableLinqExpressions="false">
<MasterTableView AutoGenerateColumns="False"
DataSourceID="HECINA_DEV_M_SearchPersonEntities">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<SortExpressions>
<telerik:GridSortExpression FieldName="Persons_FullName" SortOrder="Ascending" />
</SortExpressions>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="Persons_FullName" DefaultInsertValue=""
HeaderText="Naam" ReadOnly="True" SortExpression="Persons_FullName"
UniqueName="Persons_FullName"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Persons_BirthDate"
DataType="System.DateTime" DefaultInsertValue="" HeaderText="Geboortedatum"
ReadOnly="True" SortExpression="Persons_BirthDate"
UniqueName="Persons_BirthDate"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Persons_IdentificationNumber"
DefaultInsertValue="" HeaderText="Identificatienummer" ReadOnly="True"
SortExpression="Persons_IdentificationNumber"
UniqueName="Persons_IdentificationNumber"></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:EntityDataSource ID="HECINA_DEV_M_SearchPersonEntities" runat="server"
ConnectionString="name=HECINA_DEV_M_SearchPersonEntities"
DefaultContainerName="HECINA_DEV_M_SearchPersonEntities"
EntitySetName="Persons" EntityTypeFilter="Persons"
Select="it.[Persons_BirthDate], it.[Persons_FullName], it.[Persons_IdentificationNumber]">
</asp:EntityDataSource>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CX.Hecina.DataAccessLayer;
public partial class SearchPersonControl : System.Web.UI.UserControl
{
HECINA_DEV_M_SearchPersonEntities searchPersonEntities;
protected void Page_Load(object sender, EventArgs e)
{
this.searchPersonEntities = new HECINA_DEV_M_SearchPersonEntities();
}
protected void btnSearch_Click(object sender, EventArgs e)
{
//Only one of these can be set. Always clear both to ensure the data grid is current.
this.grdPersons.DataSourceID = null;
this.grdPersons.DataSource = null;
this.grdPersons.CurrentPageIndex = 0;
this.grdPersons.Rebind();
}
protected void grdPersons_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
//Always default to the full data set. This is useful if no search terms were specified.
IQueryable<Persons> qry = this.searchPersonEntities.Persons.OrderBy(p => p.Persons_FullName);
if (this.txtName.Text.Length != 0)
{
qry = this.searchPersonEntities.Persons.Where(p => p.Persons_FullName.ToUpper().Contains(this.txtName.Text.ToUpper()));
}
if (this.txtID.Text.Length != 0)
{
qry = this.searchPersonEntities.Persons.Where(p => p.Persons_IdentificationNumber.ToUpper().Contains(this.txtID.Text.ToUpper()));
}
//Google-like search that matches on multiple fields simultaneously.
if (this.txtPersonSearch.Text.Length != 0)
{
string searchText = this.txtPersonSearch.Text.ToUpper();
qry = this.searchPersonEntities.Persons.Where(p => p.Persons_FullName.ToUpper().Contains(searchText) ||
//TODO: Figure this out, at runtime an exception is thrown that LINQ does not
//recognize ToShortDateString().
//p.Persons_BirthDate.ToShortDateString().Contains(searchText) ||
p.Persons_IdentificationNumber.ToUpper().Contains(searchText));
}
//TODO: figure out how to update record and page count.
this.grdPersons.DataSource = qry;
}
protected void btnAdvancedSearch_Click(object sender, EventArgs e)
{
//Simply invert the visibility property value of the advanced search fields.
this.tblrAdvancedSearch1.Visible ^= true;
this.tblrAdvancedSearch2.Visible ^= true;
if (this.tblrAdvancedSearch1.Visible == true)
{
this.btnAdvancedSearch.Text = "Hide Advanced Search";
}
else
{
this.btnAdvancedSearch.Text = "Show Advanced Search";
}
}
}
The only thing I could think I'm doing differently is that I'm using the grid inside a user control.