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

[Solved] grid editing using FormTemplate

1 Answer 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Milind
Top achievements
Rank 1
Milind asked on 31 Oct 2009, 12:24 PM
following is my code :
ASPX:-

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="frmROEntryNew.aspx.cs" Inherits="frmROEntryNew" Title="RO Entry" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script language="javascript" type="text/javascript">
                function msg(strvar)
                {
                    alert(strvar);
                }
        </script>
    </telerik:RadCodeBlock>

    <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" Skin="Office2007" />
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="gvROEdit">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="gvROEdit" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" HorizontalAlign="Center" Skin="Office2007">
    </telerik:RadAjaxLoadingPanel>
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Height="99%" HorizontalAlign="NotSet" LoadingPanelID="RadAjaxLoadingPanel1" Width="100%">
    <telerik:RadToolBar ID="RadToolBar1" runat="server" Skin="Office2007" Width="100%" BackColor="#D6E6F4">
        <Items>
            <telerik:RadToolBarButton runat="server" ImageUrl="~/Images/AddRecord.gif" Text="New" Value="1">
            </telerik:RadToolBarButton>
            <telerik:RadToolBarButton runat="server" IsSeparator="True" Text="Button 1" Value="3">
            </telerik:RadToolBarButton>
            <telerik:RadToolBarButton runat="server" ImageUrl="~/Images/save.gif" Text="Save" Value="2">
            </telerik:RadToolBarButton>
            <telerik:RadToolBarButton runat="server" IsSeparator="True" Text="Button 5">
            </telerik:RadToolBarButton>
            <telerik:RadToolBarButton runat="server" ImageUrl="~/Images/Delete.gif" Text="Delete" Value="3">
            </telerik:RadToolBarButton>
            <telerik:RadToolBarButton runat="server" IsSeparator="True" Text="Button 2" Value="4">
            </telerik:RadToolBarButton>
        </Items>
    </telerik:RadToolBar>
    <br />
    <table border="0" cellpadding="0" cellspacing="0" style="width: 100%">
        <tr>
            <td style="font-size:9px;" colspan="6"> &nbsp;
            </td>
        </tr>
        <tr>
            <td style="width:10%;">
            </td>
            <td class="LabelTdRightAlign" style="width:15%;">
                DD Ref No :
            </td>
            <td class="LabelTdLeftAlign" colspan="3" >
                <telerik:RadComboBox ID="ddlOurRefNo" runat="server" Skin="Outlook" Width="100%"
                    AutoPostBack="True" MarkFirstMatch="True" DataTextField="nCounter" DataValueField="nCounter"
                    HighlightTemplatedItems="True" EmptyMessage="- Select -" >
                </telerik:RadComboBox>
            </td>
            <td style="width:15%;">
            </td>
        </tr>
        <tr>
            <td style="font-size:5px;" colspan="6"> &nbsp;
            </td>
        </tr>
        <tr>
            <td style="width:10%;">
            </td>
            <td class="LabelTdRightAlign" style="width: 15%;">
                RO No :
            </td>
            <td class="LabelTdLeftAlign" style="width: 25%; text-align: left; ">
                <asp:TextBox ID="txtRONo" runat="server"></asp:TextBox></td>
            <td class="LabelTdRightAlign" style="width: 10%; ">
                RO Date :
            </td>
            <td style="width: 25%; text-align: left;">
                <telerik:RadDatePicker ID="txtRODate" runat="server" Culture="English (United Kingdom)"
                    Skin="Office2007" >
                    <Calendar ID="Calendar1" runat="server" Skin="Office2007" UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False"
                        ViewSelectorText="x" FirstDayOfWeek="Sunday">
                    </Calendar>
                    <DatePopupButton HoverImageUrl="" ImageUrl="" />
                    <DateInput ID="DateInput1" runat="server" AutoPostBack="True">
                    </DateInput>
                </telerik:RadDatePicker>
            </td>
            <td style="width:15%;">
            </td>
        </tr>
        <tr>
            <td style="font-size:5px;" colspan="6"> &nbsp;
            </td>
        </tr>
        <tr>
            <td style="width:10%;">
            </td>
            <td class="LabelTdRightAlign" style="width:15%;">
                Product Name :
            </td>
            <td class="LabelTdLeftAlign" colspan="3" >
                <asp:TextBox ID="txtProductName" runat="server" Width="99%">Type Here </asp:TextBox>
            </td>
            <td style="width:15%;">
            </td>
        </tr>
        <tr>
            <td style="font-size:5px;" colspan="6"> &nbsp;
            </td>
        </tr>
        <tr>
            <td style="width:10%;">
            </td>
            <td class="LabelTdRightAlign" style="width: 15%;">
                Client :
            </td>
            <td class="LabelTdLeftAlign" style="width: 25%;">
                <telerik:RadComboBox ID="ddlClient" runat="server" Skin="Outlook" Width="100%"
                    AutoPostBack="True" MarkFirstMatch="True" DataTextField="vClientName" DataValueField="vClientId"
                    HighlightTemplatedItems="True" EmptyMessage="- Select -" OnSelectedIndexChanged="ddlClient_SelectedIndexChanged" >
                </telerik:RadComboBox>
            </td>
            <td class="LabelTdRightAlign" style="width: 10%;">
                Agency :
            </td>
            <td class="LabelTdLeftAlign" style="width: 25%;">
                <telerik:RadComboBox ID="ddlAgency" runat="server" Skin="Outlook" Width="100%"
                    AutoPostBack="True" MarkFirstMatch="True" DataTextField="vAgencyName" DataValueField="vAgencyId"
                    HighlightTemplatedItems="True" EmptyMessage="- Select -">
                </telerik:RadComboBox>
            </td>
            <td style="width:15%;">
            </td>
        </tr>
        <tr>
            <td style="font-size:5px;" colspan="6"> &nbsp;
            </td>
        </tr>
        <tr>
            <td class="LabelTdRightAlign" colspan="3">
                Channel :
            </td>
            <td class="LabelTdLeftAlign" colspan="3">
                <telerik:RadComboBox ID="ddlChannel" runat="server" Skin="Outlook"
                    AutoPostBack="True" MarkFirstMatch="True" DataTextField="vChannelName" DataValueField="vChannelId"
                    HighlightTemplatedItems="True" EmptyMessage="- Select -" >
                </telerik:RadComboBox>
            </td>
            <td style="width:15%;">
            </td>
        </tr>
        <tr>
            <td style="font-size:5px;" colspan="6"> &nbsp;
            </td>
        </tr>
        <tr>
            <td class="LabelTdCenterAlign" colspan="6" style="font:Arial; font-size:large; font-weight:bold">
                RO Details
            </td>
        </tr>
        <tr>
            <td style="font-size:5px;" colspan="6"> &nbsp;
            </td>
        </tr>
        <tr>
            <td style="width:100%;" align="left" colspan="6">
                <telerik:RadGrid ID="gvRODetail" runat="server" AllowPaging="True"
                    AllowSorting="True" AutoGenerateColumns="False" GridLines="None" ShowFooter="True"
                    ShowGroupPanel="True" ShowStatusBar="True" Skin="Outlook" OnNeedDataSource="gvRODetail_NeedDataSource" OnItemDataBound="gvRODetail_ItemDataBound"
                    AllowAutomaticInserts="false" AllowAutomaticUpdates="false" AllowAutomaticDeletes="false"
                    OnInsertCommand ="gvRoDetail_ItemInsert" OnUpdateCommand="gvRoDetail_ItemUpdated" >
                    <MasterTableView Name="tblROMasterView" CommandItemDisplay="TopAndBottom" DataKeyNames="nRowNo,nCounter">
                        <Columns>
                            <telerik:GridEditCommandColumn ButtonType="ImageButton">
                            </telerik:GridEditCommandColumn>
                            <telerik:GridTemplateColumn DataField="nRowNo" UniqueName="TColnRowNo" Groupable="False" AllowFiltering="False" Visible="false">
                                <ItemTemplate>
                                    <asp:Label ID="lblRowNo" runat="server" Text='<%# Bind("nRowNo") %>' />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="0%" />
                                <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="0%" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn DataField="nCounter" UniqueName="TColnCounter" Groupable="False" AllowFiltering="False" Visible="false">
                                <ItemTemplate>
                                    <asp:Label ID="lblCounter" runat="server" Text='<%# Bind("nCounter") %>' />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Left" VerticalAlign="Top"  Width="0%"  />
                                <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="0%" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Program Name" DataField="vProgramName" SortExpression="vProgramName" UniqueName="TColvProgramName" Groupable="False">
                                <ItemTemplate>
                                    <asp:Label ID="lblProgramName" runat="server" Text='<%# Bind("vProgramName") %>' />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="14%" />
                                <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="14%" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Telecast Date" DataField="dtTelecastDate" SortExpression="dtTelecastDate" AllowFiltering="False" UniqueName="TcolDtTelecastDate" Groupable="False">
                                <ItemTemplate>
                                    <asp:Label ID="lblTelecastDate" runat="server" Text='<%# Bind("dtTelecastDate") %>' />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="8%" />
                                <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="8%" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Category" DataField="vCategoryId" UniqueName="TcolvCategory" Visible="false">
                                <ItemTemplate>
                                    <asp:Label ID="lblCategory" runat="server" Text='<%# Bind("vCategoryId") %>' />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="0%" />
                                <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="0%" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Status" DataField="vStatus" UniqueName="TcolvStatus" >
                                <ItemTemplate>
                                    <asp:Label ID="lblStatus" runat="server" Text='<%# Bind("vStatus") %>' />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="10%" />
                                <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="10%" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Product Name" DataField="vProductName" SortExpression="vProductName" UniqueName="TcolvProductName"  Groupable="False">
                                <ItemTemplate>
                                    <asp:Label ID="lblProductNameDt" runat="server" Text='<%# Bind("vProductName") %>' />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="17%" />
                                <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="17%" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Caption" DataField="vCaption" UniqueName="TColvCaption" AllowFiltering="False">
                                <ItemTemplate>
                                    <asp:Label ID="lblCaption" runat="server" Text='<%# Bind("vCaption") %>' />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="16%" />
                                <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="16%" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Rate" DataField="nRate" UniqueName="TcolnRate" AllowFiltering="False">
                                <ItemTemplate>
                                    <asp:Label ID="lblRate" runat="server" Text='<%# Bind("nRate") %>' />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right" VerticalAlign="Top" Width="7%" />
                                <HeaderStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="7%" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="FCT" DataField="nFCT" UniqueName="TcolnFCT" AllowFiltering="False">
                                <ItemTemplate>
                                    <asp:Label ID="lblFCT" runat="server" Text='<%# Bind("nFCT") %>' />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right" VerticalAlign="Top" Width="7%" />
                                <HeaderStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="7%" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Duration" DataField="nDuration" UniqueName="TcolnDuration" AllowFiltering="False">
                                <ItemTemplate>
                                    <asp:Label ID="lblDuration" runat="server" Text='<%# Bind("nDuration") %>' />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right" VerticalAlign="Top" Width="7%" />
                                <HeaderStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="7%" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Amount" DataField="nAmount" UniqueName="TcolnAmount" AllowFiltering="False">
                                <ItemTemplate>
                                    <asp:Label ID="lblAmount" runat="server" Text='<%# Bind("nAmount") %>' />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right" VerticalAlign="Top" Width="7%" />
                                <HeaderStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="7%" />
                            </telerik:GridTemplateColumn>
                        </Columns>
                        <EditFormSettings EditFormType="Template">
                            <FormTemplate>
                                <table id="tblHtmlEditRo" style="width: 100%" cellspacing="1" cellpadding="2" border="0">
                                    <tr>
                                        <td colspan="4" class="LabelTdRightAlign" > &nbsp;<asp:TextBox ID="txtCounter" runat="server" Visible="false" Text ="0" />
                                            <asp:TextBox ID="txtRowNo" runat="server" Visible="false" Text = "0" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="LabelTdRightAlign" style="width:15%">
                                            Program Status : </td>
                                        <td  class="LabelTdLeftAlign"  style="width: 30%">
                                            <telerik:RadComboBox ID="ddlStatus" runat="server" Skin="Outlook"
                                                AutoPostBack="True" MarkFirstMatch="True" Width="90%" OnSelectedIndexChanged="ddlStatus_SelectedIndexChanged"
                                                HighlightTemplatedItems="True">
                                                <Items>
                                                    <telerik:RadComboBoxItem runat="server" Text="Sponsorship" Value="Sponsorship" Selected="true" />
                                                    <telerik:RadComboBoxItem runat="server" Text="Banking" Value="Banking" />
                                                    <telerik:RadComboBoxItem runat="server" Text="Spot" Value="Spot" />
                                                </Items>
                                            </telerik:RadComboBox>
                                         </td>
                                        <td id="HtmlColPrgName" class="LabelTdRightAlign" style="width:15%">
                                            Program Name : </td>
                                        <td  class="LabelTdLeftAlign" style="width: 30%">
                                            <telerik:RadComboBox ID="ddlProgram" runat="server" Skin="Outlook" Width="90%"
                                                AutoPostBack="True" MarkFirstMatch="True" DataTextField="vProgramName" DataValueField="vProgramId"
                                                HighlightTemplatedItems="True" EmptyMessage="- Select -" OnSelectedIndexChanged="ddlProgram_SelectedIndexChanged">
                                            </telerik:RadComboBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="LabelTdRightAlign" style="width:15%">
                                            Category : </td>
                                        <td  class="LabelTdLeftAlign" style="width: 30%">
                                            <telerik:RadComboBox ID="ddlCategory" runat="server" Skin="Outlook" Width="100%" Enabled="false"
                                                AutoPostBack="True" MarkFirstMatch="True" DataTextField="vCategoryName" DataValueField="vCategoryId"
                                                HighlightTemplatedItems="True" EmptyMessage="- Select -">
                                            </telerik:RadComboBox>
                                         </td>
                                        <td class="LabelTdRightAlign" style="width: 10%">
                                            Telecast Date : </td>
                                        <td  class="LabelTdLeftAlign" style="width: 45%">
                                            <telerik:RadDatePicker ID="txtTelecastDateDt" runat="server" Culture="English (United Kingdom)"
                                                Skin="Office2007" OnSelectedDateChanged="txtTelecastDateDt_SelectedDateChanged" AutoPostBack="True">
                                                <Calendar ID="Calendar1" runat="server" Skin="Office2007" UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False"
                                                    ViewSelectorText="x" FirstDayOfWeek="Sunday">
                                                </Calendar>
                                                <DatePopupButton HoverImageUrl="" ImageUrl="" />
                                                <DateInput ID="DateInput2" runat="server" AutoPostBack="True">
                                                </DateInput>
                                            </telerik:RadDatePicker>
                                        </td>                
                                    </tr>
                                    <tr>
                                        <td class="LabelTdRightAlign" style="width:15%">
                                            Product Name : </td>
                                        <td  class="LabelTdLeftAlign" style="width: 30%">
                                            <asp:TextBox ID="txtProductNameDt" runat="server" Width="100%"></asp:TextBox></td>
                                        <td class="LabelTdRightAlign" style="width: 10%">
                                            Caption : </td>
                                        <td  class="LabelTdLeftAlign" style="width: 45%">
                                            <asp:TextBox ID="txtCaption" runat="server" Width="90%"></asp:TextBox>
                                        </td>                
                                    </tr>
                                    <tr>
                                        <td class="LabelTdRightAlign" style="width:15%">
                                            Rate : </td>
                                        <td  class="LabelTdLeftAlign" style="width: 30%">
                                            <asp:TextBox ID="txtRate" runat="server" Text="0" Enabled="false"></asp:TextBox></td>
                                        <td class="LabelTdRightAlign" style="width: 10%">
                                            FCT : </td>
                                        <td  class="LabelTdLeftAlign" style="width: 45%">
                                            <asp:TextBox ID="txtFCT" runat="server" Text="0" Enabled="false"></asp:TextBox>
                                        </td>                
                                    </tr>
                                    <tr>
                                        <td class="LabelTdRightAlign" colspan="2">
                                            Progressive Balance : </td>
                                        <td  class="LabelTdLeftAlign"  colspan="2">
                                            <asp:TextBox ID="txtProgressiveBalance" runat="server" Text="0"></asp:TextBox></td>
                                    </tr>
                                    <tr>
                                        <td class="LabelTdRightAlign" style="width:15%">
                                            Duration (In Secs) : </td>
                                        <td  class="LabelTdLeftAlign" style="width: 30%">
                                            <asp:TextBox ID="txtDuration" runat="server" AutoPostBack="true" OnTextChanged="txtDuration_TextChanged"></asp:TextBox></td>
                                        <td class="LabelTdRightAlign" style="width: 10%">
                                            Amount : </td>
                                        <td  class="LabelTdLeftAlign" style="width: 45%">
                                            <asp:TextBox ID="txtAmount" runat="server" Enabled="false"></asp:TextBox>
                                        </td>                
                                    </tr>
                                    <tr>
                                        <td class="LabelTdLeftAlign" style="width: 100%" colspan="4">
                                            <asp:Button ID="btnSave" runat="server" Text='<%# (Container is GridEditFormInsertItem) ? "Save" : "Update" %>' CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' />
                                            <asp:Button ID="btnCancel" runat="server" CausesValidation="false" CommandName="Cancel" Text="Cancel" />
                                        </td>
                                    </tr>
                                </table>
                            </FormTemplate>
                            <EditColumn UniqueName="EditCommandColumn1">
                            </EditColumn>
                        </EditFormSettings>
                    </MasterTableView>
                    <ClientSettings AllowDragToGroup="True">
                        <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                        <Selecting AllowRowSelect="True" EnableDragToSelectRows="True" />
                    </ClientSettings>
                </telerik:RadGrid></td>
        </tr>
        <tr>
            <td colspan="6">
            </td>
        </tr>
    </table>
    </telerik:RadAjaxPanel>
