Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Telerik
Situation: i have this radgrid (radgrid1) in which 5 columns are readonly, the other columns are given to user so user can enter new data in it, scanario is like entering the data into column6 and it will multiply it with column3 (readonly) and i will display the result in column 7.
Problem: I need to do it without the post back event. i do not want to bind/rebind the grid. the method i am using right now works fine but it have to fire PostBack and then change value in grid. i need "Some solution with better performance"
 

Code for ItemBound : to enable TextChanged event and AutoPostBacks
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
 
            if (e.Item is GridDataItem)
            {
                GridDataItem item = e.Item as GridDataItem; 
 
                foreach (GridColumn column in item.OwnerTableView.RenderColumns)
                {
                    if (column.UniqueName == "sItemUnitCost")
                    {
                        RadTextBox txt = new RadTextBox();
                        txt.Text = ((RadTextBox)item.FindControl("TextBox50")).Text ;
                        txt.TextChanged += new EventHandler(txt_TextChanged);
                        txt.AutoPostBack = true;
                        txt.ToolTip = item["column"].Text;
                        txt.Width = 30;
                        item[column].Controls.Clear();
                        item[column].Controls.Add(txt);
                    }
                }
            }
        }
Code For OnTextChanged event handler:
 protected void txt_TextChanged(object sender, EventArgs e)
        {
            RadTextBox txt = (RadTextBox)sender;
            foreach (System.Data.DataRow drow in WS1.dt.Rows)
            {
                if (string.Compare((string)drow["itemLineNo"], txt.ToolTip, true) == 0)
                {
                    drow["sitemUnitCost"] = txt.Text;
                    drow["sItemCostAmount"] = int.Parse(drow["itemQuantity"].ToString()) * double.Parse(txt.Text);
                }
            }
        }
 
code for grid: (columns are(Quantity * Unit Cost = Cost Ammount) )
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"
            AllowSorting="True" AutoGenerateColumns="False" AutoGenerateEditColumn="True"
            CellSpacing="0" GridLines="None" Skin="WebBlue"
            OnUpdateCommand="RadGrid1_UpdateCommand"
            OnEditCommand="RadGrid1_EditCommand" OnItemCommand="RadGrid1_ItemCommand"
            AllowMultiRowEdit="True"  EnableViewState="False" OnNeedDataSource="HandlerGridOnNeedDataSource"
             AllowAutomaticUpdates="True" OnItemDataBound ="RadGrid1_ItemDataBound"
            >
        <clientsettings allowcolumnsreorder="True" reordercolumnsonclient="True">
            <Selecting AllowRowSelect="True" />
        </clientsettings>
        <mastertableview EditMode="InPlace">
            <commanditemsettings exporttopdftext="Export to PDF" />
            <rowindicatorcolumn filtercontrolalttext="Filter RowIndicator column">
                <HeaderStyle Width="20px" />
            </rowindicatorcolumn>
            <expandcollapsecolumn filtercontrolalttext="Filter ExpandColumn column">
                <HeaderStyle Width="20px" />
            </expandcollapsecolumn>
            <Columns>
 
                <telerik:GridBoundColumn DataField="itemLineNo"
                    FilterControlAltText="Filter column column" HeaderText="Line No"
                    ReadOnly="True" UniqueName="column" EmptyDataText="Volume">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="itemName"
                    FilterControlAltText="Filter column1 column" HeaderText="Name" ReadOnly="True"
                    UniqueName="column1">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="itemPartNo"
                    FilterControlAltText="Filter column2 column" HeaderText="Part No"
                    ReadOnly="True" UniqueName="column2">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="itemShortDsc"
                    FilterControlAltText="Filter column3 column" HeaderText="Short Description"
                    ReadOnly="True" UniqueName="column3">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="itemLongDsc"
                    FilterControlAltText="Filter column4 column" HeaderText="Description"
                    ReadOnly="True" UniqueName="column4">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="itemQuantity"
                    FilterControlAltText="Filter column5 column" HeaderText="Quantity"
                    ReadOnly="True" UniqueName="column5" DataType="System.Int32">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="itemUOM"
                    FilterControlAltText="Filter column6 column" HeaderText="UOM" ReadOnly="True"
                    UniqueName="column6">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn HeaderText="Unit Cost" UniqueName="sItemUnitCost"
                    DataField="sItemUnitCost" DataType="System.Double" >
                <ItemTemplate>
                    <telerik:RadTextBox id="Textbox50" Runat="server" Text='<%# Eval("sItemUnitCost") %> '   />
                </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="sItemCostAmount"
                    FilterControlAltText="Filter column7 column" HeaderText="Cost Amount"
                    UniqueName="column7" DataType="System.Double">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn HeaderText="Weight (LBS)" UniqueName="sItemWeightLBS"
                    DataField="sItemWeightLBS" DataType="System.Double" >
                <ItemTemplate>
                    <telerik:RadTextBox id="Textbox51" Runat="server" Text='<%# Eval("sItemWeightLBS") %> '   />
                </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridButtonColumn CommandName="calcVolume"
                    DataTextField="sItemVolCuInch" FilterControlAltText="Filter column8 column"
                    HeaderText="Volume Cu Inch" UniqueName="column8" DataType="System.Double">
                </telerik:GridButtonColumn>
            <telerik:GridDropDownColumn FilterControlAltText="Filter column9 column"
                    HeaderText="Lead Time" UniqueName="column9">
                </telerik:GridDropDownColumn>
 
            </Columns>
            <editformsettings>
                <editcolumn filtercontrolalttext="Filter EditCommandColumn column">
                </editcolumn>
            </editformsettings>
        </mastertableview>
        <filtermenu enableimagesprites="False">
        </filtermenu>
        <headercontextmenu cssclass="GridContextMenu GridContextMenu_Default">
        </headercontextmenu>
        </telerik:RadGrid>
Code For Grid refresh without grid databind
 
<telerik:RadAjaxManager ID="RadAjaxManager1" DefaultLoadingPanelID="RadAjaxLoadingPanel1"
        runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="controlID">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="radGrid1"  />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
Posted 23-Nov-12 4:19am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 PIEBALDconsult 150
3 BillWoodruff 148
4 Jochen Arndt 135
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100