Telerik Forums
UI for ASP.NET AJAX Forum
3 answers
329 views

Hello 

I am using RadGrid, which is using BatchEditing. I am using RadComboBox in a column, which is using LoadOnDemand.

This column is showing PROJECT_ID value in the grid. What I need to do, is to bind Column to show PROJECT_NAME.

Because of optimization, I cannot load PROJECT_NAME as a hidden column to the grid or something like that.

I need some Data source where I will have combinations PROJECT_ID  -> PROJECT_NAME and bind it to the column.

This is a solution we are using in different systems.

It is this achievable in Telerik RadGrid and RadCombobox?

Stripped demo code:

ASPX:

<%@ Page Title="Test Page" Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="TimeReport.Web.Pages.WebForm2" MasterPageFile="~/MasterPage.master" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> 
   <link href="/Styles/mail.css" rel="stylesheet" />
</asp:Content>
 
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent"   runat="Server">
   <asp:Label CssClass="header" ID="Label1" runat="server" Text="content3" />
   <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" OnNeedDataSource="messages_NeedDataSource"
    AllowAutomaticInserts="True"
     AllowAutomaticUpdates="True" AllowPaging="True"
    AutoGenerateColumns="False"   PageSize="20"
           
    Width="100%"
    Height="100%"
    Style="border: 0; outline: none" AllowSorting="True">
    <MasterTableView CommandItemDisplay="Top" DataKeyNames="PERSON_ACTIVITY_ID"
      HorizontalAlign="NotSet" EditMode="Batch" AutoGenerateColumns="False"
      TableLayout="Fixed">
      <BatchEditingSettings EditType="Cell" HighlightDeletedRows="true" OpenEditingEvent="DblClick" />
      <SortExpressions>
        <telerik:GridSortExpression FieldName="PERSON_ACTIVITY_ID" SortOrder="Descending" />
      </SortExpressions>
      <CommandItemSettings ShowExportToExcelButton="True" ShowExportToPdfButton="True" />
      <Columns>
         <telerik:GridTemplateColumn HeaderText="Projekt" UniqueName="PROJECT_ID" DataField="PROJECT_ID" SortExpression="PROJECT_ID" HeaderStyle-Width="15%" ItemStyle-Width="15%"  >
          <ItemTemplate>
            <%#DataBinder.Eval(Container.DataItem, "PROJECT_ID")%>
          </ItemTemplate>
          <EditItemTemplate>
            <telerik:RadComboBox RenderMode="Lightweight" runat="server" ID="GCB_Project" ShowMoreResultsBox="true" EnableVirtualScrolling="true"
              OnItemsRequested="PROJECT_ItemsRequested1" EnableLoadOnDemand="true" Width="100%" Height="300" ItemsPerRequest="10"  DataTextField="PROJECT_NAME" DataValueField="PROJECT_ID" >
            </telerik:RadComboBox>
          </EditItemTemplate>
 
<HeaderStyle Width="15%"></HeaderStyle>
 
<ItemStyle Width="15%"></ItemStyle>
        </telerik:GridTemplateColumn>    
 
      </Columns>
      <PagerStyle Position="TopAndBottom" AlwaysVisible="True" />
    </MasterTableView>
    <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
 
    <ExportSettings>
      <Pdf PageWidth="">
      </Pdf>
    </ExportSettings>
 
    <ClientSettings AllowKeyboardNavigation="true" EnableRowHoverStyle="true">
      <Selecting AllowRowSelect="True" />
      <Scrolling AllowScroll="true" UseStaticHeaders="true" />
    </ClientSettings>
 
    <PagerStyle Position="TopAndBottom" AlwaysVisible="True" />
    <FilterMenu RenderMode="Lightweight"></FilterMenu>
 
    <HeaderContextMenu RenderMode="Lightweight"></HeaderContextMenu>
  </telerik:RadGrid>
 
 
</asp:Content>

CS:

using System;
using System.Data;
using Telerik.Web.UI;
 
 
namespace TimeReport.Web.Pages
{
  public partial class WebForm2 : Api.Page
  {
    private const int ItemsPerRequest = 10;
 
    protected void Page_Load(object sender, EventArgs e)
    {
    }
 
    protected void PROJECT_ItemsRequested1(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
      DataTable data = new Api.Projects(TRApiSessionContext.CurrentUser.Login).LoadBasic();  //Load DataTable for ComboBox
      int itemOffset = 0;
    int endOffset = 0;
    int count = 0;
      if (data == null)
      {
        e.EndOfItems = true;
      }
      else
      {
        itemOffset = e.NumberOfItems;
        endOffset = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count);
        e.EndOfItems = endOffset == data.Rows.Count;
        count = data.Rows.Count;
      }
       