</asp:Content>

.CS:-
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using Telerik.Web.UI;

public partial class frmROEntryNew : System.Web.UI.Page
{
    clsFunctionLib objFunLib;
    string strSql, strMsg;
    SqlDataReader objRdr;
    string strArg1, strArg2, strRtnCounter;
    DataTable objDT;

    protected void Page_Load(object sender, EventArgs e)
    {
        objFunLib = new clsFunctionLib();
        objFunLib.ExpirePageCache();

        if (!IsPostBack)
        {
            txtRONo.Text = "";
            txtRODate.SelectedDate = null;
            txtProductName.Text = "";

            ddlClient.Items.Clear();
            strSql = "select vClientId, vClientName from tblClient";
            objFunLib.BindTelerikDropDown(strSql, ref ddlClient);

            ddlChannel.Items.Clear();
            strSql = "select vChannelId, vChannelName from tblChannel order by vChannelName";
            objFunLib.BindTelerikDropDown(strSql, ref ddlChannel);

            ddlOurRefNo.Items.Clear();
            strSql = "Select nCounter from tblROMaster order by nCounter Desc";
            objFunLib.BindTelerikDropDown(strSql, ref ddlOurRefNo);

            ddlOurRefNo.SelectedIndex = 0;
            ddlClient.SelectedIndex = 0;
            ddlAgency.SelectedIndex = 0;
        }
    }

