Tuesday, December 20, 2011

Getting started with RadDesktopAlert

Problem: Is there any thing in which a pop-up or alert appears from the bottom of screen.
Solution: Telerik has a solution for this,use RadDesktopAlert.

To see video Click the following link.
http://tv.telerik.com/watch/winforms/getting-started-with-raddesktopalert

How to disable filter button in RadGridView in Winforms

Problem: I am setting the properties of RadGridView in Winforms like Header of column and filter to disable but they are not working.
Solution: This is a bug in current version of Telerik. and hope it iwll be resolved in next version but you can do this by coding.
for example:
VB Code:
RadGridView1.MasterTemplate.AllowDeleteRow = False
RadGridView1.MasterTemplate.AllowEditRow = False
RadGridView1.MasterTemplate.AllowAddNewRow = False
RadGridView1.MasterTemplate.EnableGrouping = False
RadGridView1.MasterTemplate.ShowRowHeaderColumn = False
C# Code:
RadGridView1.MasterTemplate.AllowDeleteRow = false;
RadGridView1.MasterTemplate.AllowEditRow = false;
RadGridView1.MasterTemplate.AllowAddNewRow = false;
RadGridView1.MasterTemplate.EnableGrouping = false;
RadGridView1.MasterTemplate.ShowRowHeaderColumn = false;

Thursday, December 15, 2011

How to show Desktop Alert (RadDesktopAlert)

Problem: How to show desktop alert or a pop-up in desktop which comes from the bottom of screen.
Solution: Drag and drop RadDesktopAlert control from toolbox.It will appear in bottom of form.

You can set its properties from the properties window and see its preview.
Now the code is really simple, I am using a simple button to demonstrate it.Desktop alert is shown at the OnClick event of this button.

VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        RadDesktopAlert1.ContentText = "Hello World"
        RadDesktopAlert1.Show()

End Sub

Wednesday, December 7, 2011

Calculate the GCD

