Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
139 views
Hi,

I am looking for custom pagination in Pivot Grid and also a way to hide the Total's Row for each group.

Basically I Have large set of data that to be shown on the grid, i want to bind only sub set of data thru custom pagination otherwise my page will suffer if i have to bind whole data to the grid.

Thanks,
Pavan
Marin
Telerik team
 answered on 09 Oct 2012
1 answer
69 views
Hi,

I have a radgrid on page. which has few textbox conrols, comobox, button etc in grid.
We create row dynamically. Clicking on + sign from grid footer and then it creates a new row.
On new row, we have some input boxes for user to enter info. One os theinput is such that, it has textbox control and button besieds a text box. clicking on button opens a pop up window, user will enter some value in pop window text box, whixh will be passed back from pop up to radgrid textbox control. For existing row it can access the row and textbox control for that row, however for newly created row it throws exception.

Please suggest.

Thanks,
Aditi
Shinu
Top achievements
Rank 2
 answered on 09 Oct 2012
3 answers
118 views
Hi,
I am using Radrotator  control inside modalpopup(using modalpopup extender). But while i am running my project and show modalpopup Radrotator  is not displaying. Normally it is working fine(without modalpopup).
Can you please tell me why it is happening?.
Shinu
Top achievements
Rank 2
 answered on 09 Oct 2012
5 answers
216 views
Hi all,

My MasterTable is defined by:

<MasterTableView DataKeyNames="id">  
    <Columns> 
        <telerik:GridBoundColumn HeaderText="Street" DataField="Address.Street" />                                          
        <telerik:GridBoundColumn HeaderText="HouseNumber" DataField="Address.HouseNumber" /> 
        <telerik:GridBoundColumn HeaderText="ZipCode" DataField="Address.ZipCode.Code" /> 
        <telerik:GridBoundColumn HeaderText="City" DataField="Address.ZipCode.City" /> 
    </Columns> 
</MasterTableView> 

And I want to get the id of the selected item client side. I thought that this would do the trick:

// Javascript  
var selectedItem = $find("MyGridClientID").get_masterTableView().get_selectedItems()[0];  
var selectedItemID = selectedItem.getDataKeyValue("id"); 

But this 'selectedItemID' is following null. What do I do wrong? :o/
Shinu
Top achievements
Rank 2
 answered on 09 Oct 2012
8 answers
282 views
Hi,

I'm creating a grid programmatically based on an unknown number of columns of unknown type and wish to generate multi-line footers with aggregated values. I have looked at the help page, but still not sure how to proceed.

I'm currently working in the RadGrid1_ItemDataBound method where I'm stuck at "if (e.Item is GridFooterItem)". I still need to figure out how to create the footers, populate them with text boxes, and refer to the mysterious clientID mentioned in the help article.
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Text.RegularExpressions;
 
 
public partial class Spreadsheet : System.Web.UI.Page
{
    protected global::System.Web.UI.WebControls.Literal dataRow;
 
    protected void Page_Init(object sender, System.EventArgs e)
    {
        DefineGridStructure();
    }
 
 
    protected void Page_Load(object sender, EventArgs e)
    {
 
        RadGrid grid = (RadGrid)PlaceHolder1.FindControl("RadGrid1");
        RadAjaxManager1.AjaxSettings.AddAjaxSetting(grid, grid);
 
        if (Page.IsPostBack)
        {
            Label1.Text += "Post back!! <br>";
        }
        if (!Page.IsPostBack)
        {
            Label1.Text += "Page_Load; " + DateTime.Now.ToString() + "<br>";
        }
    }
 