    protected void ddlClient_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        ddlAgency.Items.Clear();
        strSql = "select vAgencyId, vAgencyName from tblAgency where vAgencyId in (select vAgencyId from tblClient where vClientId = '" + ddlClient.SelectedValue + "') order by vAgencyName";
        objFunLib.BindTelerikDropDown(strSql, ref ddlAgency);
        if (ddlAgency.Items.Count > 0)
        {
            ddlAgency.SelectedIndex = 1;
        }
        else
        {
            ddlAgency.SelectedIndex = 0;
        }
        ddlChannel.SelectedIndex = 0;
    }
    protected void gvRODetail_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        if (ddlOurRefNo.SelectedValue == "")
        {
            strSql = "select nRowNo, nCounter, vProgramName, convert(varchar(10),dtTelecastDate,103) as dtTelecastDate, vStatus, vProductName, vCaption, nRate, nFCT, nDuration, nAmount from tblRODetail, tblProgram where tblRODetail.vProgramId = tblProgram.vProgramId and nCounter = 0";
        }
        else
        {
            strSql = "select nRowNo, nCounter, vProgramName, convert(varchar(10),dtTelecastDate,103) as dtTelecastDate, vStatus, vProductName, vCaption, nRate, nFCT, nDuration, nAmount from tblRODetail, tblProgram where tblRODetail.vProgramId = tblProgram.vProgramId and nCounter = '" + ddlOurRefNo.SelectedValue + "'";
        }
        gvRODetail.DataSource = objFunLib.ReturnDataTable(strSql, "tblRODtl");

    }

    protected void gvRODetail_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if ((e.Item is GridEditFormInsertItem) && (e.Item.OwnerTableView.IsItemInserted))
        {
            GridEditFormInsertItem editItem = (GridEditFormInsertItem)(e.Item);
            RadComboBox ddlProgram = (RadComboBox)editItem.FindControl("ddlProgram");
            RadComboBox ddlCategory = (RadComboBox)editItem.FindControl("ddlCategory");
            ddlProgram.Items.Clear();
            strSql = "select vProgramId, vProgramName from tblProgram where vProgramId in (select vProgramId from tblRateDetail where vChannelId = '" + ddlChannel.SelectedValue + "' and vClientId = '" + ddlClient.SelectedValue + "' and vAgencyId = '" + ddlAgency.SelectedValue + "') order by vProgramName";
            objFunLib.BindTelerikDropDown(strSql, ref ddlProgram);
            ddlProgram.SelectedIndex = 0;

            ddlCategory.Items.Clear();
            strSql = "select vCategoryId, vCategoryName from tblCategory order by vCategoryName";
            objFunLib.BindTelerikDropDown(strSql, ref ddlCategory);

        }
    }

    protected void ddlProgram_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        RadComboBox combo = (RadComboBox)o;
        GridEditFormInsertItem editItem = (GridEditFormInsertItem)(combo.NamingContainer);
        TextBox txtRate = (TextBox)editItem.FindControl("txtRate");
        TextBox txtFCT = (TextBox)editItem.FindControl("txtFCT");
        TextBox txtAmount = (TextBox)editItem.FindControl("txtAmount");
        TextBox txtCounter = (TextBox) editItem.FindControl("txtCounter");
        TextBox txtRowNo = (TextBox) editItem.FindControl("txtRowNo");
        TextBox txtProgressiveBalance = (TextBox)editItem.FindControl("txtProgressiveBalance");
        RadComboBox ddlCategory = (RadComboBox)editItem.FindControl("ddlCategory");
        RadComboBox ddlStatus = (RadComboBox)editItem.FindControl("ddlStatus");
        if (ddlCategory.SelectedIndex == 0)
        {
            strSql = "select vCategoryId from tblRateDetail where vChannelId = '" + ddlChannel.SelectedValue + "' and vClientId = '" + ddlClient.SelectedValue + "' and vAgencyId = '" + ddlAgency.SelectedValue + "' and vProgramId = '" + e.Value + "'";
            ddlCategory.SelectedIndex = ddlCategory.FindItemIndexByValue(objFunLib.ReturnFieldData(strSql, false));
        }

        if (ddlStatus.SelectedValue.ToUpper() == ("Banking").ToUpper())
        {
            txtRate.Text = "0";
            txtFCT.Text = "0";
            txtAmount.Text = "0";
        }
        else
        {
            txtRate.Text = "0";
            txtFCT.Text = "0";
            txtAmount.Text = "0";
            strSql = "select nAmount from tblRate where vAgencyId = '" + ddlAgency.SelectedValue + "' and vClientId = '" + ddlClient.SelectedValue + "' and vChannelId = '" + ddlChannel.SelectedValue + "' and vCategoryId = '" + ddlCategory.SelectedValue + "' and upper(vStatus) = '" + ddlStatus.SelectedValue.ToUpper() + "'";
            txtRate.Text = objFunLib.ReturnFieldData(strSql, true);
            txtAmount.Text = txtRate.Text;
            strSql = "select nFCT from tblRate where vAgencyId = '" + ddlAgency.SelectedValue + "' and vClientId = '" + ddlClient.SelectedValue + "' and vChannelId = '" + ddlChannel.SelectedValue + "' and vCategoryId = '" + ddlCategory.SelectedValue + "' and upper(vStatus) = '" + ddlStatus.SelectedValue.ToUpper() + "'";
            txtFCT.Text = objFunLib.ReturnFieldData(strSql, true);
        }
        if (ddlStatus.SelectedValue.ToUpper() != ("Spot").ToUpper())
        {
            double dblTotTime, dblUsedTime;
            strSql = "select sum(nFCT) as nFCT from tblRODetail where nCounter in (select nCounter from tblROMaster where vClientId = '" + ddlClient.SelectedValue + "' and vCategoryId = '" + ddlCategory.SelectedValue + "' and vChannelId = '" + ddlChannel.SelectedValue + "') and upper(vStatus) <> 'SPOT'";
            dblTotTime = Convert.ToDouble(objFunLib.ReturnFieldData(strSql, true));
            strSql = "select sum(nDuration) as nDuration from tblRODetail where nCounter in (select nCounter from tblROMaster where vClientId = '" + ddlClient.SelectedValue + "' and vCategoryId = '" + ddlCategory.SelectedValue + "' and vChannelId = '" + ddlChannel.SelectedValue + "') and upper(vStatus) <> 'SPOT'";
            dblUsedTime = Convert.ToDouble(objFunLib.ReturnFieldData(strSql, true));
            if (txtCounter.Text.Equals("0"))
            {
                txtProgressiveBalance.Text = Convert.ToString(dblTotTime - dblUsedTime + Convert.ToDouble(txtFCT.Text));
            }
            else
            {
                txtProgressiveBalance.Text = Convert.ToString(dblTotTime - dblUsedTime);
            }

        }


    }

    protected void txtTelecastDateDt_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
    {
        RadDatePicker txtTelecastDate = (RadDatePicker)sender;
        GridEditFormInsertItem editItem = (GridEditFormInsertItem)(txtTelecastDate.NamingContainer);
        RadComboBox ddlProgram = (RadComboBox)editItem.FindControl("ddlProgram");
        string strTimeOfTelecast;
        int intDOW;
        if (string.IsNullOrEmpty(e.NewDate.ToString()))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "msg('Invalid Telecast Date');", true);
            txtTelecastDate.SelectedDate = null;