      for (int i = itemOffset; i<endOffset; i++)
      {
        ((RadComboBox)sender).Items.Add(new RadComboBoxItem(data.Rows[i]["PROJECT_FULL_NAME"].ToString(), data.Rows[i]["PROJECT_ID"].ToString()));
      }
    //  e.Message = GetStatusMessage(endOffset, count);
    }
 
    protected void messages_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
      RadGrid1.DataSource = new Api.Activities("vrabel").Load();  //Load DataTable for Grid
    }
  }
}

 

Thank you.

Attila Antal
Telerik team
 answered on 18 Nov 2019
1 answer
132 views
I cannot find a example of this, but is there a way to distinguish between edit mode types such as "Insert","Update"? I have the button for inserting and updating already configured to switch between the modes. 
Eyup
Telerik team
 answered on 18 Nov 2019
2 answers
1.0K+ views
Here is my RadGrid aspx :   

     
<telerik:RadGrid ID="grd_transactions" runat="server" GroupPanelPosition="Top" AutoGenerateColumns="False">
            <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
            <MasterTableView>
                <Columns>
                    <telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn_Type column" HeaderText="Type" UniqueName="TemplateColumn_Type">
                        <HeaderStyle Font-Bold="True" Font-Size="Medium" Width="100px" HorizontalAlign="Center" VerticalAlign="Middle" />
                        <ItemTemplate>
                            <asp:Label ID="lbl_Type" runat="server" Text="lbl_Type"></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn_Date_Time_UTC_GMT column" HeaderText="Date & Time (UTC/GMT)" UniqueName="TemplateColumn_Date_Time_UTC_GMT">
                        <HeaderStyle Font-Bold="True" Font-Size="Medium" Width="200px" HorizontalAlign="Center" VerticalAlign="Middle" />
                        <ItemTemplate>
                            <asp:Label ID="lbl_Date_Time_UTC_GMT" runat="server" Text="lbl_Date_Time_UTC_GMT"></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn_BTC_Investment_Address column" HeaderText="BTC Investment Address" UniqueName="TemplateColumn_BTC_Investment_Address">
                        <HeaderStyle Font-Bold="True" Font-Size="Medium" Width="600px" HorizontalAlign="Center" VerticalAlign="Middle" />
                        <ItemTemplate>
                            <asp:Label ID="lbl_BTC_Investment_Address" runat="server" Text="lbl_BTC_Investment_Address"></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn_Deposit_Amount column" HeaderText="Deposit Amount" UniqueName="TemplateColumn_Deposit_Amount">
                        <HeaderStyle Font-Bold="True" Font-Size="Medium" Width="150px" HorizontalAlign="Center" VerticalAlign="Middle" />
                        <ItemTemplate>
                            <asp:Label ID="lbl_Deposit_Amount" runat="server" Text="lbl_Deposit_Amount"></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn_Payout_Amount column" HeaderText="Payout Amount" UniqueName="TemplateColumn_Payout_Amount">
                        <HeaderStyle Font-Bold="True" Font-Size="Medium" Width="150px" HorizontalAlign="Center" VerticalAlign="Middle" />
                        <ItemTemplate>
                            <asp:Label ID="lbl_Payout_Amount" runat="server" Text="lbl_Payout_Amount"></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn_Status column" HeaderText="Status" UniqueName="TemplateColumn_Status">
                        <HeaderStyle Font-Bold="True" Font-Size="Medium" Width="150px" HorizontalAlign="Center" VerticalAlign="Middle" />
                        <ItemTemplate>
                            <asp:Label ID="lbl_Status" runat="server" Text="lbl_Status"></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>


Now in code behind i want to fill those labels inside TemplateColumns like this :  
 

DataTable table = new DataTable();
table.Columns.Add("Type", typeof(string));
table.Columns.Add("Date & Time (UTC/GMT)", typeof(string));
table.Columns.Add("BTC Investment Address", typeof(string));
table.Columns.Add("Deposit Amount", typeof(string));
table.Columns.Add("Payout Amount", typeof(string));
table.Columns.Add("Status", typeof(string));
table.Rows.Add("1", "2", "3", "4" ,"5", "6");
table.Rows.Add("1", "2", "3", "4", "5", "6");
table.Rows.Add("1", "2", "3", "4", "5", "6");
table.Rows.Add("1", "2", "3", "4", "5", "6");
table.Rows.Add("1", "2", "3", "4", "5", "6");
grd_transactions.DataSource = table;
grd_transactions.DataBind();


