<telerik:RadGrid ID="RadGrid2" runat="server" AllowMultiRowSelection="true" Width="300px"OnNeedDataSource="RadGrid2_NeedDataSource"> <MasterTableView AutoGenerateColumns="False" DataKeyNames="codigo" EditMode="InPlace"> <Columns> <telerik:GridTemplateColumn> <ItemTemplate> <asp:CheckBox runat="server" ID="CheckBox1" /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridBoundColumn HeaderText="Código" DataField="codigo" UniqueName="codigo" ReadOnly="True" Display="true" ColumnEditorID="GridTextBoxColumnEditor1" /> <telerik:GridBoundColumn HeaderText="Descrição" DataField="descricao" UniqueName="descricao" ColumnEditorID="GridTextBoxColumnEditor1" /> <telerik:GridEditCommandColumn ButtonType="ImageButton"> </telerik:GridEditCommandColumn> </Columns> </MasterTableView> <ClientSettings> <ClientEvents OnRowDblClick="RowDblClick" /> </ClientSettings> </telerik:RadGrid> <telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor1" runat="server" TextBoxStyle-Width="180px" /> <asp:Button ID="btnDeletar" runat="server" Text="Deletar Items" OnClick="btnDeletar_Click" /> <asp:Button ID="btnInserir" runat="server" Text="Inserir Items" OnClick="btnInserir_Click" /> <asp:Button ID="btnEditar" runat="server" Text="Editar Items" OnClick="btnEditar_Click" /> <telerik:RadWindowManager ID="Window" runat="server" EnableShadow="true" />protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e){ // Atribui dados a grid. RadGrid2.DataSource = this.GridSource; this.GridSource.PrimaryKey = new DataColumn[] { this.GridSource.Columns["codigo"] };}/// <summary>/// Obtem a source do grid./// </summary>private DataTable GridSource{ get { object obj = ViewState["GRID"]; if ((!(obj == null))) { return ((DataTable)(obj)); } DataTable myDataTable = new DataTable(); myDataTable = Preenche(); ViewState["GRID"] = myDataTable; return myDataTable; }}/// <summary>/// Obtem data table com dados para grid./// </summary>/// <returns>Retorna datatable</returns>public DataTable Preenche(){ C001 c001 = new C001(); DataTable dt = new DataTable(); dt = c001.ObterDados(); return dt;}Hi,
I have a RadGrid that contains two GridButtonColumns of HeaderButtonType LinkButton. I would like to control the behavior to dynamically hide one column and show the other and vice versa.
In addition, in one of the circumstances there is an additional GridBoundColumn that I would like to hide.
How do I do this? Also, can I do it in the ItemDataBound method or does it need to be done in a PreRender method?
In the Grid below, I want to show the RequestorName and RequestorPd columns and hide the InstitutionName column in one case and in the other I want to show the InstitutionName column and hide the RequestorName and RequestorPd columns.
<telerik:RadGrid ID="RadGridPrescriber" runat="server" AutoGenerateColumns="false" AllowSorting="True" AllowPaging="false" Skin="Simple" ClientSettings-Resizing-AllowColumnResize="true" ItemStyle-Wrap="false" Width="95%" HeaderStyle-Wrap="false" PageSize="25" OnNeedDataSource="RadGridPrescriber_NeedDataSource" OnItemDataBound="RadGridPrescriber_ItemDataBound" OnItemCommand="RadGridPrescriber_ItemCommand"> <ClientSettings> <Scrolling AllowScroll="true" UseStaticHeaders="true" /> </ClientSettings> <ExportSettings ExportOnlyData="false" IgnorePaging="true" OpenInNewWindow="true" /> <MasterTableView TableLayout="Fixed" AllowMultiColumnSorting="true" DataKeyNames="RequestorSln" ShowFooter="false" PagerStyle-AlwaysVisible="false" CommandItemDisplay="Top" > <NoRecordsTemplate> <asp:Label ID="lblMsg" runat="server" Text="No Records found"></asp:Label> </NoRecordsTemplate> <CommandItemSettings ShowExportToPdfButton="true" ShowExportToCsvButton="true" ShowExportToExcelButton="true" ShowRefreshButton="false" ShowAddNewRecordButton="false" /> <Columns> <telerik:GridButtonColumn HeaderText="Name" HeaderButtonType="LinkButton" UniqueName="RequestorName" CommandName="GetByRequestorSLN" DataTextField="RequestorName" ItemStyle-HorizontalAlign="Left" /> <telerik:GridButtonColumn HeaderText="Name" HeaderButtonType="LinkButton" UniqueName="InstitutionName" CommandName="GetByRequestorSLN" DataTextField="InstitutionName" ItemStyle-HorizontalAlign="Left" /> <telerik:GridBoundColumn HeaderText="PD" HeaderButtonType="TextButton" DataField="RequestorPd" ItemStyle-HorizontalAlign="Left" /> </Columns> </MasterTableView> </telerik:RadGrid>
Thanks,
ClientIDMode="AutoID"
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"></asp:Content><asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <div> <telerik:RadScriptManager ID="RadScriptManager1" runat="server"> </telerik:RadScriptManager> <telerik:RadComboBox runat="server" ID="RadComboBox1" Height="100px" EnableLoadOnDemand="true" ShowMoreResultsBox="true" EnableVirtualScrolling="true" EmptyMessage="Type here ..."> <WebServiceSettings Path="~/ComboBoxWcfService.svc" Method="LoadData" /> </telerik:RadComboBox> </div> <asp:LinqDataSource ID="LinqDataSource1" runat="server"></asp:LinqDataSource></asp:Content>
WCF code:
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ComboBoxWcfService {
public void DoWork()
{
}
[OperationContract]
public RadComboBoxData LoadData(RadComboBoxContext context)
{
//The RadComboBoxData object contains all required information for load on demand:
// - the items
// - are there more items in case of paging
// - status message to be displayed (which is optional)
AdventureWorksDataContext northwind = new AdventureWorksDataContext();
RadComboBoxData result = new RadComboBoxData();
//Get all items from the Customers table. This query will not be executed untill the ToArray method is called.
var allCustomers = from customer in northwind.Customers
orderby customer.ContactName
select new RadComboBoxItemData
{
Text = customer.ContactName
};
//In case the user typed something - filter the result set
string text = context.Text;
if (!String.IsNullOrEmpty(text))
{
allCustomers = allCustomers.Where(item => item.Text.StartsWith(text));
}
//Perform the paging
// - first skip the amount of items already populated
// - take the next 10 items
int numberOfItems = context.NumberOfItems;
var customers = allCustomers.Skip(numberOfItems).Take(10);
//This will execute the database query and return the data as an array of RadComboBoxItemData objects
result.Items = customers.ToArray();
int endOffset = numberOfItems + customers.Count();
int totalCount = allCustomers.Count();
//Check if all items are populated (this is the last page)
if (endOffset == totalCount)
result.EndOfItems = true;
//Initialize the status message
result.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>",
endOffset, totalCount);
return result;
}
}
WebConfig:
<service behaviorConfiguration="metadataAndDebug" name="WebApplication1.ComboBoxWcfService">
<endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding"
contract="WebApplication1.ComboBoxWcfService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
We are using "RadInput.Net2.dll" and RadMaskedTextBox for phone number. For validating phone number format as (###) ###-####, we are using RegularExpressionValidator.
Below is the code we used
<radI:RadMaskedTextBox ID="txtPhone" runat="server"></radI:RadMaskedTextBox><br />
<asp:RegularExpressionValidator ID="revOtherPhone" Display="dynamic" ControlToValidate="txtPhone" ValidationExpression ="^(\([0-9]\d{2}\)|[0-9]\d{2})[- .]?\d{3}[- .]?\d{4}$" ToolTip="Input other phone" ErrorMessage="Enter the correct phone number." runat="server"></asp:RegularExpressionValidator>
The functionality is working fine OnKeyPress event.
But we do not want to display the error message on every key press. We want to display the error message only on tab / mouse out from text box like demo available in "http://demos.telerik.com/aspnet-ajax/input/examples/common/validation/defaultcs.aspx"
But we have used the same code as mentioned in the demo source code. But we are getting the validation message at every key press event instead of tab out.
Iwe could not find out where the RegularExpressionValidator validation event is setup for RadMaskedTextBox key press. Could you please help me to fix this issue?
Thanks in advance.
We are using "RadInput.Net2.dll" and RadMaskedTextBox for phone number. We want to check if first character of area code should not be 0 or 1.
If we use CustomValidator and javascript as below, it is working fine.
For example, if phone # is "(316) 446-2777" and if I replace 3 as 1, I could see the correct error message. But if I delete 3, I can see numbers in text box as "(_16) 446-2777". But still I can see the error message as "This number cannot begin with a 1 or 0.". The prompt character is not part of the args.value.
I want to display the error message only if first character after ( is 0 or 1. Could you please help us to find out the first character only of the input text
Thanks in advance.
<radI:RadMaskedTextBox ID="txtPhone" runat="server"> </radI:RadMaskedTextBox><br /> <asp:CustomValidator id="revBusinessPhone" Display="dynamic" runat = "server" ControlToValidate="txtPhone" ErrorMessage = "This number cannot begin with a 1 or 0." ClientValidationFunction ="validateLength" ></asp:CustomValidator> function validateLength(oSrc, args) { var phnVal = args.Value; if (((phnVal1.substring(0, 2)) == "(1" || (phnVal.substring(0, 2) == "(0"))) { oSrc.innerText = "This number cannot begin with a 1 or 0."; args.IsValid = false; } else { var regex = /^(\([0-9]\d{2}\)|[0-9]\d{2})[- .]?\d{3}[- .]?\d{4}$/; if (regex.test(phnVal)) { args.IsValid = true; } else { oSrc.innerText = "This number must contain 10 digits."; args.IsValid = false; } } return true; }