This is a migrated thread and some comments may be shown as answers.

Solution For Item databound

3 Answers 117 Views
Grid
This is a migrated thread and some comments may be shown as answers.
nagendra
Top achievements
Rank 1
nagendra asked on 30 Oct 2010, 10:35 AM
I want to pass UpdatebuttonClientID on to javacript method in item databound.. to make update button  enable or  disable it if quantity assinged is more than the  available quantity. so detail bind method onfocusout event i need to pass the button client id. how to know which row is expaned or not.... i need to pass details of radtextbox id and update buttonid and available quantity.. please give solution it z very urgent...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CostBasisLotSelection.aspx.cs" Inherits="CostBasis.CostBasisLotSelection" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title>Cost Basis Lot Selection Screen</title>
    <link href="css/Default.css" rel="stylesheet" type="text/css" />
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
 
        <script type="text/javascript">
 
 
            var sumInput = null;
            var tempValue = 100;
 
            function Load(sender, args) {
                sumInput = sender;
                sumInput.set_value(tempValue);
            }
 
            function Blur(sender, args) {
                alert(tempValue);
                sumInput.set_value(tempValue - sender.GetValue());
            }
             
            function Focus(sender, args) {
                tempValue = sumInput.get_value() - sender.get_value();
            }
             
            function letternumber(e) {
 
               
                var key;
                var keychar;
 
                if (window.event)
                    key = window.event.keyCode;
                else if (e)
                    key = e.which;
                else
                    return true;
                keychar = String.fromCharCode(key);
                keychar = keychar.toLowerCase();
 
                // control keys
                if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27))
                    return true;
 
                // alphas and numbers
                else if ((("abcdefghijklmnopqrstuvwxyz0123456789").indexOf(keychar) > -1))
                    return true;
                else
                    return false;
            }
 
            function ClientValidate(source, arguments) {
                var DateTo = document.getElementById("dtToDate_dateInput_text").value;
                var DateFrom = document.getElementById("dtFromDate_dateInput_text").value;
                var dtto = new Date(DateTo);
                var dtFrom = new Date(DateFrom);
                if (DateFrom == undefined) {
                    arguments.IsValid = true;
 
                } else {
                    if (DateFrom > DateTo) {
                        arguments.IsValid = false;
                    } else {
                        arguments.IsValid = true;
                    }
                }
            }
            function OnKeyPress(sender, eventArgs) {
                var c = eventArgs.get_keyCode();
                if ((c < 47) || (c > 57))
                    eventArgs.set_cancel(true);
            }
            function calculate(price, quantity) {
                var text1 = $find(price).get_value(); //I used Asp.net Ajax find method
                var text2 = quantity;
                //alert(text1 + " == "+text2)
                if (text1 >= text2) {
                    //alert("here");
                   
                    text1.focus();
                   
                }
//                var text3 = $find(totalAmount);
//                var total = text1.GetValue() * text2.GetValue();
//                text3.SetValue(total);
            }  
 
   
        </script>
    </telerik:RadCodeBlock>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="Scriptmanager1" runat="server">
    </asp:ScriptManager>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="btnGo">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="pnlTaxLotsSearch" LoadingPanelID="LoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="btnTaxLotsGo">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rgCostBasisTrades"  />
                    <telerik:AjaxUpdatedControl ControlID="pnlTaxLotsSearch"  />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="rgCostBasisTrades">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rgCostBasisTrades" LoadingPanelID="LoadingPanel3" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="LoadingPanel1" runat="server" Style="padding-top: 45px;padding-left: 35px;"
        Height="75px" Width="75px" IsSticky="false" Transparency="30">
        <img alt="Loading..." src="img/loadingReport.gif" style="border: 0;" />
    </telerik:RadAjaxLoadingPanel>
        <telerik:RadAjaxLoadingPanel ID="LoadingPanel2" runat="server" Style="padding-top: 85px;padding-left: 15px;"
        Height="75px" Width="75px" IsSticky="false" Transparency="30">
        <img alt="Loading..."  src="img/loadingReport.gif"  style="border: 0;" />
    </telerik:RadAjaxLoadingPanel>
    </telerik:RadAjaxLoadingPanel>
        <telerik:RadAjaxLoadingPanel ID="LoadingPanel3" runat="server"
        Style="padding-top: 65px;padding-left: 20px;" IsSticky="false"
        Transparency="30">
        <img alt="Loading..."  src="img/loadingReport.gif"  style="border: 0;" />
    </telerik:RadAjaxLoadingPanel>
     <table border="0" cellpadding="4" cellspacing="0" width="100%">
        <tr class="PageTitle" valign="middle">
            <td>
                <span id="lblTitle" class="PageTitle">• Cost Basis Lot Selection Screen •</span>
            </td>
        </tr>
        <tr>
            <td>
                <table width="100%">
                    <tr>
                        <td>
                            <table width="100%">
                                <tr>
                                    <td style="width: 33%">
                                        <asp:Panel runat="server" ID="pnlCustAcctNo" Visible="true" GroupingText="Customer Account Number"
                                            Height="55px" Width="100%" HorizontalAlign="Center">
                                            <table>
                                                <tr valign="middle">
                                                    <td style="height: 35px;width:65%">
                                                        <asp:RequiredFieldValidator ID="rfdtxtCustAcctNo" Display="None" runat="server" ControlToValidate="txtCustAcctNo"
                                                            ValidationGroup="gpUser" ErrorMessage=" Enter Account Number"></asp:RequiredFieldValidator>
                                                        <telerik:RadTextBox ID="txtCustAcctNo" MaxLength="12" Skin="Office2007" CssClass="SMALLERTEXT" OnKeyPress="return letternumber(event);"
                                                            runat="server">
                                                        </telerik:RadTextBox>
                                                        <cc1:ValidatorCalloutExtender ID="valrqdFname_ValidatorCalloutExtender" runat="server"
                                                            Width="15px" TargetControlID="rfdtxtCustAcctNo">
                                                        </cc1:ValidatorCalloutExtender>
                                                    </td>
                                                    <td>
                                                        <asp:Button ID="btnGo" Enabled="true"  OnClick="btnGo_Click" ValidationGroup="gpUser"
                                                                        runat="server" BorderStyle="None" CssClass="Buttons2" Text="Go" />
                                                    </td>
                                                </tr>
                                            </table>
                                        </asp:Panel>
                                    </td>
                                    <td style="width: 67%">
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                   
                    <tr>
                        <td>
                            <table width="100%">
                                <tr>
                                    <td style="width: 83%">
                                        <asp:Panel runat="server" ID="pnlTaxLotsSearch" Enabled="false" Visible="true" GroupingText="Tax Lots Search"
                                            Height="110px" HorizontalAlign="Center">
                                            <table class="selectedPage" width="97%" style="height: 70px">
                                                <tr>
                                                    <td>
                                                        <asp:CustomValidator ID="cstValFrmDate" runat="server" ControlToValidate="dtFromDate"
                                                            ClientValidationFunction="ClientValidate" Display="None" ErrorMessage="From Date should be Less than To Date"
                                                            ValidationGroup="GpTaxLot">      
                                                        </asp:CustomValidator>
                                                    </td>
                                                </tr>
                                                <tr align="left" >
                                                    <td style="width: 24%">
                                                        <asp:Label ID="lblTaxLots" CssClass="SMALLERTEXTBOLD1" runat="server" Text="Tax Lots :"></asp:Label>
                                                    </td>
                                                    <td style="width: 26%">
                                                        <asp:RadioButtonList ID="rblSymbolCusip" Height="5px" CssClass="SMALLERTEXTBOLD1" runat="server" RepeatDirection="Horizontal">
                                                            <asp:ListItem Selected="True" Text="Symbol" Value="S"></asp:ListItem>
                                                            <asp:ListItem Text="Cusip" Value="C"></asp:ListItem>
                                                        </asp:RadioButtonList>
                                                    </td>
                                                    <td style="width: 24%">
                                                        <asp:Label ID="lblFromDate" CssClass="SMALLERTEXTBOLD1" runat="server" Text="From :"></asp:Label>
                                                    </td>
                                                    <td style="width: 24%">
                                                        <asp:Label ID="lblToDate" CssClass="SMALLERTEXTBOLD1" runat="server" Text="To :"></asp:Label>
                                                    </td>
                                                    <td style="width: 2%">
                                                    </td>
                                                </tr>
                                                <tr valign="top" align="left">
                                                    <td >
                                                        <telerik:RadComboBox ID="cmdTaxLots" runat="server" Width="110px" MarkFirstMatch="True"
                                                            Skin="Office2007" ToolTip="Select Tax Lots">
                                                            <Items>
                                                                <telerik:RadComboBoxItem Text="All" />
                                                                <telerik:RadComboBoxItem Text="Open Lots" />
                                                                <telerik:RadComboBoxItem Text="Closed Lots" />
                                                            </Items>
                                                        </telerik:RadComboBox>
                                                    </td>
                                                    <td style="width: 23%" >
                                                        <telerik:RadTextBox ID="txtSymbolCusip" Width="110px" Skin="Office2007" CssClass="SMALLERTEXT"
                                                            runat="server">
                                                        </telerik:RadTextBox>
                                                    </td>
                                                    <td>
                                                        <telerik:RadDatePicker ID="dtFromDate" Width="110px" runat="server" ToolTip="Select Date" Skin="Office2007"
                                                            Culture="English (United States)" >
                                                            <dateinput labelcssclass="radLabelCss_Office2007" DateFormat="MM/dd/yyyy"  skin="Office2007">
                                                            <ClientEvents OnKeyPress="OnKeyPress" />
                                                            </dateinput>
                                                            <calendar showrowheaders="False" skin="Office2007"
                                                                usecolumnheadersasselectors="False" userowheadersasselectors="False"
                                                                viewselectortext="x">
                                                                <specialdays>
                                                                <telerik:RadCalendarDay Date="" IsToday="True" Repeatable="Today">
                                                                    <ItemStyle CssClass="rcToday" BorderColor="Red" BorderStyle="NotSet" />
                                                                    </telerik:RadCalendarDay>
                                                                </specialdays>
                                                            </calendar>                                                           
                                                            <datepopupbutton cssclass="radPopupImage_Office2007" />
                                                        </telerik:RadDatePicker>
                                                    </td>
                                                    <td>
                                                        <telerik:RadDatePicker ID="dtToDate" Width="110px" ShowRowHeaders="false" runat="server"
                                                            ToolTip="Select Date" Skin="Office2007" Culture="English (United States)">
                                                            <dateinput labelcssclass="radLabelCss_Office2007" DateFormat="MM/dd/yyyy"  skin="Office2007">
                                                            <ClientEvents OnKeyPress="OnKeyPress" />
                                                            </dateinput>
                                                            <calendar showrowheaders="False" skin="Office2007"
                                                                usecolumnheadersasselectors="False" userowheadersasselectors="False"
                                                                viewselectortext="x">
                                                                <specialdays>
                                                                <telerik:RadCalendarDay Date="" IsToday="True" Repeatable="Today">
                                                                    <ItemStyle CssClass="rcToday" BorderColor="Red" BorderStyle="Solid" />
                                                                    </telerik:RadCalendarDay>
                                                                </specialdays>
                                                            </calendar>
                                                            <datepopupbutton cssclass="radPopupImage_Office2007" />
                                                        </telerik:RadDatePicker>
                                                        <cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" runat="server" Width="30 px"
                                                            TargetControlID="cstValFrmDate">
                                                        </cc1:ValidatorCalloutExtender>
                                                    </td>
                                                    <td>
                                                        <asp:Button ID="btnTaxLotsGo" runat="server" BorderStyle="None" CausesValidation="true"
                                                            ValidationGroup="GpTaxLot" CssClass="Buttons2" OnClick="btnTaxLotGo_Click" Text="Go" />
                                                    </td>
                                                     <td style="width: 100px">
                                                    </td>
                                                </tr>
                                            </table>
                                        </asp:Panel>
                                    </td>
                                    <td style="width: 17%">
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <table width="90%" style="height:100%">
                    <tr>
                        <td>
                            <telerik:RadGrid ID="rgCostBasisTrades" runat="server" AllowMultiRowSelection="false"
                                AllowPaging="false" ShowHeader="true"  OnItemCommand="rgCostBasisTrades_ItemCommand" AllowSorting="false" OnNeedDataSource="rgCostBasisTrades_NeedDataSource"
                                OnItemDataBound="rgCostBasisTrades_ItemDataBound"
                                OnItemUpdated="rgCostBasisTrades_UpdateCommand" OnDetailTableDataBind="rgCostBasisTrades_DetailTableDataBind"
                                AutoGenerateColumns="False" GridLines="None" Height="200px" LoadingTemplateTransparency="25"
                                AlternatingItemStyle-BackColor="AliceBlue" Visible="true"
                                Skin="Office2007" Width="100%"
                                onupdatecommand="rgCostBasisTrades_UpdateCommand1">
                                <MasterTableView TableLayout="Fixed" Name="TaxlotsMain"  >
                                    <PagerStyle Mode="NumericPages" Visible="False" />
                                    <DetailTables>
                                        <telerik:GridTableView Name="Taxlots" ShowHeader="true" runat="server" Width="100 %" ShowFooter="true">
                                            <Columns>
                                                <telerik:GridBoundColumn DataField="Symbol" HeaderButtonType="TextButton" HeaderText="Symbol"
                                                    SortExpression="Symbol" UniqueName="Symbol">
                                                    <HeaderStyle HorizontalAlign="left" Width="20%" />
                                                    <ItemStyle HorizontalAlign="left" />
                                                </telerik:GridBoundColumn>
                                                <telerik:GridTemplateColumn  DataField="Shares" HeaderButtonType="TextButton" HeaderText="Shares"
                                                    SortExpression="Shares" UniqueName="Shares">
                                                    <HeaderStyle HorizontalAlign="left" Width="20%" />
                                                    <ItemStyle HorizontalAlign="left" />
                                                    <ItemTemplate>
                                                        <asp:Label ID="lblShares" runat="server" Text='<%# Eval("Shares") %>' /> 
                                                 </ItemTemplate
 
                                                </telerik:GridTemplateColumn >
                                                <telerik:GridBoundColumn DataField="LotID" HeaderButtonType="TextButton" HeaderText="LotID"
                                                    SortExpression="LotID" UniqueName="LotID">
                                                    <HeaderStyle HorizontalAlign="left" Width="20%" />
                                                    <ItemStyle HorizontalAlign="left" />
                                                </telerik:GridBoundColumn>
                                                <telerik:GridTemplateColumn DataField="Allocation" HeaderButtonType="TextButton"
                                                    HeaderText="Allocation" SortExpression="Allocation" UniqueName="Shares">
                                                    <ItemTemplate>
                                                    <telerik:RadNumericTextBox ID="txtAllocation" Font-Size="xx-small" runat="server"
                                                        Width="80%" MinValue="1" MaxValue="999999999"  Text='<%#DataBinder.Eval(Container.DataItem, "Allocation")%>'>
                                                        <ClientEvents OnBlur="Blur" />
                                                        <NumberFormat GroupSeparator="" DecimalDigits="0" />
                                                    </telerik:RadNumericTextBox>
                                                    <asp:CompareValidator ID="CmptxtAllocation" runat="server" ErrorMessage="Enter Value Less Than Shares" 
                                                          ControlToValidate="txtAllocation"  Display="None"  Operator="LessThanEqual"></asp:CompareValidator>
                                                          <cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" runat="server" Width="50 px"
                                                            TargetControlID="CmptxtAllocation" >
                                                        </cc1:ValidatorCalloutExtender>
                                           
                                                    </ItemTemplate>
                                                    <HeaderStyle HorizontalAlign="left" Width="20%" />
                                                    <ItemStyle HorizontalAlign="left" />
                                                    <FooterStyle HorizontalAlign="Left" Width="20%" />
                                                    <FooterTemplate>
                                                       <telerik:RadNumericTextBox ID="txtTotalAllocation" Font-Size="xx-small" runat="server"  MinValue="1" MaxValue="999999999" Width="80%">
                                                        <ClientEvents OnLoad="Load" />
                                                        <NumberFormat GroupSeparator="" DecimalDigits="0" />
                                                        </telerik:RadNumericTextBox>
                                                      </FooterTemplate>
 
                                                </telerik:GridTemplateColumn>
                                            </Columns>
                                        </telerik:GridTableView>
                                    </DetailTables>
                                    <Columns>
                                        <telerik:GridBoundColumn DataField="Trade" HeaderButtonType="TextButton" HeaderText="Trade #"
                                            SortExpression="Trade" UniqueName="Trade">
                                            <HeaderStyle HorizontalAlign="left" />
                                            <ItemStyle HorizontalAlign="left" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="BS" HeaderButtonType="TextButton" HeaderText="B / S"
                                            SortExpression="BS" UniqueName="BS">
                                            <HeaderStyle HorizontalAlign="left" />
                                            <ItemStyle HorizontalAlign="left" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridTemplateColumn DataField="Allocation" HeaderButtonType="TextButton"
                                            HeaderText="Allocation" SortExpression="Allocation" UniqueName="Shares">
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridBoundColumn DataField="Symbol" HeaderButtonType="TextButton" HeaderText="Description"
                                            SortExpression="Symbol" UniqueName="Symbol">
                                            <HeaderStyle HorizontalAlign="left" />
                                            <ItemStyle HorizontalAlign="left" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="Price" HeaderButtonType="TextButton" HeaderText="Price"
                                            SortExpression="Price" UniqueName="Price">
                                            <HeaderStyle HorizontalAlign="left" />
                                            <ItemStyle HorizontalAlign="left" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="Shares" HeaderButtonType="TextButton" HeaderText="Shares"
                                            SortExpression="Shares" UniqueName="Shares">
                                            <HeaderStyle HorizontalAlign="left" />
                                            <ItemStyle HorizontalAlign="left" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridButtonColumn   ButtonType="LinkButton"  CommandName="Update"  Text="Update" UniqueName="LotUpdate">
                                        <HeaderStyle Width="60px" />
                                        
                                        </telerik:GridButtonColumn>
 
                                    </Columns>
                                </MasterTableView>
                               
                                <ClientSettings>
                <ClientEvents  />
             <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                                    <Selecting AllowRowSelect="True" />
            </ClientSettings>
                                <FilterMenu NotSelectedImageUrl="~/Skins/GridSkin/Ice/NotSelectedMenu.gif" SelectedImageUrl="~/Skins/GridSkin/Ice/SelectedMenu.gif">
                                </FilterMenu>
                            </telerik:RadGrid>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td align="center">
                <%--<asp:Button ID="btnGridUpdate" runat="server" CssClass="Buttons" Text="Update" BorderStyle="None"
                    Height="21px" Width="67px" />
                <asp:HiddenField ID="hdnActionButtonClicked" Value="false" runat="server" />--%>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