Problem: Calculate the GCD of Three, Four, or Five Integers. (Vb.Net ,C #)

Solution:

GCD of Two Numbers:
GCD(a,b)
Algorithm
Step 1: a modulus b = r (remainder)  If r Not Equal To Zero i.e i < > 0
Then
Step 2: a: =b and b : = r
Repeat Step 1 Till R become Zero i.e i := 0
Step 3:
GCD is b
Stop


VB Code:
 Module Module1
      Sub Main()
   Dim FirstNumber As Integer
        Dim SecondNumber As Integer
        FirstNumber = Console.ReadLine()
        SecondNumber = Console.ReadLine()
        If FirstNumber < SecondNumber Then
            Dim Temp As Integer
            Temp = SecondNumber
            SecondNumber = FirstNumber
            FirstNumber = Temp
        End If
        Dim NewMod As Integer
        Dim GCD As Integer
        NewMod = FirstNumber Mod SecondNumber
        While (NewMod > 0)
            FirstNumber = SecondNumber
            SecondNumber = NewMod
            NewMod = FirstNumber Mod SecondNumber
  End While
        GCD = SecondNumber
 Console.WriteLine(GCD)
Console.ReadLine()
    End Sub
End Module


For C# Code Convert It From 
http://www.developerfusion.com/tools/convert/vb-to-csharp/

GCD Of Three Numbers:

GCD(a,b,c)=GCD(a,GCD(b,c))






VB Code:
Module Module1
    Sub Main()
        Dim FirstNumber As Integer
        Dim SecondNumber As Integer
        Dim ThirdNumber As Integer
        FirstNumber = Console.ReadLine()
        SecondNumber = Console.ReadLine()
        ThirdNumber = Console.ReadLine()
        ' For GCD(a,b)
        If FirstNumber < SecondNumber Then
            Dim Temp As Integer
            Temp = SecondNumber
            SecondNumber = FirstNumber
            FirstNumber = Temp
        End If
        Dim NewMod As Integer
        Dim GCD As Integer
        NewMod = FirstNumber Mod SecondNumber
        While (NewMod > 0)
            FirstNumber = SecondNumber
            SecondNumber = NewMod
            NewMod = FirstNumber Mod SecondNumber
 End While
        GCD = SecondNumber
        'Now For GCD(GCD(a,b),c)
        FirstNumber = GCD
        SecondNumber = ThirdNumber
        If FirstNumber < SecondNumber Then
            Dim Temp As Integer
            Temp = SecondNumber
            SecondNumber = FirstNumber
            FirstNumber = Temp
        End If
     
        NewMod = FirstNumber Mod SecondNumber
        While (NewMod > 0)
            FirstNumber = SecondNumber
            SecondNumber = NewMod
            NewMod = FirstNumber Mod SecondNumber 

         End While
        GCD = SecondNumber
        Console.WriteLine(GCD) ' GCD Of a,b,c
        Console.ReadLine()
    End Sub
End Module

 For C# Code Convert It From 
http://www.developerfusion.com/tools/convert/vb-to-csharp/
The Code Will Become Easy If Using Function And Can perform two three and four by a little modification.

VB Code:
Module Module1
    Public Freinds() As String
    Dim COUNT As Integer
    Sub Main()
    Dim FirstNumber As Integer
        Dim SecondNumber As Integer
        Dim ThirdNumber As Integer
        FirstNumber = Console.ReadLine()
        SecondNumber = Console.ReadLine()
        ThirdNumber = Console.ReadLine()
        Dim GCD As Integer
        GCD = GetGCD(FirstNumber, SecondNumber)
        Console.WriteLine(GCD)
        FirstNumber = GCD
        SecondNumber = ThirdNumber
        GCD = GetGCD(FirstNumber, SecondNumber)
     Console.ReadLine()
    End Sub
    Private Function GetGCD(ByVal Firstnumber As Integer, ByVal SecondNumber As Integer) As Integer
        If Firstnumber < SecondNumber Then
            Dim Temp As Integer
            Temp = SecondNumber
            SecondNumber = Firstnumber
            Firstnumber = Temp
        End If
        Dim NewMod As Integer
        Dim GCD As Integer
        NewMod = Firstnumber Mod SecondNumber
        While (NewMod > 0)
            Firstnumber = SecondNumber
            SecondNumber = NewMod
            NewMod = Firstnumber Mod SecondNumber 

        End While
        Return SecondNumber
    End Function
End Module 

Friday, November 25, 2011

RadImage in RadGrid

Problem: How to bind and insert a RadImage in RadGrid  From Server Side using RadAsyncUpload.

Solution:
Here Is The Sample Code.
ASPX

<%@ Page Title="Home Page" Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
    Inherits="_Default" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
</head>
<body class="BODY">
    <form id="form1" runat="server">
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server">
    </telerik:RadStyleSheetManager>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            var uploadedFilesCount = 0;
            var isEditMode;
            function validateRadUpload(source, e) {
                debugger;
                if (isEditMode == null || isEditMode == undefined) {
                    e.IsValid = false;

                    if (uploadedFilesCount > 0) {
                        e.IsValid = true;
                    }
                }
                isEditMode = null;
            }

            function OnClientFileUploaded(sender, eventArgs) {
                uploadedFilesCount++;
            }
            function conditionalPostback(sender, eventArgs) {
                var theRegexp = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig");
                if (eventArgs.get_eventTarget().match(theRegexp)) {
                    var upload = $find(window['UploadId']);

                    //AJAX is disabled only if file is selected for upload
                    if (upload.getFileInputs()[0].value != "") {
                        eventArgs.set_enableAjax(false);
                    }
                }
            }
       
        </script>
    </telerik:RadCodeBlock>
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        </Scripts>
    </telerik:RadScriptManager>
    <table width="100%">
        <tr>
            <td>
            </td>
        </tr>
        <tr>
            <td align="center" width="90%">
                <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                    <AjaxSettings>
                        <telerik:AjaxSetting AjaxControlID="RadGrid1">
                            <UpdatedControls>
                                <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                            </UpdatedControls>
                        </telerik:AjaxSetting>
                    </AjaxSettings>
                </telerik:RadAjaxManager>
                <telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
                    CellSpacing="0" GridLines="None" OnInsertCommand="RadGrid1_InsertCommand" OnItemCreated="RadGrid1_ItemCreated"
                    OnNeedDataSource="RadGrid1_NeedDataSource" PageSize="3" ShowStatusBar="True"
                    Skin="Web20" Width="900px">
                    <PagerStyle AlwaysVisible="true" Mode="NumericPages" />
                    <MasterTableView CommandItemDisplay="Top" Width="900px">
                        <Columns>
                            <telerik:GridTemplateColumn HeaderStyle-Width="190px" HeaderText="Image Name" SortExpression="Name"
                                UniqueName="ImageName">
                                <ItemTemplate>
                                    <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>' />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadTextBox ID="txbName" runat="server" Text='<%# Eval("Name") %>' Width="190px" />
                                    <asp:RequiredFieldValidator ID="Requiredfieldvalidator1" runat="server" ControlToValidate="txbName"
                                        Display="Dynamic" ErrorMessage="Please, enter a name!" SetFocusOnError="true" />
                                </EditItemTemplate>
                                <HeaderStyle Width="190px" />
                                <ItemStyle VerticalAlign="Top" Width="190px" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn DataField="Description" HeaderStyle-Width="200px" HeaderText="Description"
                                UniqueName="Description">
                                <ItemTemplate>
                                    <telerik:RadTextBox ID="lblDescription" runat="server" BorderColor="White" Height="60px"
                                        ReadOnly="true" Text='<%# TrimDescription(DirectCast(IIF(Eval("Description") IsNot DBNull.Value,Eval("Description"),string.Empty),String)) %>'
                                        TextMode="MultiLine" Width="200px" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadTextBox ID="txbDescription" runat="server" Height="60px" Text='<%# Eval("Description") %>'
                                        TextMode="MultiLine" Width="180px" />
                                </EditItemTemplate>
                                <HeaderStyle Width="200px" />
                                <ItemStyle VerticalAlign="Top" Width="180px" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderStyle-Width="220px" ItemStyle-Width="220px" HeaderText="Image"
                                UniqueName="Upload">
                                <ItemTemplate>
                                    <telerik:RadBinaryImage ID="RadBinaryImage1" runat="server" AlternateText='<%#Eval("Name", "Photo of {0}") %>'
                                        AutoAdjustImageControlSize="false" DataValue='<%#Eval("Image") %>' Height="140px"
                                        ToolTip='<%#Eval("Name", "Photo of {0}") %>' Width="220px" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadAsyncUpload ID="AsyncUpload1" runat="server" AllowedFileExtensions="jpg,jpeg,png,gif"
                                        MaxFileSize="5048576" OnClientFileUploaded="OnClientFileUploaded" OnValidatingFile="RadAsyncUpload1_ValidatingFile">
                                    </telerik:RadAsyncUpload>
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                        </Columns>
                        <EditFormSettings>
                            <EditColumn ButtonType="ImageButton" />
                        </EditFormSettings>
                        <PagerStyle AlwaysVisible="True" />
                    </MasterTableView>
                    <FilterMenu EnableImageSprites="False">
                    </FilterMenu>
                    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Web20">
                    </HeaderContextMenu>
                </telerik:RadGrid>
            </td>
        </tr>
    </table>
</body>
</form>
</html>

VB Code.
Imports System.Data
Imports Telerik.Web.UI
Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page 
Const MaxTotalBytes As Integer = 1024 ' 1 MB
    Dim totalBytes As Integer
    Dim ConnString As String = "data source=localDataSource;Initial Catalog=database;User Id=User;Password=*****;"

    Dim sqlconn As New SqlConnection(ConnString)


    Public Property IsRadAsyncValid() As System.Nullable(Of Boolean)
        Get
            If Session("IsRadAsyncValid") Is Nothing Then
                Session("IsRadAsyncValid") = True
            End If

            Return Convert.ToBoolean(Session("IsRadAsyncValid").ToString())
        End Get
        Set(ByVal value As System.Nullable(Of Boolean))
            Session("IsRadAsyncValid") = value
        End Set
    End Property
    Protected Function TrimDescription(ByVal description As String) As String
        If Not String.IsNullOrEmpty(description) AndAlso description.Length > 200 Then
            Return String.Concat(description.Substring(0, 200), "...")
        End If
        Return description
    End Function

 
    Protected Sub RadGrid1_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs)
        If Not IsRadAsyncValid.Value Then
            e.Canceled = True
            RadAjaxManager1.Alert("The length of the uploaded file must be less than 1 MB")
            Return
        End If

        Dim insertItem As GridEditFormInsertItem = TryCast(e.Item, GridEditFormInsertItem)
        Dim imageName As String = TryCast(insertItem("ImageName").FindControl("txbName"), RadTextBox).Text
        Dim description As String = TryCast(insertItem("Description").FindControl("txbDescription"), RadTextBox).Text
        Dim radAsyncUpload As RadAsyncUpload = TryCast(insertItem("Upload").FindControl("AsyncUpload1"), RadAsyncUpload)

        Dim file As UploadedFile = radAsyncUpload.UploadedFiles(0)
        Dim fileData As Byte() = New Byte(file.InputStream.Length - 1) {}
        file.InputStream.Read(fileData, 0, CInt(file.InputStream.Length))
        sqlconn.Open()
        Dim Insert As New SqlCommand("Insert into [Test1].[dbo].[Test_Img] ([ImageID],[Name],[Description],[Image]) values ('3','" + imageName + "','" + description + "',  @image  )", sqlconn)
        Dim imageParam As SqlParameter = Insert.Parameters.Add("@image", SqlDbType.Image)
        imageParam.Value = fileData
        imageParam.Size = fileData.Length
        Insert.ExecuteNonQuery()
        sqlconn.Close()

      End Sub

    Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource

        Dim SqlCommand As New SqlCommand("Select [ImageID],[Image],[Name],[Description] from [Test1].[dbo].[Test_Img]", sqlconn)
        sqlconn.Open()
        Dim sqladap As New SqlDataAdapter
        sqladap.SelectCommand = SqlCommand
        Dim ds As New DataSet
        sqladap.Fill(ds, "ImageSet")

        RadGrid1.DataSource = ds.Tables(0)
        sqlconn.Close()

    End Sub

    Public Sub RadAsyncUpload1_ValidatingFile(ByVal sender As Object, ByVal e As Telerik.Web.UI.Upload.ValidateFileEventArgs)
        If (totalBytes < MaxTotalBytes) AndAlso (e.UploadedFile.ContentLength < MaxTotalBytes) Then
            e.IsValid = True
            totalBytes += e.UploadedFile.ContentLength
            IsRadAsyncValid = True
        Else
            e.IsValid = False
            IsRadAsyncValid = False
        End If
    End Sub
    Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs)
        If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
            Dim upload As RadAsyncUpload = TryCast(DirectCast(e.Item, GridEditableItem)("Upload").FindControl("AsyncUpload1"), RadAsyncUpload)
            Dim cell As TableCell = DirectCast(upload.Parent, TableCell)

            Dim validator As New CustomValidator()
            validator.ErrorMessage = "Please select file to be uploaded"
            validator.ClientValidationFunction = "validateRadUpload"
            validator.Display = ValidatorDisplay.Dynamic
            cell.Controls.Add(validator)
        End If

    End Sub
