Telerik Forums
UI for ASP.NET AJAX Forum
2 answers
175 views
Hi

The DataFormatString doesnt seem to be formatting my data. Working example below. I am building a grid programmatically (although the live example is a hierarchical grid but this example also doesnt work).

Help really appreciated as I looking at the examples on the site I would expect it would

Thanks

aspx code
<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="DataFormatting._Default" %>
  
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
  
  
<form id="form1" runat="server">
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
</telerik:RadAjaxManager>
<telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
</telerik:RadScriptManager>
  
    <div class="contributionTable" >
        <asp:PlaceHolder ID="PlaceHolder1" runat="server" >
        <telerik:RadGrid ID="clientContribution" runat="server" 
            onitemdatabound="clientContribution_ItemDataBound" >
        </telerik:RadGrid>
        </asp:PlaceHolder>
    </div>
  
</form>


Code behind
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Diagnostics;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
  
namespace DataFormatting
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                BuildTheGrid();
            }
  
        }
        protected void clientContribution_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridGroupHeaderItem)
            {
                GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;
                DataRowView groupDataRow = (DataRowView)e.Item.DataItem;
  
            }
  
        }
        #region Build the grid
        private DataSet BuildTheGrid()
        {
            try
            {
  
                clientContribution.DataSource = null;
                DataSet contributionColumns = LoadGridData();
  
  
                // Define the main grid
                for (int loopPos = clientContribution.MasterTableView.Columns.Count; loopPos > 0; loopPos--)
                {
                    clientContribution.MasterTableView.Columns.RemoveAt(loopPos - 1);
                }
                clientContribution.ID = "MyGrid";
                clientContribution.DataSource = contributionColumns;
                clientContribution.Width = Unit.Percentage(98);
                clientContribution.AutoGenerateColumns = false;
                clientContribution.ShowStatusBar = true;
                clientContribution.MasterTableView.Width = Unit.Percentage(100);
  
                // now build the hierarchical grid
                GridBoundColumn boundColumn = new GridBoundColumn();
  
                foreach (DataColumn col in contributionColumns.Tables[0].Columns)
                {
                        boundColumn = new GridBoundColumn();
                        clientContribution.MasterTableView.Columns.Add(boundColumn);
                        boundColumn.DataField = col.ColumnName;
                        boundColumn.HeaderText = col.ColumnName;
                        boundColumn.Visible = true;
  
                        if (col.Ordinal == 1)
                        {
                            boundColumn.DataFormatString = "{0:##,###.0}";
                        }
                        if (col.Ordinal == 2)
                        {
                            boundColumn.DataFormatString = "{0:###.0%}";
                        }
  
                }
                clientContribution.DataBind();
            }
            catch (Exception exc)
            {
                Debug.WriteLine(exc.Message);
                return null;
            }
            finally
            {
            }
            return null;
  
        }
        #endregion
  
        #region Load the Grid Data
        private DataSet LoadGridData()
        {
            // return the data to display
            DataSet contributionData = new DataSet("MyData");
  
            DataTable gridData = contributionData.Tables.Add("ContData");
  
            gridData.Columns.Add(new DataColumn("DummyValue"));
            gridData.Columns.Add(new DataColumn("DecimalValue"));
            gridData.Columns.Add(new DataColumn("PercentageValue"));
  
            for (int i = 0; i < 10; i++)
            {
                DataRow dataRow = contributionData.Tables[0].NewRow();
  
                dataRow["DummyValue"] = "Value" + i.ToString();
                dataRow["DecimalValue"] = 1234.88 * i;
                dataRow["PercentageValue"] = 2.33 * i;
  
                contributionData.Tables[0].Rows.Add(dataRow);
            }
            return contributionData;
        }
        #endregion
  
    }
}

wonderbison
Top achievements
Rank 1
 answered on 23 Jun 2011
