Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
94 views
I am following the post to do Automatic CRUD operation on rad grid using Entity Framework by using:
http://demos.telerik.com/aspnet-ajax/grid/examples/automaticoperations/efdatabinding/defaultvb.aspx

My code for Design Page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Demo.aspx.cs" Inherits="Telerik.Demo" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <style type="text/css">
        .MyImageButton
        {
            cursor: hand;
        }
        .EditFormHeader td
        {
            font-size: 14px;
            padding: 4px !important;
            color: #0066cc;
        }
    </style>
</head>
<body class="BODY" style="background-color: Black">
    <form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
        <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="EntityDataSource1" GridLines="None"
            AllowPaging="True" AllowAutomaticUpdates="True" AllowAutomaticInserts="True"
            AllowAutomaticDeletes="True" AllowSorting="True" Width="750px" OnItemCreated="RadGrid1_ItemCreated"
            CellSpacing="0" Skin="Black">
            <PagerStyle Mode="NextPrevAndNumeric" />
            <ClientSettings>
                <Selecting CellSelectionMode="None"></Selecting>
            </ClientSettings>
            <MasterTableView DataSourceID="EntityDataSource1" AutoGenerateColumns="False" DataKeyNames="ID"
                CommandItemDisplay="Top">
                <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
                <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                </RowIndicatorColumn>
                <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                </ExpandCollapseColumn>
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                    </telerik:GridEditCommandColumn>
                    <telerik:GridBoundColumn DataField="ID" HeaderText="ID" SortExpression="ID" UniqueName="ID"
                         MaxLength="5">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name"
                        UniqueName="Name">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Address" HeaderText="Address" SortExpression="Address"
                        UniqueName="Address">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="DeptID" HeaderText="DeptID" SortExpression="DeptID"
                        UniqueName="DeptID">
                    </telerik:GridBoundColumn>
                    <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton" />
                </Columns>
                <EditFormSettings>
                    <EditColumn ButtonType="ImageButton" />
                </EditFormSettings>
            </MasterTableView>
            <FilterMenu EnableImageSprites="False">
            </FilterMenu>
        </telerik:RadGrid>
        <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=Entity"
            DefaultContainerName="Entity" EnableDelete="True" EnableFlattening="False" EnableInsert="True"
            EnableUpdate="True" EntitySetName="EMPLOYEEs" EntityTypeFilter="EMPLOYEE">
        </asp:EntityDataSource>
    </div>
    </form>
</body>
</html>

Code Behind Page:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;


namespace Telerik
{
    public partial class Demo : System.Web.UI.Page
    {
        Entity ent = new Entity();
        EMPLOYEE emp = new EMPLOYEE();
        protected void Page_Load(object sender, EventArgs e)
        {  
                RadGrid1.DataSourceID = null;
                BindGrid();
        }

        public void BindGrid()
        {
                var query5 = from employee in ent.EMPLOYEEs
                             select new
                             {
                                 ID = employee.ID,
                                 NAME = employee.NAME,
                                 ADDRESS = employee.ADDRESS,
                                 DEPTID = employee.DEPTID
                             };
                RadGrid1.DataSource = query5;
        }

        protected void RadGrid1_ItemCreated(object sender, Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                if (!(e.Item is GridEditFormInsertItem))
                {
                    GridEditableItem item = e.Item as GridEditableItem;
                    GridEditManager manager = item.EditManager;
                    GridTextBoxColumnEditor editor = manager.GetColumnEditor("ID") as GridTextBoxColumnEditor;
                    editor.TextBoxControl.Enabled = false;
                }
            }
        }

        protected void gv1_NeedDataSource(object sender, Web.UI.GridNeedDataSourceEventArgs e)
        {
            BindGrid();
        }
    }
}

while execution it does nothing,only grid is displayed without any of the CRUD operation
Plz Help,
Thanks
Andrey
Telerik team
 answered on 01 Oct 2012
