Showing posts with label RadGrid. Show all posts
Showing posts with label RadGrid. Show all posts

Tuesday, December 4, 2012

RadGrid inside Radgrid hierarchy using Template Column

Problem:

I want to make RadGrid hierarchy using ItemTemplate.and I want commandItem display at top in Detail Grid just like Master Grid.

Solution:

Its technique is very simple,you have to put a <DetailTables> tag just after <MasterTableView> and make the relation of  Master and Detail, see the following example and watch for Bold text.But here I like to mention one thing that insert/update/delete events of Master and Detail grids are same and you have to differentiate that either insert/update/delete is called from Master or Detail. However NeedDataSource event is called when Master Grid is binned and DetailTableDataBind event is called when Detail table is binned.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" PageSize="20"
        AllowSorting="True" AllowPaging="True" ShowStatusBar="True" GridLines="None"
        Skin="WebBlue" CellSpacing="0">
        <MasterTableView DataKeyNames="ParentID_PK" ClientDataKeyNames="ParentID_PK" CommandItemDisplay="Top">
        <DetailTables>
            <telerik:GridTableView DataKeyNames="DetailID_PK" ClientDataKeyNames="DetailID_PK"
                    Width="100%" runat="server" CommandItemDisplay="Top">
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="ParentID_FK" MasterKeyField="ParentID_PK">
                    </telerik:GridRelationFields>
                </ParentTableRelation>

                <Columns>

<%--here will be the columns of Detail table--%>

                </Columns>
            </telerik:GridTableView>
        </DetailTables>
        <Columns>



<%--here will be the columns of Master table--%>

        </Columns>
    </MasterTableView>
</telerik:RadGrid>

Friday, November 16, 2012

RadGrid Multirow Selection form Client Side

Problem:

How to select a multiple rows in RadGrid from client side?

Solution:

Make AllowMultiRowSelection  property to True for multi row selection and in client settings make AllowRowSelect to True. and include a GridClientSelectColumn in Columns Tag.

For Example:

<telerik:radgrid id="RadGrid1" runat="server" autogeneratecolumns="False" pagesize="20"
        allowsorting="True" allowpaging="True" showstatusbar="True" gridlines="None"
        skin="WebBlue" cellspacing="0" allowmultirowselection="true">
<ClientSettings>
           <Selecting AllowRowSelect="True"/>
</ClientSettings>

<MasterTableView>
<Columns>
<telerik:GridClientSelectColumn UniqueName="MyClientSelectColumn" HeaderText="asd">
</telerik:GridClientSelectColumn>

<telerik:GridTemplateColumn UniqueName="TemplateColumn">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text="It is hidden ID or primary key of the row" Visible="false"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:radgrid>

To get the selected rows you should use a for each loop on selected Items of RadGrid like this one :

For Each item As GridDataItem In RadGrid1.SelectedItems
          Dim lblID As Integer = CType(CType(item.FindControl("lblID"), Label).Text, Integer)
Next

Friday, June 15, 2012

Give an option of "All" in RadGrid PageSize Combo


To show all rows in RadGrid. I want to give an option of "All" in RadGrid
PageSize Combo. Like this:


Solution:
VB Code
Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
        If TypeOf e.Item Is GridPagerItem Then
            Dim combo As RadComboBox = TryCast(TryCast(e.Item, GridPagerItem).FindControl("PageSizeComboBox"), RadComboBox)

            ' The number of items shown when all is selected
            Dim allRowsCount As Integer = Integer.MaxValue

            ' Remove duplicates
            Dim duplicate As RadComboBoxItem = combo.Items.FindItemByValue(allRowsCount.ToString())
            If duplicate IsNot Nothing Then
                duplicate.Remove()
            End If

            ' Create a new item for showing all
            Dim item As New RadComboBoxItem("All", allRowsCount.ToString())
            item.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID)
           
combo.Items.Add(item)

            ' Set the current pagesize as the selected value
            combo.Items.FindItemByValue(RadGrid1.PageSize.ToString()).Selected = True
        End If
    End Sub

Wednesday, May 23, 2012

Find Label Control from Item Temple of RadGrid

Problem:

I am using GridTemplateColumn in RadGrid and I want find the label control which is in grid's ItemTemplate to update record.

I am using this code in grid's updatecommand,

VB CODE:
Dim Label1 As Label = CType(e.Item.FindControl("Label1"), Label)

but control is not found thus there is (nothing) in Label1.

Solution:

Try this,

VB CODE:
Dim Label1 As Label = DirectCast(CType(e.Item, GridEditFormItem).OwnerTableView.Items(e.Item.ItemIndex).FindControl("Label1"), Label)

Friday, January 20, 2012

is neither a DataColumn nor a DataRelation for table DefaultView

Problem: I get this error when I try to filter any column in my RadGrid.I am using template columns.

"is neither a DataColumn nor a DataRelation for table DefaultView"

Here is my code of a Column
<telerik:GridTemplateColumn HeaderStyle-HorizontalAlign="Center" HeaderText="PO #" Visible="true">
 <ItemTemplate>
<asp:Label ID="lblPONumber" Text='<%# Eval("_PONumber") %>' runat="server">
</asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
</telerik:GridTemplateColumn>


Solution: You have to check that DataField property is present or not.

Here is corrected Code
<telerik:GridTemplateColumn DataField="_PONumber" HeaderStyle-HorizontalAlign="Center" HeaderText="PO #" Visible="true">
 <ItemTemplate>
<asp:Label ID="lblPONumber" Text='<%# Eval("_PONumber") %>' runat="server">
</asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
</telerik:GridTemplateColumn>

Wednesday, January 18, 2012

First Column of RadGrid to stay visible

Problem: I have many columns in my RadGrid ,I want first column to stay visible while scrolling.Only first column should appear all the time.
Solution: This can be done using FrozenColumnsCount in ClientSettings tag.

Example:
<telerik:RadGrid ID="radGridServices" runat="server">
    <MasterTableView CommandItemDisplay="Top" DataKeyNames="Services_ID_PK" ClientDataKeyNames="Services_ID_PK">
    </MasterTableView>
    <ClientSettings>
        <Scrolling AllowScroll="true" FrozenColumnsCount="1" SaveScrollPosition="true" UseStaticHeaders="true" />
        <ClientEvents />
    </ClientSettings>
</telerik:RadGrid>



Tuesday, December 20, 2011

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;

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);
  }

 }
}


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>

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>
               

Saturday, November 5, 2011

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

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