    private void DefineGridStructure()
    {
        RadGrid RadGrid1 = new RadGrid();
        RadGrid1.ID = "RadGrid1";
 
        System.Drawing.Color disabledBackColor = System.Drawing.Color.AliceBlue;
        System.Drawing.Color defaultBorderColor = System.Drawing.Color.Black;
 
        RadGrid1.Width = Unit.Percentage(100);
        RadGrid1.PageSize = 7;
        RadGrid1.GridLines = GridLines.Both;
        RadGrid1.AllowPaging = true;
 
        RadGrid1.AllowSorting = true;
        RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
        RadGrid1.ShowFooter = true;
        RadGrid1.AutoGenerateColumns = false;
        RadGrid1.ShowStatusBar = true;
 
        RadGrid1.DataSourceID = "ObjectDataSource1";
        RadGrid1.ItemDataBound += RadGrid1_ItemDataBound;
 
        RadGrid1.UpdateCommand += RadGrid1_UpdateCommand;
 
        RadGrid1.MasterTableView.PageSize = 7;
        RadGrid1.MasterTableView.Height = Unit.Percentage(100);
        RadGrid1.MasterTableView.DataKeyNames = new string[] { "report_id" };
        RadGrid1.MasterTableView.EditMode = GridEditMode.InPlace;
 
        GridEditCommandColumn editColumn;
        editColumn = new GridEditCommandColumn();
        editColumn.UniqueName = "EditCommandColumn";
        editColumn.ItemStyle.BackColor = disabledBackColor;
        editColumn.ItemStyle.BorderColor = defaultBorderColor;
        editColumn.ItemStyle.BorderWidth = Unit.Pixel(1);
        RadGrid1.MasterTableView.Columns.Add(editColumn);
 
        GridColumnGroup headerGroupColumn;
        GridBoundColumn boundColumn = new GridBoundColumn();
 
        boundColumn.DataField = "report_id";
        boundColumn.HeaderText = "report_id";
        boundColumn.ItemStyle.BackColor = disabledBackColor;
        boundColumn.ItemStyle.BorderColor = defaultBorderColor;
        boundColumn.ItemStyle.BorderWidth = Unit.Pixel(1);
        boundColumn.ReadOnly = true;
        RadGrid1.MasterTableView.Columns.Add(boundColumn);
 
 
        RadGrid1.MasterTableView.AllowMultiColumnSorting = true;
        RadGrid1.MasterTableView.SortExpressions.Clear();
        GridSortExpression expression = new GridSortExpression();
        expression.FieldName = "report_id";
        expression.SortOrder = GridSortOrder.Ascending;
        RadGrid1.MasterTableView.SortExpressions.AddSortExpression(expression);
 
 
 
        DataTable GroupHeaders = WastewaterGrid.GetGroupHeaders();
        DataTable Headers;
 
        foreach (DataRow groupRow in GroupHeaders.Rows)
        {
            String masterGroupName = groupRow["group_name"].ToString();
            String groupColumnHeader = groupRow["group_column_header"].ToString();
 
            Headers = WastewaterGrid.GetHeaders(masterGroupName);
 
            headerGroupColumn = new GridColumnGroup();
            headerGroupColumn.Name = masterGroupName;
            headerGroupColumn.HeaderText = groupColumnHeader;
            RadGrid1.MasterTableView.ColumnGroups.Add(headerGroupColumn);
 
            foreach (DataRow headerRow in Headers.Rows)
            {
                String groupName = headerRow["group_name"].ToString();
                String columnName = headerRow["column_name"].ToString();
                String columnHeader = headerRow["column_header"].ToString();
                String attributeType = headerRow["attribute_type"].ToString();
                String dataType = headerRow["data_type"].ToString();
                String targetValue = headerRow["target_value"].ToString();
 
                if (!groupName.Equals(masterGroupName))
                {
                    continue;
                }
 
                boundColumn = new GridBoundColumn();
                boundColumn.DataField = columnName;
                boundColumn.HeaderText = columnHeader; // where is the uniquename?
                boundColumn.ColumnGroupName = masterGroupName;
 
                if (columnName.Equals("MISDnotes"))
                {
                    boundColumn.ItemStyle.Width = Unit.Percentage(100);
                }
 
                if (!attributeType.Equals("ManualEntry"))
                {
                    boundColumn.ItemStyle.BackColor = disabledBackColor;
                    boundColumn.ReadOnly = true;
                }
 
                RadGrid1.MasterTableView.Columns.Add(boundColumn);
            }
        }
        this.PlaceHolder1.Controls.Add(RadGrid1);
    }
 
 
    public class FooterItem
    {
        private String _columnName;
        private int _count;
        private dynamic _min;
        private dynamic _max;
        private dynamic _sum;
 
        public FooterItem(String str)
        {
            _columnName = str;
            _count = 0;
        }
 