//            RadToolBarRODetail.Items[0].Enabled = false;
        }
        else
        {
            intDOW = objFunLib.FindDOW(objFunLib.DMYToYMD(e.NewDate.ToString()));
            strSql = "select vTimeOfTelecast from tblProgramTelecastDetail where vChannelId = '" + ddlChannel.SelectedValue + "' and vProgramId = '" + ddlProgram.SelectedValue + "' and intDayOfWeek = '" + intDOW + "'";
            strTimeOfTelecast = objFunLib.ReturnFieldData(strSql, false);
            if (string.IsNullOrEmpty(strTimeOfTelecast))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "msg('Invalid Telecast Date');", true);
                txtTelecastDate.SelectedDate = null;
//                RadToolBarRODetail.Items[0].Enabled = false;
            }
            else
            {
//                RadToolBarRODetail.Items[0].Enabled = true;
            }
        }
    }

    protected void ddlStatus_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        RadComboBox combo = (RadComboBox)o;
        GridEditFormInsertItem editItem = (GridEditFormInsertItem)(combo.NamingContainer);
        TextBox txtRate = (TextBox)editItem.FindControl("txtRate");
        TextBox txtFCT = (TextBox)editItem.FindControl("txtFCT");
        TextBox txtAmount = (TextBox)editItem.FindControl("txtAmount");
        RadComboBox ddlCategory = (RadComboBox)editItem.FindControl("ddlCategory");
        if (combo.SelectedValue.ToUpper() == ("Banking").ToUpper())
        {
            txtRate.Text = "0";
            txtFCT.Text = "0";
            txtAmount.Text = "0";
        }
        else
        {
            txtRate.Text = "0";
            txtFCT.Text = "0";
            txtAmount.Text = "0";
            strSql = "select nAmount from tblRate where vAgencyId = '" + ddlAgency.SelectedValue + "' and vClientId = '" + ddlClient.SelectedValue + "' and vChannelId = '" + ddlChannel.SelectedValue + "' and vCategoryId = '" + ddlCategory.SelectedValue + "' and upper(vStatus) = '" + combo.SelectedValue.ToUpper() + "'";
            txtRate.Text = objFunLib.ReturnFieldData(strSql, true);
            strSql = "select nFCT from tblRate where vAgencyId = '" + ddlAgency.SelectedValue + "' and vClientId = '" + ddlClient.SelectedValue + "' and vChannelId = '" + ddlChannel.SelectedValue + "' and vCategoryId = '" + ddlCategory.SelectedValue + "' and upper(vStatus) = '" + combo.SelectedValue.ToUpper() + "'";
            txtFCT.Text = objFunLib.ReturnFieldData(strSql, true);
            txtAmount.Text = txtRate.Text;
        }
    }

    protected void txtDuration_TextChanged(object sender, EventArgs e)
    {
        TextBox txtDuration = (TextBox)sender;
        GridEditFormInsertItem editItem = (GridEditFormInsertItem)(txtDuration.NamingContainer);
        RadComboBox ddlProgram = (RadComboBox)editItem.FindControl("ddlProgram");
        RadComboBox ddlCategory = (RadComboBox)editItem.FindControl("ddlCategory");
        RadComboBox ddlStatus = (RadComboBox)editItem.FindControl("ddlStatus");
        TextBox txtRate = (TextBox)editItem.FindControl("txtRate");
        TextBox txtFCT = (TextBox)editItem.FindControl("txtFCT");
        TextBox txtAmount = (TextBox)editItem.FindControl("txtAmount");

        if (ddlStatus.SelectedValue.ToUpper() == ("Spot").ToUpper())
        {
            txtAmount.Text = Convert.ToString(Convert.ToDecimal(txtDuration.Text) * Convert.ToDecimal(txtRate.Text) / Convert.ToDecimal(txtFCT.Text));
        }
        else if (ddlStatus.SelectedValue.ToUpper() == ("Banking").ToUpper())
        {
            txtAmount.Text = "0";
        }
        else
        {
            txtAmount.Text = txtRate.Text;
        }
    }

    protected void gvRoDetail_ItemInsert(object sender, GridCommandEventArgs e)
    {
        if ((e.Item is GridEditFormInsertItem) && (e.Item.OwnerTableView.IsItemInserted))
        {
            TextBox txtCounter = (TextBox)e.Item.FindControl("txtCounter");
            TextBox txtRowNo = (TextBox)e.Item.FindControl("txtRowNo");
            RadComboBox ddlProgram = (RadComboBox)e.Item.FindControl("ddlProgram");
            RadComboBox ddlCategory = (RadComboBox)e.Item.FindControl("ddlCategory");
            RadComboBox ddlStatus = (RadComboBox)e.Item.FindControl("ddlStatus");
            RadDatePicker txtTelecastDateDt = (RadDatePicker)e.Item.FindControl("txtTelecastDateDT");
            TextBox txtProductNameDt = (TextBox)e.Item.FindControl("txtProductNameDt");
            TextBox txtCaption = (TextBox)e.Item.FindControl("txtCaption");
            TextBox txtRate = (TextBox)e.Item.FindControl("txtRate");
            TextBox txtFCT = (TextBox)e.Item.FindControl("txtFCT");
            TextBox txtDuration = (TextBox)e.Item.FindControl("txtDuration");
            TextBox txtAmount = (TextBox)e.Item.FindControl("txtAmount");
            if (ddlOurRefNo.SelectedIndex == 0)
            {
                txtCounter.Text = "0";
            }
            else
            {
                txtCounter.Text = ddlOurRefNo.SelectedValue;
            }
            string strTimeOfTelecast;
            int intDOW;
            intDOW = objFunLib.FindDOW(objFunLib.DMYToYMD(txtTelecastDateDt.SelectedDate.ToString()));
            strSql = "select vTimeOfTelecast from tblProgramTelecastDetail where vChannelId = '" + ddlChannel.SelectedValue + "' and vProgramId = '" + ddlProgram.SelectedValue + "' and intDayOfWeek = '" + intDOW + "'";
            strTimeOfTelecast = objFunLib.ReturnFieldData(strSql, false);
            if (string.IsNullOrEmpty(strTimeOfTelecast))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "msg('Invalid Telecast Date... unable to save data');", true);
            }
            else
            {
                try
                {
                    objFunLib.NewSpParameterTable();

                    objFunLib.AddSpParameter("numeric", "@nCounter", 18, Convert.ToDecimal(txtCounter.Text));
                    objFunLib.AddSpParameter("numeric", "@nRowNo", 18, Convert.ToDecimal(txtRowNo.Text));
                    objFunLib.AddSpParameter("varchar", "@vROId", 10, txtRONo.Text);
                    objFunLib.AddSpParameter("varchar", "@vProductName", 75, txtProductName.Text);
                    objFunLib.AddSpParameter("varchar", "@vClientId", 10, ddlClient.SelectedValue);
                    objFunLib.AddSpParameter("varchar", "@vAgencyId", 10, ddlAgency.SelectedValue);
                    objFunLib.AddSpParameter("varchar", "@vChannelId", 10, ddlChannel.SelectedValue);
                    objFunLib.AddSpParameter("varchar", "@vProgramId", 10, ddlProgram.SelectedValue);
                    objFunLib.AddSpParameter("varchar", "@vCategoryId", 10, ddlCategory.SelectedValue);
                    //objFunLib.AddSpParameter("varchar", "@vBookingId", 15, ddlStatus.SelectedValue);
                    if (txtRODate.SelectedDate.ToString() == "")
                    {
                        objFunLib.AddSpParameter("date", "@dtRODate", 0, "01/01/1900");
                    }
                    else
                    {
                        objFunLib.AddSpParameter("date", "@dtRODate", 0, txtRODate.SelectedDate.ToString());
                    }
                    //if (txtTelecastDateDt.SelectedDate.ToString() == "")
                    //{
                    //    objFunLib.AddSpParameter("date", "@dtTelecastDate", 0, "01/01/1900");
                    //}
                    //else
                    //{
                    //    objFunLib.AddSpParameter("date", "@dtTelecastDate", 0, txtTelecastDateDt.SelectedDate.ToString());
                    //}
                    objFunLib.AddSpParameter("varchar", "@vProgramIdDtl", 10, ddlProgram.SelectedValue.ToString());
                    if (txtTelecastDateDt.SelectedDate.ToString() == "")
                    {
                        objFunLib.AddSpParameter("date", "@dtTelecastDateDtl", 0, "01/01/1900");
                    }
                    else
                    {
                        objFunLib.AddSpParameter("date", "@dtTelecastDateDtl", 0, objFunLib.DMYToYMD(txtTelecastDateDt.SelectedDate.ToString()));
                    }
                    objFunLib.AddSpParameter("varchar", "@vProductDtl", 75, txtProductNameDt.Text.Trim());
                    objFunLib.AddSpParameter("varchar", "@vCaptionDtl", 1000, txtCaption.Text.Trim());
                    objFunLib.AddSpParameter("numeric", "@nRateDtl", 18, Convert.ToDecimal(txtRate.Text));
                    objFunLib.AddSpParameter("numeric", "@nFCTDtl", 18, Convert.ToDecimal(txtFCT.Text));
                    objFunLib.AddSpParameter("numeric", "@nDuration", 18, Convert.ToDecimal(txtDuration.Text));
                    objFunLib.AddSpParameter("numeric", "@nAmount", 18, Convert.ToDecimal(txtAmount.Text));
                    objFunLib.AddSpParameter("varchar", "@vStatusDtl", 15, ddlStatus.SelectedValue);


                    short sintResult = Convert.ToInt16(objFunLib.SaveAndReturnData("spSaveRO", ref strRtnCounter));
                    txtCounter.Text = strRtnCounter;

                    ddlProgram.SelectedIndex = 0;
                    txtTelecastDateDt.SelectedDate = null;
                    ddlStatus.SelectedIndex = 0;
                    ddlCategory.SelectedIndex = 0;
                    //txtProgressiveBalance.Text = "";
                    txtProductName.Text = "";
                    txtCaption.Text = "";
                    txtRate.Text = "0";
                    txtFCT.Text = "0";
                    txtAmount.Text = "0";
                    txtDuration.Text = "0";

                    if (sintResult == 1)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "msg('RO saved successfully... Ref No : " + txtCounter.Text + "' );", true);
                    }
                    else if (sintResult == 2)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "msg('RO Updated Successfully');", true);
                    }


                }
                catch (Exception ex)
                {
                    strMsg = ex.Message.ToString();
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "msg('" + strMsg + "');", true);
                }

            }
        }
        gvRODetail.Rebind();
        gvRODetail.MasterTableView.Rebind();

    }

    protected void gvRoDetail_ItemUpdated(object sender, GridCommandEventArgs e)
    {
        gvRODetail.Rebind();
        gvRODetail.MasterTableView.Rebind();
    }

}

In the above page after clicking on Add new record in grid header a blank edit template is opened. After feeding in the information  gvRoDetail_ItemInsert event is not fired on first click of save button. If the save button is clicked on again then the data is saved in the table.

Where am I going wrong ?

- Milind Shevade

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 03 Nov 2009, 07:43 AM
Hi m,

The question set forth has been addressed in the support ticket, which you opened on the matter. To avoid duplicate posts, we can continue our communication there.

Best wishes,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Milind
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or