3 answers
167 views
Could someone please help me with the correct code to reference the DataKeyValue in the Child item of a Hierarchy using ItemInserted.  I have tried the following code but don't get the datakey returned at the Child ("Sheds") level.
Protected Sub RadGrid1_ItemInserted(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridInsertedEventArgs) Handles RadGrid1.ItemInserted
    If e.Exception Is Nothing Then
        Dim editedItem As GridEditableItem = e.Item
        If "Placements".Equals(editedItem.OwnerTableView.Name) Then
            Dim gridRows As GridItemCollection = RadGrid1.Items
            Dim id As Int32 = 0
            For Each data As GridDataItem In gridRows
                id = Math.Max(id, data.GetDataKeyValue("PlanMasterId"))
            Next
            UpdateFarmPerformance(id)
        ElseIf "Sheds".Equals(editedItem.OwnerTableView.Name) Then
            'Update the Placment details from the shed details
            Dim parentItem As GridDataItem = editedItem.OwnerTableView.ParentItem
            Dim id As Int32 = parentItem.OwnerTableView.DataKeyValues(parentItem.ItemIndex)("PlanMasterId")
            updatePlacements(id)
            Dim gridRows As GridItemCollection = e.Item.OwnerTableView.Items
            Dim id2 As Int32 = 0
            For Each data As GridDataItem In gridRows
                id2 = Math.Max(id2, data.GetDataKeyValue("PlanMasterShedId"))
            Next
            UpdateShedPerformance(id2)
            UpdateFarmPerformance(id)
        End If
    End If
End Sub
Thanks
Vasil
Telerik team
 answered on 23 Jun 2011
4 answers
117 views
I have turned on paging in my RadGrid control and the default limits for number of items per page are 10, 25 and 50.  However, I would also like to add additional limits for items per page for 75 and 100 in the dropdown list.

Is there a way to accomplish this in the RadGrid control?  If so, what are the settings that I need to modify?

Thanks.
Pavlina
Telerik team
 answered on 23 Jun 2011
1 answer
60 views
I have a "How the heck to I do THAT?" problem I am hoping someone can help with.

I have a page that uses a RadComboBox, which is bound to a dataset with say 10 names/values in it.  I also have a query being returned to the page, that several other controls are bound to, which also includes two columns which are nothing more than pipe separated strings, one with usernames and the other with userids.  What I need to do is, in the pre-render event, find the usernames and match them to entries in the bound ComboBox.  If found, I need to set the Checked property to true, AND then disable the checkbox so the user cannot check/uncheck the entry in the ComboBox while leaving the other entries available for use.

Anyone have any code examples that might help?  Any help at this point would be greatly appreciated!

Rich
Kate
Telerik team
 answered on 23 Jun 2011
3 answers
95 views
RadControls for ASP.NET AJAX Version: 2011.1 519 (May 19, 2011) No support for .NET 2.0?

I did not find the folder bin20 in the trial download link. can you please advise.
Sebastian
Telerik team
 answered on 23 Jun 2011
1 answer
104 views
I am trying to implement the custom skin from the Car Rental demo at http://demos.telerik.com/aspnet-ajax/carrental/about.aspx. I have downloaded the zip file and put this in my app_themes folder but it looks like maybe some images are missing or a main .css is missing. Can anyone provide me a step by step process to implement the skin properly into my web application.
Bozhidar
Telerik team
 answered on 23 Jun 2011
2 answers
63 views
Hi There,

I have a page which uses a radupload control.

We seem to encounter a problem when a user tries to insert script tags to the field. eg.

<script>
somethingnasty
</script>

What is the suggested way to either validate this input, strip it out, or prevent the error we're being shown.

The error shown is 'htmlfile : access is denied' which after some searching, seems related to possible the control caling form.submit, behind the scenes.

Are there build in validator methods we can use with the radupload control? or a way to link it sensibly to a normal asp:validator control?

Many thanks,

Doug
Peter Filipov
Telerik team
 answered on 23 Jun 2011
1 answer
234 views

Hello everybody ,

I have a combobox inside of a Radgrid and want to be bound on runtime.

There is a very suit sample in Q1 2011 version of Telerik Demo under grid title(Gridà.Net3.5àEntity Framework Manual CRUD Operations) but it is very simple and there are just some common data Management about textbox.

But I tend to do that with a relational model,Suppos that we have two tables ,USERS and GENDER related with a f_key.

USER{UserID int ,Username nvarchar , GenderID int}

GENDER{GenderID int ,Longname nvarchar}