        public String columnName
        {
            get
            {
                return _columnName;
            }
            set
            {
                _columnName = value;
            }
        }
 
        public int count
        {
            get
            {
                return _count;
            }
            set
            {
                _count = value;
            }
        }
 
        public dynamic min
        {
            get
            {
                return _min;
            }
            set
            {
                _min = value;
            }
        }
 
        public dynamic max
        {
            get
            {
                return _max;
            }
            set
            {
                _max = value;
            }
        }
 
        public dynamic sum
        {
            get
            {
                return _sum;
            }
            set
            {
                _sum = value;
            }
        }
 
         
    }
 
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        Int32 userRole = 2;
        Int32 today = int.Parse("20110907");
        //String today = DateTime.Today.ToString("yyyyMMdd");
        String columnName;
        String attributeType;
 
        GridTableCell gridCell;
        dynamic cellText;
        Boolean cellPopped = false;
        TextBox cellTextBox;
        Dictionary<String, FooterItem> FooterAggregates = new Dictionary<String, FooterItem>();
        FooterItem footerItem;
 
        DataTable Headers = WastewaterGrid.GetHeaders();
 
        foreach (DataRow row in Headers.Rows)
        {
            columnName = row["column_name"].ToString();
            attributeType = row["attribute_type"].ToString();
 
            if (!attributeType.Contains("varchar"))
            {
                FooterAggregates.Add(columnName, new FooterItem(columnName));
            }
        }
 
 
        if (e.Item is GridDataItem)
        {
            GridDataItem gridRow = (GridDataItem)e.Item;
            Int32 ReportID = int.Parse(gridRow.GetDataKeyValue("report_id").ToString());
            System.Drawing.Color defaultBorderColor = System.Drawing.Color.Black;
            System.Drawing.Color ableBackColor = System.Drawing.Color.White;
            System.Drawing.Color disabledBackColor = System.Drawing.Color.AliceBlue;
            System.Drawing.Color ableBorderColor = System.Drawing.Color.Lime;
 
            foreach (DataRow row in Headers.Rows)
            {
                columnName = row["column_name"].ToString();
                attributeType = row["attribute_type"].ToString();
                 
                gridCell = (GridTableCell)gridRow[columnName];
                //cellText = gridCell.Text;
                cellText = ((DataRowView)gridRow.DataItem)[columnName];
 
                cellPopped = !String.IsNullOrEmpty((String)cellText);
 
                if (cellPopped)
                {
                    footerItem = FooterAggregates[columnName];
 
                    footerItem.count += 1;
 
                    if (footerItem.min == null)
                    {
                        footerItem.min = cellText;
                    }
                    else
                    {
                        if (footerItem.min > cellText)
                        {
                            footerItem.min = cellText;
                        }
                    }
 
                    if (footerItem.max == null)
                    {
                        footerItem.max = cellText;
                    }
                    else
                    {
                        if (footerItem.max < cellText)
                        {
                            footerItem.max = cellText;
                        }
                    }
 
                    if (footerItem.sum == null)
                    {
                        footerItem.sum = cellText;
                    }
                    else
                    {
                        footerItem.sum += cellText;
                    }
                }
                     
                gridCell.BorderColor = defaultBorderColor;
                gridCell.BorderWidth = Unit.Pixel(1);
 
                if (userRole == 1)
                {
 
                    if (attributeType.Equals("ManualEntry"))
                    {
                        gridCell.BackColor = ableBackColor;
                        gridCell.BorderColor = ableBorderColor;
                    }
                }
                else
                {
                    if (attributeType.Equals("ManualEntry"))
                    {
                        if (!ReportID.Equals(today))
                        {
                            if (String.IsNullOrEmpty(cellText))
                            {
                                gridCell.BackColor = ableBackColor;
                                gridCell.BorderColor = ableBorderColor;
                            }
                            else
                            {
                                gridCell.BackColor = disabledBackColor;
                            }
                        }
                        else
                        {
                            gridCell.BackColor = ableBackColor;
                            gridCell.BorderColor = ableBorderColor;
                        }
                    }
 
                    if (e.Item.IsInEditMode && !ReportID.Equals(today) && cellPopped)
                    {
                        cellTextBox = (TextBox)gridCell.Controls[0];
                        cellTextBox.BorderStyle = BorderStyle.None;
                        cellTextBox.BackColor = disabledBackColor;
                        cellTextBox.ReadOnly = true;
 
                        //Label1.Text += "EditMode::ReportID=" + ReportID + "columnName=" + columnName + "::cellText=" + cellText + " <br>";
                    }
                }
            }
        }
 