End Class

C# Code.
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using Telerik.Web.UI;
using System.Data.SqlClient;
partial class _Default : System.Web.UI.Page
{

  // 1 MB
 const int MaxTotalBytes = 1024;
 int totalBytes;

 string ConnString = "data source=localDataSource;Initial Catalog=database;User Id=User;Password=*****;";

 SqlConnection sqlconn = new SqlConnection(ConnString);

 public System.Nullable<bool> IsRadAsyncValid {
  get {
   if (Session["IsRadAsyncValid"] == null) {
    Session["IsRadAsyncValid"] = true;
   }

   return Convert.ToBoolean(Session["IsRadAsyncValid"].ToString());
  }
  set { Session["IsRadAsyncValid"] = value; }
 }
 protected string TrimDescription(string description)
 {
  if (!string.IsNullOrEmpty(description) && description.Length > 200) {
   return string.Concat(description.Substring(0, 200), "...");
  }
  return description;
 }


 protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
 {
  if (!IsRadAsyncValid.Value) {
   e.Canceled = true;
   RadAjaxManager1.Alert("The length of the uploaded file must be less than 1 MB");
   return;
  }

  GridEditFormInsertItem insertItem = e.Item as GridEditFormInsertItem;
  string imageName = (insertItem("ImageName").FindControl("txbName") as RadTextBox).Text;
  string description = (insertItem("Description").FindControl("txbDescription") as RadTextBox).Text;
  RadAsyncUpload radAsyncUpload = insertItem("Upload").FindControl("AsyncUpload1") as RadAsyncUpload;

  UploadedFile file = radAsyncUpload.UploadedFiles(0);
  byte[] fileData = new byte[file.InputStream.Length];
  file.InputStream.Read(fileData, 0, Convert.ToInt32(file.InputStream.Length));
  sqlconn.Open();
  SqlCommand Insert = new SqlCommand("Insert into [Test1].[dbo].[Test_Img] ([ImageID],[Name],[Description],[Image]) values ('3','" + imageName + "','" + description + "',  @image  )", sqlconn);
  SqlParameter imageParam = Insert.Parameters.Add("@image", SqlDbType.Image);
  imageParam.Value = fileData;
  imageParam.Size = fileData.Length;
  Insert.ExecuteNonQuery();
  sqlconn.Close();

 }


 protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
 {
  SqlCommand SqlCommand = new SqlCommand("Select [ImageID],[Image],[Name],[Description] from [Test1].[dbo].[Test_Img]", sqlconn);
  sqlconn.Open();
  SqlDataAdapter sqladap = new SqlDataAdapter();
  sqladap.SelectCommand = SqlCommand;
  DataSet ds = new DataSet();
  sqladap.Fill(ds, "ImageSet");

  RadGrid1.DataSource = ds.Tables[0];
  sqlconn.Close();

 }

 public void RadAsyncUpload1_ValidatingFile(object sender, Telerik.Web.UI.Upload.ValidateFileEventArgs e)
 {
  if ((totalBytes < MaxTotalBytes) && (e.UploadedFile.ContentLength < MaxTotalBytes)) {
   e.IsValid = true;
   totalBytes += e.UploadedFile.ContentLength;
   IsRadAsyncValid = true;
  } else {
   e.IsValid = false;
   IsRadAsyncValid = false;
  }
 }
 protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
 {
  if (e.Item is GridEditableItem && e.Item.IsInEditMode) {
   RadAsyncUpload upload = (GridEditableItem)e.Item("Upload").FindControl("AsyncUpload1") as RadAsyncUpload;
   TableCell cell = (TableCell)upload.Parent;

   CustomValidator validator = new CustomValidator();
   validator.ErrorMessage = "Please select file to be uploaded";
   validator.ClientValidationFunction = "validateRadUpload";
   validator.Display = ValidatorDisplay.Dynamic;
   cell.Controls.Add(validator);
  }

 }
}