Here is the wrong output.

How can i access those labels & fill them?
Zakhaliya Ivarnovich
Top achievements
Rank 1
 answered on 16 Nov 2019
1 answer
184 views

A client wanted text selected by default when entering edit mode, so I did some research and applied the solution noted below.

Using RadGrid with VB.NET, Batch Edit Mode with GridTemplateColumns. 

When clicking a cell that has a RadComboBox, the BatchEditOpened function doesn't return the correct reference to the control when clicking a cell on the same row that is INPUT only.

Here is a link to a sample App that replicates the pattern described:
https://1drv.ms/u/s!AtPkHVExQn29bhZgXpAMSX2LKgQ

All you need to do is add the latest Telerik DLLs to the project and it should compile.  Excluded them from the ZIP file at the above link.

 

The real page is wired up to a SQL Server database, but I was able to use the XML Data Source from the Sample Applications to replicate the issue.

 

Here is the page design:

<telerik:RadCodeBlock runat="server">
    <script type="text/javascript">
 
        function BatchEditOpened(sender, args) {
            var batchManager = sender.get_batchEditingManager();
            var theCell = batchManager._getDataControl(args.get_row(), args.get_columnUniqueName());
 
            if (theCell.tagName == "INPUT") {
                setTimeout(function () {
                    theCell.select();
                }, 30)
            }
        }
 
    </script>
</telerik:RadCodeBlock>
 
<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid2" runat="server" ShowStatusBar="true" OnNeedDataSource="RadGrid2_NeedDataSource"
    OnInsertCommand="RadGrid2_InsertCommand" OnUpdateCommand="RadGrid2_UpdateCommand"
    OnDeleteCommand="RadGrid2_DeleteCommand">
 
    <MasterTableView AutoGenerateColumns="false" DataKeyNames="CustomerID" EditMode="Batch" CommandItemDisplay="Top">
        <Columns>
 
            <telerik:GridTemplateColumn HeaderStyle-Width="50px" AllowSorting="true" SortExpression="CustomerID" ItemStyle-BorderColor="Black" ItemStyle-BorderStyle="Solid" ItemStyle-BorderWidth="0.5px" HeaderText="L3" UniqueName="L3" ItemStyle-CssClass="rgRightItem" HeaderStyle-CssClass="rgCenterHeader">
                <ItemTemplate>
                    <asp:Label runat="server" ID="lblCustomerId" Text='<%# Eval("CustomerID") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox runat="server" ID="txtCustomerId" Text='<%# Eval("CustomerID") %>'></asp:TextBox>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
 
            <telerik:GridTemplateColumn HeaderStyle-Width="175px" AllowSorting="true" SortExpression="ContactName" HeaderText="Contact Name Header" UniqueName="ContactName" SortedBackColor="LemonChiffon" ItemStyle-CssClass="rgLeftItem" HeaderStyle-CssClass="rgLeftHeader">
                <ItemTemplate>
                    <asp:Label runat="server" ID="lblContactName" Text='<%# Eval("ContactName") %>'></asp:Label>
                     
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadComboBox runat="server" ID="editContactName" EnableLoadOnDemand="True" DataTextField="ContactName"
                        OnItemsRequested="editContactName_ItemsRequested" DataValueField="ID"
                        HighlightTemplatedItems="true" Height="140px" DropDownAutoWidth="Enabled" Sort="Ascending">
                    </telerik:RadComboBox>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
 
 
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnBatchEditOpened="BatchEditOpened" />
    </ClientSettings>
</telerik:RadGrid>

 

Here is the code behind:

Imports System
 
Imports Telerik.Web.UI
Imports System.Collections
 