        if (e.Item is GridFooterItem)
        {
            GridFooterItem gridRow = (GridFooterItem)e.Item;
            int count = 0;
            dynamic min;
            dynamic max;
            dynamic sum;
 
            foreach (DataRow row in Headers.Rows)
            {
                columnName = row["column_name"].ToString();
                attributeType = row["attribute_type"].ToString();
 
                gridCell = (GridTableCell)gridRow[columnName];
                //cellText = gridCell.Text;
                cellText = ((DataRowView)gridRow.DataItem)[columnName];
 
                footerItem = FooterAggregates[columnName];
 
                count += footerItem.count;
 
            }
        }
    }
 
 
 
 
 
    private void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
    {
        Label1.Text += " Table to be updated: " + e.Item.OwnerTableView.DataMember + "<br>";
 
        GridEditableItem editedItem = e.Item as GridEditableItem;
        GridEditManager editMan = editedItem.EditManager;
 
        Int32 ReportID = int.Parse(editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["report_id"].ToString());
        String Login = "David-T420s\\davidk";
 
        foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
        {
            if (column.UniqueName.Equals("report_id"))
            {
                continue;
            }
 
            if (column is IGridEditableColumn)
            {
                Boolean isEditable = column.IsEditable;
                String editColumnName = column.UniqueName.ToString();
                String ResultString;
 
                IGridEditableColumn editableCol = (column as IGridEditableColumn);
                if (editableCol.IsEditable)
                {
                    IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
 
                    if (editor is GridTextColumnEditor)
                    {
                        String Datum = (editor as GridTextColumnEditor).Text.Trim();
 
                        DataTable Headers = WastewaterGrid.GetHeaders();
                        foreach (DataRow row in Headers.Rows)
                        {
                            String columnName = row["column_name"].ToString();
                            String dataType = row["data_type"].ToString();
 
                            if (columnName.Equals(editColumnName))
                            {
                                ResultString = ValidateUserInput(dataType, Datum);
                                if (!ResultString.Equals("valid"))
                                {
                                    RadAjaxManager1.Alert(ResultString);
 
                                    e.Canceled = true;
                                    break;
                                }
                                else
                                {
                                    try
                                    {
                                        WastewaterGrid.UpsertDatum(ReportID, editColumnName, Datum, Login);
                                    }
                                    catch (Exception ex)
                                    {
                                        Label1.Text += "<strong>Unable to set value of column '" + column.UniqueName + "'</strong>  <br>" + ex.Message;
                                        RadAjaxManager1.Alert("Unable to set value of column: " + column.UniqueName + "; " + ex.Message);
                                        e.Canceled = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 
        try
        {
            WastewaterGrid.ReCalculate(ReportID);
        }
        catch (Exception ex)
        {
            RadAjaxManager1.Alert("Unable to run ReCalculate: " + ex.Message);
            e.Canceled = true;
        }
    }
 
     
     
    private String ValidateUserInput(String dataType, String Datum)
    {
        if (String.IsNullOrEmpty(Datum))
        {
            return "valid";
        }
 
        Match match;
        String ResultString;
        String TestString;
        Int32 stringLength = Datum.Length;
 
        String IntPattern = @"^\d+$";
        RadAjaxManager1.Alert("VALIDATEUSERINPUT: dataType=\"" + dataType + "\"; Datum=\"" + Datum + "\"");
 
        switch (dataType)
        {
            case "bigint":
                match = Regex.Match(Datum, IntPattern);
                if (match.Success)
                {
                    try
                    {
                        TestString = Int64.Parse(Datum).ToString();
                    }
                    catch (OverflowException)
                    {
                        return "Overflow Exception: improper " + dataType + "format in \"" + Datum + "\"";
                    }
                }
                else
                {
                    return "Improper format: Int64";
                }
                break;
 
            case "decimal(10,2)":
                ResultString = ValidateDecimalFormat(dataType, Datum, stringLength, 10, 2);
                if (!ResultString.Equals("valid"))
                {
                    return ResultString;
                }
                else
                {
                    try
                    {
                        TestString = Decimal.Parse(Datum).ToString();
                    }
                    catch (OverflowException)
                    {
                        return "Overflow Exception: improper " + dataType + "format in \"" + Datum + "\"";
                    }
                }
                break;
            case "decimal(10,3)":
                ResultString = ValidateDecimalFormat(dataType, Datum, stringLength, 10, 3);
                if (!ResultString.Equals("valid"))
                {
                    return ResultString;
                }
                else
                {
                    try
                    {
                        TestString = Decimal.Parse(Datum).ToString();
                    }
                    catch (OverflowException)
                    {
                        return "Overflow Exception: improper " + dataType + "format in \"" + Datum + "\"";
                    }
                }
                break;
            case "decimal(4,1)":
                ResultString = ValidateDecimalFormat(dataType, Datum, stringLength, 4, 1);
                if (!ResultString.Equals("valid"))
                {
                    return ResultString;
                }
                else
                {
                    try
                    {
                        TestString = Decimal.Parse(Datum).ToString();
                    }
                    catch (OverflowException)
                    {
                        return "Overflow Exception: improper " + dataType + "format in \"" + Datum + "\"";
                    }
                }
                break;
            case "decimal(5,1)":
                ResultString = ValidateDecimalFormat(dataType, Datum, stringLength, 5, 1);
                if (!ResultString.Equals("valid"))
                {
                    return ResultString;
                }
                else
                {
                    try
                    {
                        TestString = Decimal.Parse(Datum).ToString();
                    }
                    catch (OverflowException)
                    {
                        return "Overflow Exception: improper " + dataType + "format in \"" + Datum + "\"";
                    }
                }
                break;
            case "decimal(6,1)":
                ResultString = ValidateDecimalFormat(dataType, Datum, stringLength, 6, 1);
                if (!ResultString.Equals("valid"))
                {
                    return ResultString;
                }
                else
                {
                    try
                    {
                        TestString = Decimal.Parse(Datum).ToString();
                    }
                    catch (OverflowException)
                    {
                        return "Overflow Exception: improper " + dataType + "format in \"" + Datum + "\"";
                    }
                }
                break;
            case "int":
                match = Regex.Match(Datum, IntPattern);
                if (match.Success)
                {
                    try
                    {
                        TestString = Int32.Parse(Datum).ToString();
                        //throw new CustomExceptions.
                    }
                    catch (OverflowException)
                    {
                        return "Overflow Exception: improper " + dataType + "format in \"" + Datum + "\"";
                    }
                }
                else
                {
                    return "Improper format: Int32";
                }
                break;
            case "varchar(25)":
                if (stringLength > 25)
                {
                    return "Improper " + dataType + "format in \"" + Datum + "\"";
                }
                break;
 
            case "varchar(255)":
                if (stringLength > 255)
                {
                    return "Improper " + dataType + "format in \"" + Datum + "\"";
                }
                break;
            default:
                RadAjaxManager1.Alert("Unhandled data type");
                return "Unhandled data type: \"" + dataType + "\"";
        }
        return "valid";
    }
 
    private String ValidateDecimalFormat(String dataType, String Datum, int stringLength, int precision, int scale)
    {
        Match match;
        String IntPattern = @"^\d+$";
        String ResultString;
        Int32 decimalIndex = Datum.IndexOf(".");
 
        if (decimalIndex > 0)
        {
            Int32 fractionalLength = stringLength - decimalIndex - 1;
 
            if (fractionalLength > scale)
            {
                return "Improper " + dataType + "format in \"" + Datum + "\"";
            }
 
            Int32 integralLength = stringLength - fractionalLength - 1;
 
            if (integralLength > (precision - scale))
            {
                return "Improper " + dataType + "format in \"" + Datum + "\"";
            }
 
            String integralString = Datum.Substring(0, decimalIndex);
            String fractionalString = Datum.Substring(decimalIndex + 1, fractionalLength);
            match = Regex.Match(integralString, IntPattern);
            if (match.Success)
            {
                match = Regex.Match(fractionalString, IntPattern);
                if (match.Success)
                {
                    ResultString = "valid";
                }
                else
                {
                    ResultString = "Improper " + dataType + "format in \"" + Datum + "\"";
                }
            }
            else
            {
                ResultString = "Improper " + dataType + "format in \"" + Datum + "\"";
            }
 
        }
        else if (stringLength > (precision - scale))
        {
            ResultString = "Improper " + dataType + "format in \"" + Datum + "\"";
        }
        else
        {
            match = Regex.Match(Datum, IntPattern);
            if (match.Success)
            {
                ResultString = "valid";
            }
            else
            {
                ResultString = "Improper " + dataType + "format in \"" + Datum + "\"";
            }
        }
 
        return ResultString;
    }
}


Thanks,
David
David
Top achievements
Rank 1
 answered on 08 Oct 2012
3 answers
296 views
Hi 

I have a RadGrid on my aspx page with no columns defined as follows:

    <telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowSelection="True" Skin="Metro"
        GroupingEnabled="true" ShowGroupPanel="True" GridLines="None" EnableLinqExpressions="false">
        <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true">
            <Excel Format="ExcelML" />
        </ExportSettings>
        <MasterTableView TableLayout="Fixed" AutoGenerateColumns="true" Width="100%" CommandItemDisplay="Top"
            AllowMultiColumnSorting="True" GroupLoadMode="Server" ShowGroupFooter="true"
            AllowSorting="True" AllowPaging="True" PageSize="20" ShowFooter="false" HeaderStyle-HorizontalAlign="left"
            FooterStyle-HorizontalAlign="Right" EnableHeaderContextMenu="true" EnableHeaderContextAggregatesMenu="true"
            AllowFilteringByColumn="True" HeaderStyle-BackColor="Black" HeaderStyle-ForeColor="White">
            <CommandItemSettings ShowExportToExcelButton="true" />
            <NoRecordsTemplate>
                <div class="NoRecordsTemplate">
                    No records to view</div>
            </NoRecordsTemplate>
        </MasterTableView>
        <ClientSettings AllowDragToGroup="true" EnableRowHoverStyle="true" AllowColumnsReorder="true"
            ReorderColumnsOnClient="true">
            <Selecting AllowRowSelect="True"></Selecting>
            <Resizing AllowResizeToFit="true" AllowColumnResize="True" EnableRealTimeResize="True">
            </Resizing>
        </ClientSettings>
        <GroupingSettings CaseSensitive="false" ShowUnGroupButton="True" RetainGroupFootersVisibility="true" />
        <PagerStyle Mode="NextPrevNumericAndAdvanced" />
    </telerik:RadGrid> 

On my code-behind page I populate the RadGrid using the GetDataTable function as follows:

    Public Function GetDataTable(ByVal query As String) As DataTable
        Dim ConnString As String = ConfigurationManager.ConnectionStrings("SQLConn").ConnectionString
        Dim conn As SqlConnection = New SqlConnection(ConnString)
        Dim adapter As SqlDataAdapter = New SqlDataAdapter
        adapter.SelectCommand = New SqlCommand(query, conn)
        Dim table1 As New DataTable
        conn.Open()
        Try
            adapter.Fill(table1)
        Finally
            conn.Close()
        End Try
        Return table1
    End Function

What I am trying to do is hide the filter icon, set AutoPostBackOnFilter=True and set filter width to auto fit programmatically.

I was able to hide the filter icon by using the following:
    <style>
        .RadGrid .rgFilter
        {
            display: none;
        }
    </style>

However, I can't figure how to set AutoPostBackOnFilter=True and set filter width to auto fit programmatically.

How can I accomplish this?

Thanks,

Sigi Perez

 
Sigifredo
Top achievements
Rank 1
 answered on 08 Oct 2012
4 answers
220 views

I need to add a default value to one of the textboxes when adding a new item in the grid

<telerik:GridTemplateColumn HeaderText="Activity ID" SortExpression="activityID" UniqueName="activityID"  >

                    <ItemTemplate>

                        <%# Eval("activityID")%>

                    </ItemTemplate>

                    <EditItemTemplate>

                        <asp:TextBox runat="server" ID="txtActivity" Text='<%# Bind("activityID") %>' />

                        <asp:RequiredFieldValidator runat="server" ID="rfvActivity" ControlToValidate="txtActivity" Display="Dynamic" ErrorMessage="*" />

                    </EditItemTemplate>

                </telerik:GridTemplateColumn>

 

 

When clicking “Add new recored” I need to pre-populate the txtActivity textbox. How can I access this from the code behind?

 

I tried this with no success

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)

        {

            if (e.CommandName == RadGrid.InitInsertCommandName)

            {

                GridEditableItem editedItem = e.Item as GridEditableItem;

                TextBox t = (TextBox)(editedItem.FindControl("txtActivity"));

            }

        }

 

And this:

 

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

        {

            if (e.Item is GridCommandItem && e.Item.OwnerTableView.IsItemInserted)

            {               

                TextBox txtActivity = (TextBox)e.Item.FindControl("txtActivity");

                txtActivity.Text = "300";

            }

}

I am running out of ideas.

Please help. Thanks

Kati
Top achievements
Rank 1
 answered on 08 Oct 2012
1 answer
74 views
Hello,
I have following code:

<telerik:GridDateTimeColumn FilterControlWidth="140px" DataField="Datum" HeaderText="Datum"
    SortExpression="Datum" UniqueName="Datum" PickerType="DateTimePicker"
    EnableRangeFiltering="true" CurrentFilterFunction="Between" ReadOnly="True" AllowFiltering="True" FilterListOptions="VaryByDataType">
    <HeaderStyle Width="220px" />
</telerik:GridDateTimeColumn>

I would like to implement followin: After one of two dates will be picked second one should be set to the same value. How I can implement this behaviour with the simplest solution?


Angel Petrov
Telerik team
 answered on 08 Oct 2012
1 answer
58 views
Have a simple question -  the purpose of this is to reduce the data transferred during every page request. 
Is there any way that when there is a postback, I can SELECTIVELY bind the data belonging to THAT specific page on the RadGrid?

The issue is that in our application, we have a grid.  We show maybe only 20 rows per page. There maybe twenty such pages.  When any one particular row is edited, I am rebinding the grid with ALL the data that fills up ALL the pages. I wish there is some way that I could rebind only the data that the user is looking at on that specific page.

Thanks in adavance for your response.
Angel Petrov
Telerik team
 answered on 08 Oct 2012
1 answer
65 views
I created a new page with code from a grid from another page.  For some reason, when I expand the rows, the page performs a post back to the server.  I have the HierarchyLoadMode for the MasterTableView set to "Client".  This works on the other page just fine.  Any ideas?

<rad:RadGrid ID="GridSummary" runat="server" OnColumnCreated="Grid_ColumnCreated"
    OnItemCreated="Grid_ItemCreated" OnItemDataBound="Grid_ItemDataBound"
    EnableEmbeddedSkins="false" Skin="MetroMagenta" Width="900px" AutoGenerateColumns="false">
    <MasterTableView HierarchyDefaultExpanded="true" HierarchyLoadMode="Client"
        OnDataBound="Grid_DataBound"
        DataKeyNames="RecordId, ParentRecordId, RecordName"
        <SelfHierarchySettings ParentKeyName="ParentRecordId" KeyName="RecordId" />
        <Columns>
            <rad:GridBoundColumn DataField="RecordName" UniqueName="RecordName" HeaderText="" />
            <rad:GridBoundColumn DataField="SocialVolume" UniqueName="SocialVolume" HeaderText="Social Volume"  HeaderStyle-Width="150px" ItemStyle-Width="150px" />
            <rad:GridBoundColumn DataField="CaseVolume" UniqueName="CaseVolume" HeaderText="Case Volume"  HeaderStyle-Width="150px" ItemStyle-Width="150px" />
            <rad:GridBoundColumn DataField="HelpVolume" UniqueName="HelpVolume" HeaderText="Help Volume"  HeaderStyle-Width="150px" ItemStyle-Width="150px" />
        </Columns>
    </MasterTableView>
    <ClientSettings AllowExpandCollapse="true" />
</rad:RadGrid>
Angel Petrov
Telerik team
 answered on 08 Oct 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?