using System.IO;
using System.Configuration;
 
namespace CostBasis
{
    public partial class CostBasisLotSelection : System.Web.UI.Page
    {
        //Button btnTaxLotGo;
        //Button btnCustAcctNoGo;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
              
                //UserControl ucCustAcctNo = (UserControl)FindControl("ucCustAcctDetails");
                //ucCustAcctDetails.
                //CustAcctNo ucCostBasisDetail = (CustAcctNo)ucCustAcctNo;
                //ucCustAcctDetails.btnCustAcctNoHandler += new CustAcctNo.OnCustAcctNoButtonClick(ucCostBasisDetail_btnCustAcctNoHandler);
               // ucCustAcctDetails.btnCustAcctNoHandler += new CustAcctNo.OnCustAcctNoButtonClick(ucCustAcctDetails_btnCustAcctNoHandler);
                //TaxLotsSearch ucTaxLotSearch = (TaxLotsSearch)FindControl("ucTaxLotsSearch");
             //   ucTaxLotsSearch.btnHandler += new TaxLotsSearch.OnButtonClick(ucTaxLotSearch_btnHandler);
              //  ucTaxLotsSearch.btnHandler += new TaxLotsSearch.OnButtonClick(ucTaxLotsSearch_btnHandler);
                //UserControl ucTaxLots = (UserControl)FindControl("ucTaxLotsSearch");
               // btnTaxLotGo = (Button)ucTaxLotsSearch.FindControl("btnGo");
 
 
               // btnCustAcctNoGo = (Button)ucCustAcctDetails.FindControl("btnGo");
              //  RadTextBox txtCustAcctNo = (RadTextBox)ucCustAcctDetails.FindControl("txtCustAcctNo");
 
 
                if (!IsPostBack)
                {
                    rgCostBasisTrades.Visible = false;
                    //btnUpdate.Visible = false;
                    btnTaxLotsGo.Enabled = false;
                }
                else
                {
                    if (!txtCustAcctNo.Text.Equals(string.Empty))
                    {
                        btnGo.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
 
 
            }
 
        }
        protected void rgCostBasisTrades_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.ExpandCollapseCommandName)
            {
                GridDataItem dataItem = (GridDataItem)e.Item;
                LinkButton btnLotUpdate = (LinkButton)dataItem["LotUpdate"].Controls[0];
               
                //insert custom logic here
                if (e.Item.Expanded)
                {
                    btnLotUpdate.Enabled = false;
 
                }
            }
        }
        protected void btnGo_Click(object sender, EventArgs e)
        {
            btnTaxLotsGo.Enabled = true;
            pnlTaxLotsSearch.Enabled = true;
        }
        void ucTaxLotsSearch_btnHandler(string strValue)
        {
            
        }
 
        void ucCustAcctDetails_btnCustAcctNoHandler(string strValue)
        {
             
        }
        protected void btnTaxLotGo_Click(object sender, EventArgs e)
        {
            PopulateGrid();
        }
      
 
        //void ucTaxLotSearch_btnHandler(string strValue)
        //{
             
        //}
 
        //void ucCostBasisDetail_btnCustAcctNoHandler(string strValue)
        //{
             
        //}
 
        protected void rgCostBasisTrades_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            if (Session["ReportDefinitionGridView1"] != null)
            {
                DataSet gridViewRptDef = this.Session["ReportDefinitionGridView1"] as DataSet;
                rgCostBasisTrades.DataSource = gridViewRptDef;
                rgCostBasisTrades.DataMember = "catalog";
            }
           
        }
 
        void PopulateGrid()
        {
            rgCostBasisTrades.Visible = true;
            //btnUpdate.Visible = true;
 
            string myXMLfile = ConfigurationManager.AppSettings["CBLotSelection"];
            DataSet ds = new DataSet();
            try
            {
                ds.ReadXml(myXMLfile);
                this.Session["ReportDefinitionGridView1"] = ds;
                rgCostBasisTrades.Rebind();
                 
            }
            catch (Exception ex)
            {
            }
        }
     
        protected void rgCostBasisTrades_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.OwnerTableView.Name == "TaxlotsMain") // check with name of DetailTable
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem dataItem = (GridDataItem)e.Item;
                    LinkButton btnLotUpdate = (LinkButton)dataItem["LotUpdate"].Controls[0];
                    if (e.Item.Expanded)
                    {
                        btnLotUpdate.Enabled = true;
                    }
                    else
                    {
                        btnLotUpdate.Enabled = false;
                    }
                }
            }
            else if (e.Item.OwnerTableView.Name == "Taxlots")
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem item = (GridDataItem)e.Item;
                    RadNumericTextBox txtAllocation = item.FindControl("txtAllocation") as RadNumericTextBox;
                    Label SharesLabel = item["Shares"].FindControl("lblShares") as Label;
                    CompareValidator cmp = item.FindControl("CmptxtAllocation") as CompareValidator;
                    //cmp.ValueToCompare = Math.Round(Convert.ToDecimal(SharesLabel.Text.ToString()), 2).ToString();
                    cmp.ValueToCompare = Convert.ToString(Convert.ToInt32(SharesLabel.Text.ToString()));
                    //cmp.ValueToCompare = "100";
                   // cmp.c
                    // Get the textbox for column Price   
                    //txtAllocation.Attributes.Add("onFocusout", "return calculate('" + txtAllocation.ClientID + "','" + 100 + "','" + txtTotalAmount.ClientID + "')");
                   // txtAllocation.Attributes.Add("onFocusout", "return calculate('" + txtAllocation.ClientID + "','" + 100 + "')");
                    //    txtPrice.Attributes.Add("onFocusout", "return calculate('" + txtPrice.ClientID + "','" + txtQuantity.ClientID + "','" + txtTotalAmount.ClientID + "')");
                    //    txtQuantity.Attributes.Add("onFocusout", "return calculate('" + txtPrice.ClientID + "','" + txtQuantity.ClientID + "','" + txtTotalAmount.ClientID + "')");
                    //    txtTotalAmount.Attributes.Add("onfocus", "return calculate('" + txtPrice.ClientID + "','" + txtQuantity.ClientID + "','" + txtTotalAmount.ClientID + "')");
                    //}  
 
 
                }
 
                //GridDataInsertItem insertItem = (GridDataInsertItem)e.Item;
                //GridDataItem parentitem = (GridDataItem)insertItem.OwnerTableView.ParentItem;
                //GridTableView tableView = (GridTableView)parentitem.ChildItem.NestedTableViews[0];
                //tableView.GetColumn("EditcolumnUniqueName").Visible = true;
                //GridDataItem dataItem = (GridDataItem)ParentItem;
                //foreach (GridDataItem dataItem in rgCostBasisTrades.Items)
                //    ((LinkButton)dataItem["EditcolumnUniqueName"].Controls[0]).Visible = false;
            }
            //else
            //{
            //    foreach (GridDataItem parentitem in rgCostBasisTrades.Items)
            //    {
            //        if (parentitem.Expanded)
            //        {
            //            LinkButton btnLotUpdate = (LinkButton)parentitem["LotUpdate"].Controls[0];
            //            btnLotUpdate.Enabled = false;
            //            //GridTableView tableView = (GridTableView)parentitem.ChildItem.NestedTableViews[0];
            //            //tableView.GetColumn("EditcolumnUniqueName").Visible = false;
            //        }
            //    }
            //}
          
            //if (e.Item is GridDataItem)
            //{
            //    GridDataItem dataItem = (GridDataItem)e.Item;
            //    LinkButton btnLotUpdate = (LinkButton)dataItem["LotUpdate"].Controls[0];
            //    btnLotUpdate.Enabled = false;
            //}  
 
        }
 
        protected void rgCostBasisTrades_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
        {
            GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
 
         
            switch (e.DetailTableView.Name)
            {
                case "Taxlots":
                    {
                        LinkButton btnLotUpdate = (LinkButton)dataItem["LotUpdate"].Controls[0];
                        btnLotUpdate.Enabled = true;
                        string myXMLfile = ConfigurationManager.AppSettings["CBLotSelection2"];//Path.Combine(Environment.CurrentDirectory, @"CostBasis\XML\SampleXML21.xml"); //"C:\\Documents and Settings\\SPuttappa\\My Documents\\Visual Studio 2008\\Projects\\CostBasis\\XML\\SampleXML21.xml";
                        DataSet ds = new DataSet();
                        try
                        {
                            ds.ReadXml(myXMLfile);
                            e.DetailTableView.DataSource = ds;
                            e.DetailTableView.DataMember = "catalog";
                        }
                        catch (Exception ex)
                        {
                        }
                         break;
                    }
            }
        }
 
        protected void rgCostBasisTrades_UpdateCommand(object source, GridUpdatedEventArgs e)
        {
            
        }
 
        protected void rgCostBasisTrades_UpdateCommand1(object source, GridCommandEventArgs e)
        {
            //e.Item.OwnerTableView.ParentItem.OwnerTableView.Rebind();
        }
    }
}