Thursday, November 24, 2011

Open RadWindow from server side programming


Problem: How to open RadWindow from server side programming
Solution: It is very simple and can be done in following steps,
Step1: Create a ASPX Page which will be open as RadWindow in project e.g "Windowsvb.aspx"
The Page Must Be On Same Directory Where Your Current Page(Calling Rad Window) e.g "Default.aspx" Exist . Not Neccessary But The Code Bellow Work On This Condition

Step2: In Your Current Page "Default.aspx.vb" Write The Function.Given bellow
Protected Sub CreateWindowScript() 
        Dim window1 As New RadWindow()
        window1.NavigateUrl = "Windowsvb.aspx" ' The Path  Be Same As Created In Project
        window1.VisibleOnPageLoad = True
        window1.Width = 950
        window1.Height = 700
        window1.Modal = True
        window1.Behaviors = WindowBehaviors.Close 
        window1.Visible = True
        window1.VisibleOnPageLoad = True
        window1.AutoSize = False
        window1.VisibleStatusbar = True 
        Me.form1.Controls.Add(window1)
End Sub

'You can call this function from any event e.g Click Button Event etc

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        CreateWindowScript()
End Sub


'The DOM Which IS calling This Function Must Not BE In RadAjaxManager OR RadAjaxPanel

Tuesday, November 22, 2011

Server Side Binding Of Telerik RadGrid


Problem: I want To Bind Telerik RadGrid From Server Side.
Solution: Its very ,simple and easy to bind RadGrid from server-side,Use NeedDataSource.NeedDataSource event is called whenever RadGrid is performing some operation like sorting,filtering etc.
Here is the sample code ,hope it works.
ASPX Code:
 <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" >
   <MasterTableView  Width="100%" GridLines="None"  >
 <Columns>
   <telerik:GridTemplateColum  HeaderText="Name"   UniqueName="Name">
             
                 <ItemTemplate>
<asp:Label ID="Name" runat="server" Text='<%# eval("Name") %>'></asp:Label>
  </ItemTemplate>
             </telerik:GridTemplateColumn>
   </Columns>
            </MasterTableView>
     </telerik:RadGrid>

VB Code:
Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
      
Dim Ds as DataSet
Ds=GetDataSETFromDataBase '  Use Function Or Procedure You Use To Fetch Data SET From DataBase
  RadGrid1.DataSource = Ds.Tables(0)

End Sub














Friday, November 18, 2011

RadComboBox not to select any Item on Load

Problem: I am trying to set SelectedIndex to -1 with the objective that I don't any item in the RadCombo to be highlighted. Whilst the debugger passes the line the next statement says SelectedIndex 0.
How to make the RadCombo not to select any particular item automatically?
Solution: To avoid automatic selection of RadComboBox you can try any of the following approaches.
1) Set EmptyMessage property.
or
2) Add an empty text as first RadComboBoxItem.
Here is the sample ASPX,
<telerik:RadComboBox ID="RadComboBox1" runat="server"
            AutoPostBack="true"  Skin="Sunset" EnableAjaxSkinRendering="false"  >
      <Items>
            <telerik:RadComboBoxItem Text="" Value="-1" />
            <telerik:RadComboBoxItem Text="Telerik School Item 1" Value="0"  >
            </telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem Text="Telerik School Item 2" Value="1">
            </telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem Text="Telerik School Item 3" Value="2">
            </telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem Text="Telerik School Item 4" Value="3">
            </telerik:RadComboBoxItem>
     </Items>     