2 answers
91 views
I have a radgrid that when the page loads all items are in edit mode. When I click to go to the next page all of the items on the next page aren't in edit mode. :( I gave to click "edit" for each item. I'd like for the next page to go into edit mode too.

This is what I'm using to get it into edit mode, which works for the first page.

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        LinkButton lnkBtnDelete = (LinkButton)item["AutoGeneratedDeleteColumn"].Controls[0];
        lnkBtnDelete.Attributes["onclick"] = "javascript:return confirm(\'Do you want to delete this item?\')";
    }
    if (!Page.IsPostBack && e.Item is GridEditableItem)
    {
        e.Item.Edit = true;
    }
 
}

protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        foreach (GridItem item in RadGrid1.MasterTableView.Items)
        {
            if (item is GridEditableItem)
            {
                GridEditableItem editableItem = item as GridDataItem;
                editableItem.Edit = true;
            }
        }
        RadGrid1.Rebind();
    }
}



Kee Fai Foong
Top achievements
Rank 1
 answered on 30 Sep 2012
1 answer
128 views
Hi,

I have a grid with a lot of data.  I notice that when I add a new row it load the grid and presents the editable section at the very end of the grid pagination.  This increases the amount of time required to add a record.  Whenever we are adding a record we are doing so on the first page so it is most desirable to have the insert happen in the 1st position instead of having to reload the grid and go to the end.  Hope that make sense and how can I accomplish this.

Thanks

Eric
Jayesh Goyani
Top achievements
Rank 2
 answered on 30 Sep 2012
5 answers
182 views
Just starting to use telerik controls and I've combed through the forums and documentation for my problem but something hasn't clicked for me.  My scenario is that I have a radgrid with multiple griddropdowncolumns, 7 of them to be exact (days of the week).  The data is being bound in codebehind of type int for these 7 columns (there are other columns but those are coming back fine).  When I'm binding the data to the grid, the griddropdowncolumns do not populate at all.  The values should be between 1-5 to represent a status for each day.  So, initially, upon load of the radgrid, the columns will appear with respective status' and in edit mode the user shoul be able to select a different status for each day.  Sorry for the length, but trying to make my point here...
Here is a snippet of  my aspx code:
<telerik:GridDropDownColumn DataField="Mon" HeaderText="Mon" ListTextField=""
                                ListValueField="Mon" UniqueName="MonTitleColumn" DropDownControlType="RadComboBox" ColumnEditorID="MonTitleEditor1" />
                            <telerik:GridDropDownColumn DataField="Tue" HeaderText="Tue" ListTextField="StatusName"
                                ListValueField="Tue" UniqueName="TueTitleColumn" DropDownControlType="RadComboBox" ColumnEditorID="FebTitleEditor1" />
                            <telerik:GridDropDownColumn DataField="Wed" HeaderText="Wed" ListTextField="StatusName"
                                ListValueField="Wed" UniqueName="MarTitleColumn" DropDownControlType="DropDownList" ColumnEditorID="MarTitleEditor1" />
                            <telerik:GridDropDownColumn DataField="Thu" HeaderText="Thu" ListTextField="StatusName"
                                ListValueField="Thu" UniqueName="ThuTitleColumn" DropDownControlType="DropDownList" ColumnEditorID="AprTitleEditor1" />
                            <telerik:GridDropDownColumn DataField="Fri" HeaderText="Fri" ListTextField="StatusName"
                                ListValueField="Fri" UniqueName="MayTitleColumn" DropDownControlType="DropDownList" ColumnEditorID="MayTitleEditor1" />
How do I show the value in the db (1-5) for each of the GridDropDownColumns and in edit mode select the values 1-5...
I'm afraid I've spent all day and yesterday and my brain is fried.  And in the process I've thoroughly confused myself.
Any and all help is appreciated!
SS
SikhSuperman
Top achievements
Rank 1
 answered on 30 Sep 2012
1 answer
95 views
Hi!