3 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 04 Nov 2010, 12:43 PM
Hello Nagendra,

One option would be if you add the three ID's in one string value and save it in a HiddenField control in your page, then in javascript take the value, split it by spaces and use the three values in your script. I hope this is what you need for your scenario to work out.

Best wishes,
Tsvetina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
nagendra
Top achievements
Rank 1
answered on 05 Nov 2010, 11:14 AM
Hi Tsvetina ,

Thanks for the reply. My question was on which grid event i can get expaned master table row detail along with the detail table items . so that in code behind i can call focusout event and call the javascript.

Because i need to disable the update button which is in the master table expaned row if my condition fails. and if mulitple rows are expaned then also i should be able to pass the value. can please give me this solution.

currently i am calling the javascript in the Itemdatabound function. But i need to know the detail of master table expanded row in this event. storing the expaned row detail in the view state if expaned else removing it from it. please give any other approch.
This approach doesnot work if multiple rows are expanded..
protected void rgCostBasisTrades_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExpandCollapseCommandName)
    {
        GridDataItem dataItem = (GridDataItem)e.Item;
        LinkButton btnLotUpdate = (LinkButton)dataItem["LotUpdate"].Controls[0];
        Label lblshares = dataItem["Shares"].FindControl("lblmain") as Label;
        //Label lblshares = (Label)dataItem.FindControl["lblmain"];
        //insert custom logic here
        if (e.Item.Expanded)
        {
            btnLotUpdate.Enabled = false;
            SetShouldInitializeNestedContent(btnLotUpdate.ClientID + ":" + lblshares.Text, false);
 
        }
        else
        {
            SetShouldInitializeNestedContent(btnLotUpdate.ClientID + ":" + lblshares.Text, true);
            //if (e.Item.OwnerTableView.Name == "Taxlots")
            //{
            //    if (e.Item is GridDataItem)
            //    {
            //        GridDataItem items = (GridDataItem)e.Item;
            //        RadNumericTextBox txtAllocation = items.FindControl("txtAllocation") as RadNumericTextBox;
            //        Label SharesLabel = items["Shares"].FindControl("lblShares") as Label;
            //        CompareValidator cmp = items.FindControl("CmptxtAllocation") as CompareValidator;
            //        //cmp.ValueToCompare = Math.Round(Convert.ToDecimal(SharesLabel.Text.ToString()), 2).ToString();
            //        cmp.ValueToCompare = Convert.ToString(Convert.ToInt32(SharesLabel.Text.ToString()));
            //        //cmp.ValueToCompare = "100";
            //        // cmp.c
            //        // Get the textbox for column Price   
            //        txtAllocation.Attributes.Add("OnBlur", "return calculate('" + txtAllocation.ClientID + "','" + 100 + "','" + btnLotUpdate.ClientID + "')");
            //        // txtAllocation.Attributes.Add("onFocusout", "return calculate('" + txtAllocation.ClientID + "','" + 100 + "')");
            //        //    txtPrice.Attributes.Add("onFocusout", "return calculate('" + txtPrice.ClientID + "','" + txtQuantity.ClientID + "','" + txtTotalAmount.ClientID + "')");
            //        //    txtQuantity.Attributes.Add("onFocusout", "return calculate('" + txtPrice.ClientID + "','" + txtQuantity.ClientID + "','" + txtTotalAmount.ClientID + "')");
            //        //    txtTotalAmount.Attributes.Add("onfocus", "return calculate('" + txtPrice.ClientID + "','" + txtQuantity.ClientID + "','" + txtTotalAmount.ClientID + "')");
            //        //}  
 
 
            //    }
 
            //}
 
        }
 
    }
}
ach for this.
protected void rgCostBasisTrades_ItemDataBound(object sender, GridItemEventArgs e)
       {
           if (e.Item.OwnerTableView.Name == "TaxlotsMain") // check with name of DetailTable
           {
               if (e.Item is GridDataItem)
               {
                   GridDataItem dataItem = (GridDataItem)e.Item;
                   LinkButton btnLotUpdate = (LinkButton)dataItem["LotUpdate"].Controls[0];
                   if (e.Item.Expanded)
                   {
                       btnLotUpdate.Enabled = true;
                   }
                   else
                   {
                       btnLotUpdate.Enabled = false;
                   }
               }
           }
           else if (e.Item.OwnerTableView.Name == "Taxlots")
           {
               if (e.Item is GridDataItem)
               {
                   GridDataItem item = (GridDataItem)e.Item;
                   RadNumericTextBox txtAllocation = item.FindControl("txtAllocation") as RadNumericTextBox;
                   Label SharesLabel = item["Shares"].FindControl("lblShares") as Label;
                   sum += int.Parse(txtAllocation.Value.ToString());
 
                   // CompareValidator cmp = item.FindControl("CmptxtAllocation") as CompareValidator;
                   // //cmp.ValueToCompare = Math.Round(Convert.ToDecimal(SharesLabel.Text.ToString()), 2).ToString();
                   // //cmp.ValueToCompare = Convert.ToString(Convert.ToInt32(SharesLabel.Text.ToString()));
                   // cmp.ValueToCompare = "100";
                   //// cmp.c
                   // Get the textbox for column Price  
                   string[] Allc = ExpandedItemKeys[0].Split(':');
 
                   txtAllocation.Attributes.Add("onFocusout", "return calculate('" + txtAllocation.ClientID + "','" + SharesLabel.ClientID + "','" + Allc[0] + "','" + Allc[1] + "')");
                   // txtAllocation.Attributes.Add("onFocusout", "return calculate('" + txtAllocation.ClientID + "','" + 100 + "')");
                   //    txtPrice.Attributes.Add("onFocusout", "return calculate('" + txtPrice.ClientID + "','" + txtQuantity.ClientID + "','" + txtTotalAmount.ClientID + "')");
                   //    txtQuantity.Attributes.Add("onFocusout", "return calculate('" + txtPrice.ClientID + "','" + txtQuantity.ClientID + "','" + txtTotalAmount.ClientID + "')");
                   //    txtTotalAmount.Attributes.Add("onfocus", "return calculate('" + txtPrice.ClientID + "','" + txtQuantity.ClientID + "','" + txtTotalAmount.ClientID + "')");
                   //}  
 
 
               }
               else if (e.Item is GridFooterItem)
               {
                   GridFooterItem footer = (GridFooterItem)e.Item;
                   RadNumericTextBox txtTotalAllocation = footer.FindControl("txtTotalAllocation") as RadNumericTextBox;
                   txtTotalAllocation.Value = int.Parse(sum.ToString());
 
                   txtTotalAllocation.Attributes.Add("OnLoad", "return OnLoad()");
                   txtTotalAllocation.Visible = false;
                   // footer["ShipCity"].Controls.Add(new LiteralControl("<span style='color: Black; font-weight: bold;'>Total freight on this page is:</span> "));
                   // footer.FindControl("txtTotalAllocation") as RadNumericTextBox.Value = int.Parse(sum.ToString());
               }
 
 
               //GridDataInsertItem insertItem = (GridDataInsertItem)e.Item;
               //GridDataItem parentitem = (GridDataItem)insertItem.OwnerTableView.ParentItem;
               //GridTableView tableView = (GridTableView)parentitem.ChildItem.NestedTableViews[0];
               //tableView.GetColumn("EditcolumnUniqueName").Visible = true;
               //GridDataItem dataItem = (GridDataItem)ParentItem;
               //foreach (GridDataItem dataItem in rgCostBasisTrades.Items)
               //    ((LinkButton)dataItem["EditcolumnUniqueName"].Controls[0]).Visible = false;
           }
           //else
           //{
           //    foreach (GridDataItem parentitem in rgCostBasisTrades.Items)
           //    {
           //        if (parentitem.Expanded)
           //        {
           //            LinkButton btnLotUpdate = (LinkButton)parentitem["LotUpdate"].Controls[0];
           //            btnLotUpdate.Enabled = false;
           //            //GridTableView tableView = (GridTableView)parentitem.ChildItem.NestedTableViews[0];
           //            //tableView.GetColumn("EditcolumnUniqueName").Visible = false;
           //        }
           //    }
           //}
 
           //if (e.Item is GridDataItem)
           //{
           //    GridDataItem dataItem = (GridDataItem)e.Item;
           //    LinkButton btnLotUpdate = (LinkButton)dataItem["LotUpdate"].Controls[0];
           //    btnLotUpdate.Enabled = false;
           //}  
 
 
           //GridDataInsertItem insertItem = (GridDataInsertItem)e.Item;
           //GridDataItem parentitem = (GridDataItem)insertItem.OwnerTableView.ParentItem;
           //GridTableView tableView = (GridTableView)parentitem.ChildItem.NestedTableViews[0];
           //tableView.GetColumn("EditcolumnUniqueName").Visible = true;
           //GridDataItem dataItem = (GridDataItem)ParentItem;
           //foreach (GridDataItem dataItem in rgCostBasisTrades.Items)
           //    ((LinkButton)dataItem["EditcolumnUniqueName"].Controls[0]).Visible = false;
           //else
           //{
           //    foreach (GridDataItem parentitem in rgCostBasisTrades.Items)
           //    {
           //        if (parentitem.Expanded)
           //        {
           //            LinkButton btnLotUpdate = (LinkButton)parentitem["LotUpdate"].Controls[0];
           //            btnLotUpdate.Enabled = false;
           //            //GridTableView tableView = (GridTableView)parentitem.ChildItem.NestedTableViews[0];
           //            //tableView.GetColumn("EditcolumnUniqueName").Visible = false;
           //        }
           //    }
           //}
 
           //if (e.Item is GridDataItem)
           //{
           //    GridDataItem dataItem = (GridDataItem)e.Item;
           //    LinkButton btnLotUpdate = (LinkButton)dataItem["LotUpdate"].Controls[0];
           //    btnLotUpdate.Enabled = false;
           //}
       }


0
Tsvetina
Telerik team
answered on 10 Nov 2010, 02:51 PM
Hello,

The best event to access detail tables of RadGrid is PreRender where the whole hierarchy is loaded. You can take a look at this help article, more specifically the Looping through all detail tables/items in Telerik RadGrid section for a code-sample.

Kind regards,
Tsvetina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
nagendra
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
nagendra
Top achievements
Rank 1
Share this question
or