</telerik:RadComboBox>

RadComboBox EnableLoadOnDemand

Problem: I created radcombobox dynamically. I want to add EnableLoadOnDemand functionality from codebehind. I need a sample of code in asp.net having this functionality doing from codebehind.
Solution: To see how RadComboBox is bound to various data sources, you could refer to the DataBinding section of the Combo's online documentation.

To enable the load on demand functionality, you need to set the property LoadOnDemand to true, and subscribe to the OnItemsRequested server-side event, where the items will be populated when they are requested on demand (which happens when the user opens the drop-down list, or type in the input field), as in the code-block below:
protected void Page_Load(object sender, EventArgs e)
{
    RadComboBox combo = new RadComboBox();
    combo.ID = "RadComboBox1";
    combo.EnableLoadOnDemand = true;
    combo.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(combo_ItemsRequested);
    form1.Controls.Add(combo);
}
protected void combo_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    RadComboBox combo = (RadComboBox)sender;
    for (int i = 0; i <= 3; i++)
    {
        combo.Items.Add(new RadComboBoxItem("item_" + i.ToString()));
    }
}

Sunday, November 13, 2011

How to filter record on RadGrid by only one column

Problem: When i set AllowFilteringByColumn property of RadGrid to "True", all columns can be filtered. What i want to do is to filter records by only one column. How can i do that?
Solution: You can set the AllowFitering property for the every column other than the one with which you want to filter the grid to false.

Example:
<radG:GridBoundColumn AllowFiltering="false" DataField="ContactName" UniqueName="BoundColumnUniqueName" HeaderText="ContactName">
</radG:GridBoundColumn>

Friday, November 11, 2011

Remove mouse cursor from RadComboBox

Problem: How to remove the blinking mouse cursor from the RadComboBox ?
Solution: You want to prevent to type in RadComboBox. You could try setting AllowCustomText property of the RadComboBox to false which prevents typing any text in the input of the RadComboBox. Also set the EnableLoadOnDemand and MarkFirstMatch properties to false.

Thursday, November 10, 2011

Label to filter in GridTemlpateColumn

Problem: I want to filter an ASP label
"<asp:Label  runat="server" Text='<%# eval("AnyThing") %>' ></asp:Label>"
in Telerik GridTemplateColumn .Also I dont want Filter Icon to display and I Want "Contains" Filter Function.

Sloution: Just give DataField="DataFieldName" in GridTemplateColumn.The DataField Name which you are using to evaluate Label

Example:
<asp:Label ID="lblName" runat="server" Text='<%# eval("Name")></asp:Label>
Must be given to DataField e.g DataField="Name".
The Green Highlighted Text Is For Filter Icon To Hide and For Filtering With "Contains" 
The Aqua Highlighted  text is For Filtering a String From  Label

Yellow  Is Common For Both

Here Is The Sample Code:


<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"   >
           <MasterTableView  AllowFilteringByColumn="True"  >
                    <Columns>
                             <telerik:GridTemplateColumn AllowFiltering="true"   AutoPostBackOnFilter="true" HeaderText="Name" datafield="Name" DataType="System.String"
ShowFilterIcon="false"   CurrentFilterFunction="Contains" UniqueName="Name" >
                                         <ItemTemplate>
                                                   <asp:Label ID="lblName" runat="server" Text='<%# eval("Name") %>'>
                                                   </asp:Label>
                                         </ItemTemplate>
                             </telerik:GridTemplateColumn>
                    </Columns>
           </MasterTableView>
</telerik:RadGrid>
               


Wednesday, November 9, 2011

TextBox in GridTemplateColumn

Problem: I want to filter an ASP TextBox
"<asp:TextBox ID="TXTName" runat="server" Text='<%# eval("Name") %>'  ></asp:TextBox>"
in Telerik GridTemplateColumn .Also I dont want filter Icon to display and I Want "StartsWith" Filter Function.

Sloution: Just give DataField="DataFieldName" in GridTemplateColumn.The DataField Name which you are using to evaluate TextBox.