Public Class test1
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
    End Sub
 
    Private Const FILE_PATH As String = "~/App_Data/Xml/XmlDataSourceExampleTemp.xml"
 
    Protected Sub RadGrid2_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs)
 
        Dim sourceDocument = LoadDocument(FILE_PATH)
        Dim customers = GetCustomersEnumeration(sourceDocument, "Customers", "Customer")
        Dim gridSource = From customer In customers
                         Select New With {.CustomerID = customer.Attribute("CustomerID").Value, .ContactName = customer.Attribute("ContactName").Value, .CompanyName = customer.Attribute("CompanyName").Value}
        CType(sender, RadGrid).DataSource = gridSource
 
    End Sub
 
    Private Function LoadDocument(path As String) As XDocument
 
        Dim sourceDocument As XDocument = XDocument.Load(Me.Server.MapPath(path))
        Return sourceDocument
 
    End Function
 
    Private Function GetCustomersEnumeration(sourceDocument As XDocument, rootNode As XName, childNode As XName) As IEnumerable(Of XElement)
 
        Dim customers = sourceDocument.Element(rootNode).Elements(childNode)
        Return customers
 
    End Function
 
    Protected Sub RadGrid2_UpdateCommand(source As Object, e As GridCommandEventArgs)
 
    End Sub
 
    Protected Sub RadGrid2_InsertCommand(source As Object, e As GridCommandEventArgs)
 
    End Sub
 
    Protected Sub RadGrid2_DeleteCommand(source As Object, e As GridCommandEventArgs)
 
    End Sub
 
    Protected Sub editContactName_ItemsRequested(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs)
        Dim combo As RadComboBox = TryCast(sender, RadComboBox)
        combo.Items.Add(New RadComboBoxItem("Alfreds Futterkiste", "0"))
        combo.Items.Add(New RadComboBoxItem("Antonio Moreno Taqueria", "1"))
        combo.Items.Add(New RadComboBoxItem("Around the Horn", "2"))
    End Sub
 
 
End Class
Attila Antal
Telerik team
 answered on 15 Nov 2019
5 answers
316 views
I get a trouble when using Excel-like Filtering with GridDateTimeColumn.
It doesn't worked.
Anyone give me an example about it. 
Many thanks !
Attila Antal
Telerik team
 answered on 15 Nov 2019
3 answers
672 views

I am trying to get the values from the RadGrid insert form and then insert those values from the form elements into a SQL database using a stored procedure. When I run the following code using the RadGrid insert command sub, empty values are inserted to the database.

Here is the code:

Protected Sub rg_InsertCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles rg.InsertCommand
        Dim item As GridEditFormInsertItem = CType(e.Item, GridEditFormInsertItem)
        Dim name As RadTextBox = TryCast(item.FindControl("txtName"), RadTextBox)
        Dim str As String = name.Text
    End Sub
Attila Antal
Telerik team
 answered on 14 Nov 2019
5 answers
273 views
Hello I am trying to keep radgrid inside fieldset but when i keep radgrid inside fieldset, i am getting the grid's scroll bar but the horizontal width i am getting is what exactly with out scrollbars. i want the grid to be fit on the Browser with scroll bars. But it is long grid.

please reply.
Thanks.
Attila Antal
Telerik team
 answered on 14 Nov 2019
1 answer
125 views

Hi, 

We need to move the RadGrid selected Row Up and Down by using buttons Up and Down outside the RadGrid. We need to implement this approach on Urgent basis any Solution would be highly appreciated?

Thanks,

Sufyan

Attila Antal
Telerik team
 answered on 14 Nov 2019
8 answers
998 views
Hi,

I have a Asp.Net Label control  and few Button controls ( "OK", Cancel" and "Submit" Buttons) inside rad window.
I want to modify the Label's text and toggle the visibility of these buttons using javascript. I tried following code


function showConfirmationBox(){
     var Radwindow1 = $find("<%=Radwindow1.ClientID %>");
     var confirmWinContentTemplate =  Radwindow1.get_contentFrame().contentWindow;
     var label1 = _confirmWin.getElementById("Label1");
     var submitBtn = _confirmWin.getElementById("SubmitBtn1");
     label1.innerHTML ="Error in code!";
     submitBtn.style.display = "none";
     submitBtn.style.visibility = "hidden";

 
     ......
      ....
    Radwindow1.show();
}
 

Any idea?

Thanks,
Prava
nitin
Top achievements
Rank 1
 answered on 14 Nov 2019
1 answer
155 views
When I double click on a Word file within File Explorer I get some garbage text in the browser.  Is there anyway to double click on the Word document and it opens up the file in Word?
Vessy
Telerik team
 answered on 14 Nov 2019
Narrow your results
Selected tags
Tags
+? more
Top users last month
Tien
Top achievements
Rank 1
Iron
Krasimir
Top achievements
Rank 3
Bronze
Iron
Iron
Cedar
Top achievements
Rank 1
Iron
Emil
Top achievements
Rank 1
Iron
Kyle Watson
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Tien
Top achievements
Rank 1
Iron
Krasimir
Top achievements
Rank 3
Bronze
Iron
Iron
Cedar
Top achievements
Rank 1
Iron
Emil
Top achievements
Rank 1
Iron
Kyle Watson
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?