My  aspx file is like this :

  <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"

                AllowPaging="true" AllowSorting="true" OnDeleteCommand="RadGrid1_DeleteCommand"

                OnInsertCommand="RadGrid1_InsertCommand" AllowFilteringByColumn="true" OnUpdateCommand="RadGrid1_UpdateCommand"

                OnUnload="RadGrid1_Unload">

                <MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="false" DataKeyNames="USERID"

                    InsertItemPageIndexAction="ShowItemOnCurrentPage">

                    <Columns>

                        <telerik:GridBoundColumn   DataField="UserID" HeaderText="UserID" UniqueName="UserID" />

                        <telerik:GridBoundColumn DataField="Username" HeaderText="Username" UniqueName="Username" />

                        <telerik:GridTemplateColumn DataField="GENDER" HeaderText="GENDER" UniqueName="GENDER" >

                            <InsertItemTemplate>

                                <telerik:RadComboBox ID="RadComboBox1" runat="server"

                                    Width="140px" />

                            </InsertItemTemplate>

                            <EditItemTemplate>

                                <telerik:RadTextBox ID="RadTComboBox1" runat="server"

                                    ReadOnly="true" Width="140px" />

                            </EditItemTemplate>

 

                    </Columns>

                </MasterTableView>

            </telerik:RadGrid>

 

 

 

How I do my CRUDoperation with this realational model with EntityFramework.

I should demonstarte that I have an edmx file with two entities:tbl_Users , tbl_Gender and I tend to do this operation in Codebehind.

Some common code is such as this,if we use only textbox :

protected void RadGrid1_Unload(object sender, EventArgs e)

    {

        if (DbContext != null)

            DbContext.Dispose();

    }

 

    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)

    {

        RadGrid1.DataSource = DbContext.tbl_User.Select("it.UserID,it.Username,...");

       

    }

 

    protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)

    {

        GridEditableItem item = e.Item as GridEditableItem;

        int _userId = (int)item.GetDataKeyValue("UserID");

        tbl_User _tbl_user = DbContext.tbl_User.Where(p => p.UserID == _userId).FirstOrDefault();

        item.UpdateValues(_tbl_user);

        DbContext.SaveChanges();

    }

 

    protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)

    {

        GridEditableItem item = e.Item as GridEditableItem;

        Hashtable values = new Hashtable();

        item.ExtractValues(values);

        tbl_User _tbl_user = new tbl_User();

        item.UpdateValues(_tbl_user);

        DbContext.AddTotbl_User(_tbl_user);

        DbContext.SaveChanges();

    }

 

    protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)

    {

        int _userId = (int)(e.Item as GridDataItem).GetDataKeyValue("UserID");

        tbl_User _tbl_user = DbContext.tbl_User.Where(p => p.USERID == _userId).FirstOrDefault();

        DbContext.DeleteObject(_tbl_user);

        DbContext.SaveChanges();

    }

 

 

Radoslav
Telerik team
 answered on 23 Jun 2011
4 answers
242 views
Hi,

I have a  form with RadComboBox. I have set EmptyMessage for RadComboBox. I need to keep that ComboBox focused when the page is loaded and start typing.

I tried followings.

in Page load event

1.
this.Form.DefaultFocus = RadComboBox1.ClientID;

2.
RadAjaxManager am = RadAjaxManager.GetCurrent(this);
 
am.FocusControl(RadComboBox1.ClientID + "_Input");
RadScriptManager1.SetFocus(RadComboBox1);


In 1st method RadComboBox is focused but EmptyMessge is not cleared. when we type, "EmptyMessage" also remains.

In 2nd method all work fine only in IE. but not in FireFox or Chrome.

Can anybody help regarding this matter ?.

Thank you,

Dinesh 
Helen
Telerik team
 answered on 23 Jun 2011
1 answer
420 views
Hi,

I am Srinivasa

in my project i have a problem for bind the Date form backend table to RadDatePicker in Rad Grid. But in my data Base in date column i have a empty value. 

here i am using the client side coding for bind Date data to RadDatePicker in RadGrid like the following way...

                       <telerik:RadDatePicker ID="actstart" runat="server" MaxDate='<%# Convert.ToDateTime(Eval("early_start_display")).ToString("dd/MMM/yyyy") %>' Width="100px" Calendar-ShowOtherMonthsDays="false" 
                        Calendar-ShowRowHeaders="false" DbSelectedDate='<%# Bind("actual_start") %>' DateInput-DateFormat="MM/dd/yyyy">
                       </telerik:RadDatePicker>

But it shows the error at the time of Date Column Null value in the DataBase...

Error is :

object cannot be cast from dbnull to other types

Please Help me.

Thanks

D.Srinivasa
Veli
Telerik team
 answered on 23 Jun 2011
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?