Example:
<asp:TextBox ID="TXTName" runat="server" Text='<%# eval("Name") %>'  ></asp:TextBox>
Must BE Given To DataField e.g DataField="Name".
The Green Highlighted Text Is For Filter Icon To Hide and  For Filtering With "StartsWith" 
The Aqua Highlighted text is For Filtering a String From Label

Yellow Is Common For Both

Here Is The Sample Code:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"   >
            <MasterTableView  AllowFilteringByColumn="True"  >
                     <Columns>                 
                           <telerik:GridTemplateColumn AllowFiltering="true"   AutoPostBackOnFilter="true" HeaderText="Name" datafield="Name" DataType="System.String"
ShowFilterIcon="false"   CurrentFilterFunction="StartsWith" UniqueName="Name" >
                                     <ItemTemplate>
                                        <asp:TextBox ID="TXTName" runat="server" Text= '<%# eval("Name") %>' >
                                        </asp:TextBox>
                                     </ItemTemplate>
                            </telerik:GridTemplateColumn>
                    </Columns>
            </MasterTableView>
</telerik:RadGrid>
               

Right to left support in telerik

Problem: How to set Right to left in different controls of telerik ?
Solution: 
Right to left support in Telerik


Here is the sample code

Monday, November 7, 2011

How To Get SelectedValue Of RadComboBox From Java Script


Problem: How to get SelectedValue Of RadComboBox using Java Script ?
Solution: Place this Script in the Head tag,

 <script type="text/javascript">
    function GetSelectedValueOfRadComboBox() {
        var radcmb = $find("RadComboBox1");  // Find The Object By  ID 
        var value = radcmb.get_value();  // Get_Value() Is telerik Library Included Function
        Return value;
    }
</script>

Sunday, November 6, 2011

Radcalendar having different weekend like (friday,saturday)

Problem: How can we make different weekends like Friday and Saturday in RadCalender ?
Solution: There are two ways,
1) You can do in source of Page like

<telerik:RadCalendar ID="RadCalendar1" Runat="server" FirstDayOfWeek="Thursday">
</telerik:RadCalendar>
RadCalender
Here you can see that Thursday became the first day of week.

RadDatePicker not taking the value from keyboard

Problem: You have noticed that when you pick the value from calender pop up button then it works fine. But when you enter the value through keyboard like 1/1/1920 it does not work.
RadDatePicker

Solution: Remember RadCalender default minimum date is 1/1/1980.So if you give a date less than 1980 it will will not understand the date.


Example:

<telerik:RadDatePicker ID="Datepicker1" Width="100px" runat="server" MinDate="01/01/1900"
     MaxDate="12/31/2100">
</telerik:RadDatePicker>

Saturday, November 5, 2011

~/Telerik.Web.UI.WebResource.axd' is missing in web.config

Problem: When you place RadScriptManager on aspx page and compile it gives error like, 
" '~/Telerik.Web.UI.WebResource.axd' is missing in web.config. RadScriptManager requires a HttpHandler registration in web.config. Please, use the control Smart Tag to add the handler automatically, or see the help for more information: Controls > RadScriptManager "


Solution: Its Simple And fast you Just Have to register The radScriptmanager and it will modify the web config file automatically.
Example:

  • Click RadScriptManager Menu Cursor .It Will Display RadScript Manager Tasks click on Regiter Telerik.Web>UI.WebResource.axd

Telerik.Web.UI.WebResource.axd

  • Telerik.WebUI.WebResources.axd Is Now Succeessfully Register in Web Config.
Telerik.Web.UI.WebResource.axd




To apply client side validation on RadGrid Update or Insert button

Problem: To call any javascript(Client Side) on click of UpdateButton or InsertButton of RadGrid like this image,

Solution: Here is the code

Problem Using Telerik Project

Problem: When I up the website it is showing a strange behaviour, sometimes comboboxes are not working ,sometimes problem in RadGrid.It is running perfectly at local server.
Here is sample code,
<body>
    <form runat="server">
           <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
           <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="All" />
...........
           <telerik:RadGrid ID="RadGrid1" runat="server">
           </telerik:RadGrid>
...........
    </form>
</body>
Solution: It is because you are using RadScriptManager and it is conflicting with Telerik.StyleSheetManager.TelerikCdn.You can do EnableScriptCombine="false" and EnableHandlerDetection="false" (properties of RadScriptManager).
Here is sample code,
<body>
    <form runat="server">
           <telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnableScriptCombine="false" EnableHandlerDetection="false"></telerik:RadScriptManager>
           <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="All" />
...........
           <telerik:RadGrid ID="RadGrid1" runat="server">
           </telerik:RadGrid>