Here is my problem:
I use ascx editform in telerik radgrid. I have some textboxes, a Cancel and a Save button on it.
I want it to work the following way:
- if the user writes correct values in the textboxes and clicks the save button, the editform must close and the grid must show the new values.
- if the user writes wrong values in the textboxes and clicks the button, the editform must stay visible so the user can change the wrong values.

The situation is a little bit more complicated, because I use the editform in the grid's childgrid/detailtable.
If it is possible, I want to solve the problem in the ascx form's code behind. 

Sorry for my bad English,
Thanks for the answers!
Kostadin
Telerik team
 answered on 29 Sep 2012
1 answer
66 views
Hi,

I have a data structure similar to the one below where one class contains a colleciton of another class as one of it's fields:

Product
{
    String name
    String desription
    Address[] addresses
}

Address
{
    String state
    String suburb
}

Within a data grid which I am binding to the Product class, I want to display only the Product "name" field but have it grouped by the "state" field of the first item of the addresses collection (within my data I am ensuring that every Product has at least one Address)

So my data grid would look somthing like:

VIC
    - Product Name 1
    - Product name 2
NSW
    - Product Name 3
    - Product Name 4

Is this possible? To date I can only get grouping working on fields within the Business (or top level) class, not fields from the Address (or nested) class.
Angel Petrov
Telerik team
 answered on 29 Sep 2012
7 answers
262 views

Hello,

I have used asp.net telerik RadEditor control in web-site and to host this website in Shared hosting server, I have to disable Telerik.EnableEmbeddedScripts and add required scripts in page but Dialog of RadEditor is not working.

My site is hosted in FastHost shared hosting server. Other controls of Telerik is worked perfect. Version of Telerik is 2011.3.1115.35

Can any one have solution to enable dialogs for editor control in any shared hosting server?

Thanks,
Mohmedsadiq

Rumen
Telerik team
 answered on 29 Sep 2012
1 answer
106 views
I'm able to export to a pdf using the ExportToPdf() function, then in the ExportContent event I can save the PDF to the hard drive.  Is there any way to kill the event from opening up the PDF.  Or is there another way to save the RadEditor's content directly to a PDF on the computers hard drive with out having to open the PDF?
Rumen
Telerik team
 answered on 29 Sep 2012
3 answers
151 views
Hi,

I have a dropdown list inside the radgrid 

<telerik:GridTemplateColumn  HeaderText="" UniqueName="Answer" DataField="Answer"  >
                    <ItemTemplate>
                    <asp:DropDownList ID="ddlAnswer" runat="server"   DataTextField="Answer"
DataValueField="Answer" >
                    <asp:ListItem  Value="Yes" >Yes</asp:ListItem>
                    <asp:ListItem  Value="No" >No</asp:ListItem>
                    </asp:DropDownList>
                    </ItemTemplate>
                     </telerik:GridTemplateColumn>

If the user selects No and hits submit button the record will be updated in the database and below the answer No will be saved.(Database is updating properly)

When I click on this page again or refresh the page the page should be loaded with all the correct data from the database.

 every time the page loads all data except this drop down is getting binded properly. There are few records where the user selected No but still the drop down is showing Yes. How can I make No as the selected item?
Pavlina
Telerik team
 answered on 29 Sep 2012
2 answers
304 views
I have a screen with a radgird that has a master table and a detail table.  When I Expand a record that has no detail information the grid expands and shows No Child Record To Display, but when I click on a record that has detail information nothin happens.