...........
    </form>
</body>

Friday, November 4, 2011

Client Side Validation of RadDatePicker

Problem: How to validate two RadDatePicker Controls for example "From Date" can
not be greater than "To Date".
Solution: It can be done by using asp validation controls like RequiredFieldValidator and CompareValidator. RequiredFieldValidator checks that whether value(date) is present or not. And CompareValidator compares the two values. Here is the sample code,

Tuesday, November 1, 2011

RadDatePicker enable/disable through javascript

Problem: How to enable/disable RadDatePicker through javascript ?
Solution: You can make use of the client side method set_enabled to false.

Example:
function disable()
  {
      var dateinput = $find("<%= RadDatePicker1.ClientID %>");
      dateinput.set_enabled(false);
  }

Also refer the following documentation for more on the RadDatePicker Client Object.
RadDatePicker Client Object

Monday, October 31, 2011

Load RadGrid on Click event

Problem: I Am Using Need data Source, For Binding Telerik Rad Grid,But  I don't Want To Load Rad Grid ,On Page Load Event,Because I want To Load Grid On Click_Button Event.

Solution: First you have to make your RadGrid Visible False on "PageLoad" Event.Then make Visible True on "Click" event of your button. Then Call Function Rebind() it will automatically call Need Data Source and Will Bind Your Rad Grid.

Example:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If IsPostBack = False Then
    'Enter The Code Just First Time When Page Is Load
    RadGrid1.visible=false       
    End If
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    RadGrid1.visible=True
    RadGrid1.rebind()
End Sub

Note: Need Data Source Function Is Necessary Here

Importance of NeedDataSource event

For advanced features such as Grouping, Sorting, Paging, RadGrid must be bound using declarative data sources or through the NeedDataSource event. When using declarative data sources or the NeedDataSource event, RadGrid can automatically accommodate the appropriate database operations without the need for you explicitly handle any sorting, paging, grouping, and so on.
Also note that you should never call the Rebind() method in a NeedDataSource event handler.You should never call DataBind() as well when using advanced data-binding through NeedDataSource.

Could not load file or assembly 'Telerik.Web.UI' or one of its dependencies. The system cannot find the file specified


Problem: You have created web application and using telerik controls. Its working fine at your local environment and even at staging. But when you deployed the application on server it throws error "Could not load file or assembly 'Telerik.Web.UI' or one of its dependencies. The system cannot find the file specified."

And suppose ,You have another application on the same server using Telerik controls and it's working fine. But the new application is not.

Solution: After the project fails in runtime this means that your web site is not referencing properly the Telerik.Web.UI.dll assembly. First check the version of dll and then Check if Telerik.Web.UI.dll assembly is located in the bin folder of your web site. If deployed in GAC check your web.config file for a reference of Telerik.Web.UI.dll within the <assemblies> tag.

Problem with RadLoadingPanel


Problem: When you are using RadAjaxManager and RadLoadingPanel for RadGrid ,Sometimes the Loading Panel Icon appears forever.
For example, when You click on the next page, the LoadingPanel Icon appears forever.
But some days later, it runs smoothly.

Solution: Make sure you are not showing the loading panel manually over the updated control OnRequestStart client-side event. If this is the case, please make sure that you hide it OnResponseEnd client-side event.

More Help >>

Monday, October 24, 2011

RadFormDecorator not working in some controls

Problem: RadFormDecorator is working in some controls and not working in some controls.
Solution: This is because of css. If you have applied inline css to any control it over-writes the css of RadFormDecorator ,so it appears that it is not working. Remove the CssClass property in your control and then it will work.

For Example:

<telerik:RadTextBox ID="txt" runat="server" Width="270px" CssClass="bold">
</telerik:RadTextBox>

Two different languages on same page

Problem: How can we write two different languages on same page.
Solution: Suppose you have two text boxes in the first one you want to write English but in the second one you want to write French. Remember that controls have no property to set the language. So you have to download install the keyboard first and then enter the data.

Wednesday, September 28, 2011

Right to left support in telerik control

Problem: How to give right to left support in any telerik control ?
Solution:
1. Paste this code in the head section of your page

<style type="text/css">
    .rtlSupport
    {
        direction: rtl !important;
    }
</style>

2. Then give CssClass name to the desired control

<telerik:RadDatePicker ID="RadDatePicker1" CssClass="rtlSupport" runat="server" Width="297px"
                                    PopupDirection="BottomLeft">
                                </telerik:RadDatePicker>