<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Office2007" AllowPaging="True" EnableLinqExpressions="false" AllowCustomPaging="true" AutoGenerateColumns="False" GridLines="None" AllowSorting="true" AllowFilteringByColumn="false" AlternatingItemStyle-BackColor="#eeeeee" ShowGroupPanel="False" ShowStatusBar="True" OnNeedDataSource="RadGrid1_NeedDataSource"                                  OnPreRender="RadGrid1_PreRender" OnDetailTableDataBind="HistoryDetail_NeedDataSource">
             <AlternatingItemStyle BackColor="#EEEEEE"></AlternatingItemStyle>
             <MasterTableView DataKeyNames="MarketingID"  PagerStyle-Mode="NextPrevNumericAndAdvanced" >
                    <GroupByExpressions>
                            <telerik:GridGroupByExpression>
                                   <SelectFields>
                                            <telerik:GridGroupByField FieldAlias="ClientName" HeaderText="Client" FieldName="ClientName"
                                                     HeaderValueSeparator=" : "></telerik:GridGroupByField>
                                   </SelectFields>
                      <GroupByFields>
                          <telerik:GridGroupByField FieldName="ClientName" HeaderText="Client" SortOrder="Ascending">
                          </telerik:GridGroupByField>
                      </GroupByFields>
                   </telerik:GridGroupByExpression>
              </GroupByExpressions>
              <RowIndicatorColumn>
                 <HeaderStyle Width="20px"></HeaderStyle>
               </RowIndicatorColumn>
               <ExpandCollapseColumn>
                     <HeaderStyle Width="20px"></HeaderStyle>
               </ExpandCollapseColumn>
                    <Columns>
                           <telerik:GridBoundColumn DataField="MarketingID" HeaderText="MarketingID" SortExpression="MarketingID"  UniqueName="MarketingID" Visible="false">
                           </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="ClientID" UniqueName="ClientID" Visible="false">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="MarketingFormattedID" HeaderText="Marketing ID"
                                       ItemStyle-Width="85" SortExpression="MarketingFormattedID" UniqueName="MarketingFormattedID"
                                        Visible="true" ItemStyle-VerticalAlign="Top">
                             </telerik:GridBoundColumn>
                             <telerik:GridBoundColumn DataField="MarketingTypeName" HeaderText="Marketing Type"
                                              ItemStyle-VerticalAlign="Top" SortExpression="" AllowSorting="false"  UniqueName="MarketingTypeName"        Visible="true">
                             </telerik:GridBoundColumn>
                   </Columns>
                  <PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>
                                          
                  <DetailTables>
                       <telerik:GridTableView DataKeyNames="MarketingID"  runat="server"  >
                             <ParentTableRelation>
                                     <telerik:GridRelationFields DetailKeyField="MarketingID" MasterKeyField="MarketingID" />
                             </ParentTableRelation>
                             <Columns>
                                    <telerik:GridBoundColumn HeaderText="Status"  DataField="MarketingStatusTypeName" UniqueName="MarketingStatusTypeName">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  HeaderText="Changed By"  DataField="ChangedBy" UniqueName="ChangedBy">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn HeaderText="Date Changed"  DataField="DateChanged" UniqueName="DateChanged">
                                    </telerik:GridBoundColumn>
                        </Columns>                                                
              </telerik:GridTableView>
         </DetailTables>
      </MasterTableView>
     <ClientSettings AllowDragToGroup="True">
          <Selecting AllowRowSelect="True" />
     </ClientSettings>
     <FilterMenu Skin="Office2007" EnableTheming="True">
          <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
     </FilterMenu>
  </telerik:RadGrid>

and here is the OnDetailTableDataBind Code
protected void HistoryDetail_NeedDataSource(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
        {
  
            GridDataItem dataItem = e.DetailTableView.ParentItem;
  
            ClientDataContext db = new ClientDataContext();
            var query = from m in db.MarketingStatusChangeLogs
                        where (m.MarketingID == int.Parse(dataItem.GetDataKeyValue("MarketingID").ToString()))
                        select new
                        {
                            m.MarketingStatusType.MarketingStatusTypeName,
                            m.ChangedBy,
                            m.DateChanged
                        };
            e.DetailTableView.DataSource = query;
        }


am I missing something?
Angel Petrov
Telerik team
 answered on 29 Sep 2012
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?