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

How to Show Filter Row AND Hide Insert Row on InitInsert Item Command

4 Answers 151 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike West
Top achievements
Rank 1
Mike West asked on 02 Jul 2010, 06:21 PM

Here is what I want my solution to do:

1) Grid loads unfiltered, shows list of deals with company information for each, one-to-many companies to deals, one row per deal.
2) User clicks "Add new record" button
    a) Filter row is VISIBLE
    b) Insert row is HIDDEN
3) User types in RadComboBox in filter row of company column to select company, tabs-out or hits enter
    a) Filter row is HIDDEN
    b) Insert row is VISIBLE
    c) Grid filters to just those deal records for the company selected
    d) 3 columns of info in Insert row prepopulate with company information
4) User enters info for remaining columns in Insert row, saves record

My solution is almost 100%, except for Step 2.

Your example at:
    http://www.telerik.com/help/aspnet/grid/grdinsertingvaluesusercontrolformtemplate.html
under the section
    "Setting predefined values for controls inside user control on item insertion"
does not work for me as-is because canceling the event does not allow the code to set the IsFilterItemExpanded to true.

Please tell me how I can satisfy step 2 as defined above, HIDING the Insert row and SHOWING the Filter row on InitInsert.

Thanks!

Code samples and screenshots to follow in responses.

4 Answers, 1 is accepted

Sort by
0
Mike West
Top achievements
Rank 1
answered on 02 Jul 2010, 06:23 PM
UserControl:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DealEntry.ascx.cs" Inherits="SplendidCRM.Opportunities.DealEntry" %> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
<%@ Register TagPrefix="LtControls" Namespace="LtControls"%> 
 
<div> 
<asp:CheckBox runat="server" ID="Checkbox_MineOnly" Text=" Only my items" style="position:absolute;top:54px;left:375px;" /> 
</div> 
<div style="position:absolute;top:55;left:-200;" id="div_buttons">  
<href="/reports"><asp:Image runat="server" ID="Image_Report" BackColor="Transparent" ImageUrl="~/include/images/report.png" BorderWidth="0"/></a> 
</div> 
 
<asp:UpdatePanel ID="UpdatePanel1" runat="server">  
    <ContentTemplate> 
 
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"   
            CellPadding="0" CellSpacing="0" AllowSorting="True" PageSize="40" Width="100%" AutoGenerateColumns="False" EnableViewState="true" 
            AllowAutomaticInserts="False" AllowAutomaticUpdates="False"   
            AllowFilteringByColumn="true"   
            OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand"   
            OnInsertCommand="RadGrid1_InsertCommand" OnUpdateCommand="RadGrid1_UpdateCommand"   
            OnItemInserted="RadGrid1_ItemInserted" OnItemUpdated="RadGrid1_ItemUpdated" 
            > 
            <ClientSettings ClientEvents-OnCommand="OnCommand" /> 
            <ItemStyle Height="14" Wrap="true" BorderColor="Gray" BorderWidth="1px" BorderStyle="Solid" /> 
            <AlternatingItemStyle Height="14" Wrap="true" BorderColor="Gray" BorderWidth="1px" BorderStyle="Solid" /> 
            <HeaderStyle HorizontalAlign="Center" Font-Underline="true"/>  
            <MasterTableView DataKeyNames="OPPORTUNITY_ID" EditMode="InPlace" CommandItemDisplay="Top" IsFilterItemExpanded="false">  
                <Columns> 
                    <telerik:GridBoundColumn DataField="OPPORTUNITY_ID" DataType="System.Int32" HeaderText="OPPORTUNITY ID"   
                        ReadOnly="True" SortExpression="OPPORTUNITY_ID" UniqueName="OPPORTUNITY_ID" Visible="False" AllowFiltering="false">  
                    </telerik:GridBoundColumn> 
                      
                    <telerik:GridTemplateColumn HeaderText="Status" SortExpression="STATUS_C" DataField="STATUS_C"   
                        HeaderStyle-HorizontalAlign="Left" HeaderButtonType="LinkButton" AllowFiltering="false">  
                        <ItemStyle Width="75" /> 
                        <HeaderStyle Width="75" Font-Underline="true" /> 
                        <EditItemTemplate> 
                            <telerik:RadComboBox ID="STATUS_C" AllowCustomText="True" runat="server"   
                                DataSourceID="SqlDataSource_Status" DataValueField="DISPLAY_NAME" DataTextField="DISPLAY_NAME"   
                                DropDownWidth="150" Width="100%" 
                                Text='<%# Bind("STATUS_C") %>' Filter="Contains" /> 
                        </EditItemTemplate> 
                        <ItemTemplate> 
                            <asp:Label ID="Label_STATUS_C" runat="server" Text='<%# Bind("STATUS_C") %>'></asp:Label>&nbsp;  
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
 
                    <telerik:GridTemplateColumn HeaderText="Date" SortExpression="DEAL_DATE_C" DataField="DEAL_DATE_C" HeaderStyle-HorizontalAlign="Left" AllowFiltering="false">  
                        <ItemStyle Width="65" /> 
                        <HeaderStyle Width="65" /> 
                        <EditItemTemplate> 
                            <asp:TextBox ID="DEAL_DATE_C" runat="server"  Width="100%" BorderWidth="0" Text='<%# ShortDate(Eval("DEAL_DATE_C").ToString(), true) %>' style="text-align:center;"></asp:TextBox> 
                        </EditItemTemplate> 
                        <ItemTemplate> 
                            <asp:Label ID="Label_DEAL_DATE_C" runat="server" Text='<%# ShortDate(Eval("DEAL_DATE_C").ToString(), true) %>'></asp:Label>&nbsp;  
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
 
                    <LtControls:MyCustomFilteringColumn HeaderText="Company" SortExpression="COMPANY_NAME" ItemStyle-Wrap="false" HeaderStyle-HorizontalAlign="Left"   
                        AllowFiltering="true" AutoPostBackOnFilter="true" DataField="COMPANY_NAME">  
                        <ItemStyle Width="180" /> 
                        <HeaderStyle Width="180" /> 
                        <EditItemTemplate> 
                            <telerik:RadComboBox ID="ACCOUNT_ID" AllowCustomText="True" runat="server" DataSourceID="SqlDataSource_Accounts"   
                                DataValueField="ID" DataTextField="COMPANY_NAME" Width="180" Text='<%# Bind("COMPANY_NAME") %>' Filter="Contains" OnDataBound="Account_DataBound"   
                                /> 
                        </EditItemTemplate> 
                        <ItemTemplate> 
                            <asp:HyperLink runat="server" ID="Hyperlink_Account" Text='<%# Bind("COMPANY_NAME") %>' NavigateUrl='<%#GetAccountUrl((System.Guid)Eval("ACCOUNT_ID"))%>' /> 
                        </ItemTemplate> 
                    </LtControls:MyCustomFilteringColumn> 
 
                    <telerik:GridTemplateColumn HeaderText="Description" SortExpression="DESCRIPTION" HeaderStyle-HorizontalAlign="Left" AllowFiltering="false">  
                        <ItemStyle Wrap="true" /> 
                        <EditItemTemplate> 
                            <asp:TextBox ID="SHORT_DESCRIPTION_C" runat="server" Text='<%# Bind("DESCRIPTION") %>' Width="100%" BorderWidth="0" OnPreRender="Description_DataBound"  /> 
                        </EditItemTemplate> 
                        <ItemTemplate> 
                            <asp:Label ID="Label_DESCRIPTION" runat="server" Text='<%# Bind("DESCRIPTION") %>'></asp:Label>&nbsp;  
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                      
                    <telerik:GridTemplateColumn HeaderText="Sector" SortExpression="INDUSTRY" HeaderStyle-HorizontalAlign="Left" AllowFiltering="false">  
                        <ItemStyle Width="120" /> 
                        <HeaderStyle Width="120" /> 
                        <EditItemTemplate> 
                            <telerik:RadComboBox ID="INDUSTRY" AllowCustomText="True" runat="server"  OnDataBound="Industry_DataBound"   
                                DataSourceID="SqlDataSource_Industry" DataValueField="DISPLAY_NAME" DataTextField="DISPLAY_NAME"   
                                DropDownWidth="150"  Width="100%" Text='<%# Bind("INDUSTRY") %>' Filter="Contains" /> 
                        </EditItemTemplate> 
                        <ItemTemplate> 
                            <asp:Label ID="Label_INDUSTRY" runat="server" Text='<%# Bind("INDUSTRY") %>'></asp:Label>&nbsp;  
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
 
                    <telerik:GridTemplateColumn HeaderText="Lead" SortExpression="LEAD_INITIALS" HeaderStyle-HorizontalAlign="Left" AllowFiltering="false">  
                        <ItemStyle Width="30" /> 
                        <HeaderStyle Width="30" /> 
                        <EditItemTemplate> 
                            <telerik:RadComboBox ID="ASSIGNED_USER_ID" AllowCustomText="True" runat="server" 
                                DataSourceID="SqlDataSource_Users" DataValueField="ID" DataTextField="INITIALS_C"   
                                DropDownWidth="55"  Width="40" 
                                Text='<%# Bind("LEAD_INITIALS") %>' Filter="Contains" /> 
                        </EditItemTemplate> 
                        <ItemTemplate> 
                            <asp:Label ID="Label_LEAD_NAME" runat="server" Text='<%# Bind("LEAD_INITIALS") %>'></asp:Label>&nbsp;  
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
 
                    <telerik:GridTemplateColumn HeaderText="Team" SortExpression="TEAM" HeaderStyle-HorizontalAlign="Left" AllowFiltering="false">  
                        <ItemStyle Width="65" /> 
                        <HeaderStyle Width="65" /> 
                        <EditItemTemplate> 
                            <div id='<%# "team_div" + (Eval("OPPORTUNITY_ID").ToString()) %>'   
                                onclick='<%# "showWin(\"#team" + (Eval("OPPORTUNITY_ID").ToString()) + "\");" %>' 
                                style="text-decoration:underline;"><%# EmptyToString(Eval("TEAM_INITIALS_LIST").ToString(), "&lt;none&gt;")%></div>  
                            <div id='<%# "team" + (Eval("OPPORTUNITY_ID").ToString()) %>' 
                                style="display:none;z-index:9000;position:absolute;border: 1px solid gray;background-color:white;margin-top:3px;">  
                                <div class="win-selector">  
                                    <asp:HiddenField ID="HiddenField_TeamInitials" runat="server" /> 
                                    <LtControls:CheckboxSelector runat="server" id="CheckboxSelector_Team" InitialValue='<%# Eval("TEAM_ID_LIST").ToString()%>' 
                                        DataTextField="INITIALS_C" DataValueField="ID" DataSourceID="SqlDataSource_Users"   
                                        ControlID_ToSet='<%# "team_div" + (Eval("OPPORTUNITY_ID").ToString()) %>' /> 
                                </div> 
                            </div> 
                        </EditItemTemplate> 
                        <ItemTemplate> 
                            <%# Eval("TEAM_INITIALS_LIST").ToString() %> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
 
                    <telerik:GridTemplateColumn HeaderText="Type" SortExpression="TYPE_C" ItemStyle-HorizontalAlign="Center" AllowFiltering="false">  
                        <ItemStyle Width="30" /> 
                        <HeaderStyle Width="30" /> 
                        <EditItemTemplate> 
                            <telerik:RadComboBox ID="TYPE_C" AllowCustomText="True" runat="server" Width="30" 
                                Height="70px" DataSourceID="SqlDataSource_Type" DataValueField="DISPLAY_NAME" DataTextField="DISPLAY_NAME" DropDownWidth="50"   
                                Text='<%# Bind("TYPE_C") %>' Filter="Contains" /> 
                        </EditItemTemplate> 
                        <ItemTemplate> 
                            <asp:Label ID="Label_TYPE_C" runat="server" Text='<%# Bind("TYPE_C") %>'></asp:Label>&nbsp;  
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                      
                    <telerik:GridTemplateColumn HeaderText="Round" SortExpression="ROUND_C" ItemStyle-HorizontalAlign="Center" AllowFiltering="false">  
                        <ItemStyle Width="30" /> 
                        <HeaderStyle Width="30" /> 
                        <EditItemTemplate> 
                            <telerik:RadComboBox ID="ROUND_C" AllowCustomText="True" runat="server"   
                                DataSourceID="SqlDataSource_Round" DataValueField="DISPLAY_NAME" DataTextField="DISPLAY_NAME"   
                                DropDownWidth="80"  Width="40" 
                                Text='<%# Bind("ROUND_C") %>' Filter="Contains" /> 
                        </EditItemTemplate> 
                        <ItemTemplate> 
                            <asp:Label ID="Label_ROUND_C" runat="server" Text='<%# Bind("Round_C") %>'></asp:Label>&nbsp;  
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                                                                                                          
                    <telerik:GridTemplateColumn HeaderText="Source" SortExpression="SOURCE_INITIALS" HeaderStyle-HorizontalAlign="Left" AllowFiltering="false">  
                        <ItemStyle Width="65" /> 
                        <HeaderStyle Width="65" /> 
                        <EditItemTemplate> 
                            <div id='<%# "source_div" + (Eval("OPPORTUNITY_ID").ToString()) %>'   
                                onclick='<%# "showWin(\"#source" + (Eval("OPPORTUNITY_ID").ToString()) + "\");" %>' 
                                style="text-decoration:underline;"><%# EmptyToString(Eval("SOURCE_INITIALS_LIST").ToString(), "&lt;none&gt;")%></div>  
                            <div id='<%# "source" + (Eval("OPPORTUNITY_ID").ToString()) %>' 
                                style="display:none;z-index:9000;position:absolute;border: 1px solid gray;background-color:white;margin-top:3px;">  
                                <div class="win-selector">  
                                    <asp:HiddenField ID="HiddenField_SourceInitials" runat="server" /> 
                                    <LtControls:CheckboxSelector runat="server" id="CheckboxSelector_Source" InitialValue='<%# Eval("SOURCE_ID_LIST").ToString()%>' 
                                        DataTextField="INITIALS_C" DataValueField="ID" DataSourceID="SqlDataSource_Users"   
                                        ControlID_ToSet='<%# "source_div" + (Eval("OPPORTUNITY_ID").ToString()) %>' /> 
                                </div> 
                            </div> 
                        </EditItemTemplate> 
                        <ItemTemplate> 
                            <%# Eval("SOURCE_INITIALS_LIST").ToString() %> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                      
                    <telerik:GridEditCommandColumn ItemStyle-Wrap="false"   
                        EditImageUrl="~/img/ico_note.png" UpdateImageUrl="~/img/ico_save.png"   
                        CancelImageUrl="~/img/ico_cancel.png" InsertImageUrl="~/img/ico_save.png"   
                        ButtonType="ImageButton">  
                        <ItemStyle Width="40" HorizontalAlign="Center" Wrap="false" /> 
                        <HeaderStyle Width="40" /> 
                    </telerik:GridEditCommandColumn> 
                      
                </Columns> 
                <EditFormSettings> 
                    <EditColumn UniqueName="EditCommandColumn1"></EditColumn> 
                </EditFormSettings> 
            </MasterTableView> 
            <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">  
            </ClientSettings> 
        </telerik:RadGrid> 
                      
    </ContentTemplate> 
</asp:UpdatePanel> 
 
<asp:UpdatePanel ID="UpdatePanel_Message" runat="server">  
    <ContentTemplate> 
    </ContentTemplate> 
</asp:UpdatePanel> 
 
<asp:HiddenField ID="HiddenField_TeamIdList" runat="server" /> 
<asp:HiddenField ID="HiddenField_SourceIdList" runat="server" /> 
<asp:Literal runat="server" ID="Literal_JS_Lists" /> 
 
<asp:SqlDataSource ID="SqlDataSource_Contacts" runat="server"   
    ConnectionString="<%$ ConnectionStrings:SplendidCRM_EnterpriseConnectionString %>"   
    SelectCommand="SELECT ID, FIRST_NAME + ' ' + LAST_NAME AS FULL_NAME FROM CONTACTS WHERE DELETED = 0 ORDER BY FIRST_NAME, LAST_NAME"   
    /> 
<asp:SqlDataSource ID="SqlDataSource_Users" runat="server"   
    ConnectionString="<%$ ConnectionStrings:SplendidCRM_EnterpriseConnectionString %>"   
    SelectCommand="SELECT ID, FIRST_NAME + ' ' + LAST_NAME AS FULL_NAME, INITIALS_C FROM USERS LEFT OUTER JOIN USERS_CSTM ON USERS.ID = USERS_CSTM.ID_C WHERE DELETED = 0 AND FIRST_NAME + ' ' + LAST_NAME <> '' ORDER BY FULL_NAME"   
    /> 
<asp:SqlDataSource ID="SqlDataSource_Industry" runat="server"   
    ConnectionString="<%$ ConnectionStrings:SplendidCRM_EnterpriseConnectionString %>"   
    SelectCommand="SELECT DISPLAY_NAME, LIST_ORDER FROM TERMINOLOGY WHERE LIST_NAME = 'industry_DOM' AND DISPLAY_NAME NOT LIKE '%|%' AND DELETED = 0 AND DISPLAY_NAME <> '' ORDER BY LIST_ORDER"   
    /> 
<asp:SqlDataSource ID="SqlDataSource_Industry_Sub" runat="server"   
    ConnectionString="<%$ ConnectionStrings:SplendidCRM_EnterpriseConnectionString %>"   
    SelectCommand="SELECT SUBSTRING(DISPLAY_NAME, 1, CHARINDEX('|',DISPLAY_NAME)-1) AS PARENT_NAME, SUBSTRING(DISPLAY_NAME, CHARINDEX('|',DISPLAY_NAME)+1, LEN(DISPLAY_NAME)) AS DISPLAY_NAME,  LIST_ORDER FROM TERMINOLOGY WHERE LIST_NAME = 'industry_DOM' AND DISPLAY_NAME LIKE '%|%' AND DELETED = 0 AND DISPLAY_NAME <> '' ORDER BY LIST_ORDER"   
    /> 
<asp:SqlDataSource ID="SqlDataSource_Round" runat="server"   
    ConnectionString="<%$ ConnectionStrings:SplendidCRM_EnterpriseConnectionString %>"   
    SelectCommand="SELECT DISPLAY_NAME, LIST_ORDER FROM TERMINOLOGY WHERE LIST_NAME = 'ROUND_DOM' AND DELETED = 0 AND NAME <> '' ORDER BY LIST_ORDER"   
    /> 
<asp:SqlDataSource ID="SqlDataSource_Type" runat="server"   
    ConnectionString="<%$ ConnectionStrings:SplendidCRM_EnterpriseConnectionString %>"   
    SelectCommand="SELECT DISPLAY_NAME, LIST_ORDER FROM TERMINOLOGY WHERE LIST_NAME = 'DEAL_TYPE_DOM' AND DELETED = 0 AND NAME <> '' ORDER BY LIST_ORDER"   
    /> 
<asp:SqlDataSource ID="SqlDataSource_Status" runat="server"   
    ConnectionString="<%$ ConnectionStrings:SplendidCRM_EnterpriseConnectionString %>"   
    SelectCommand="SELECT DISPLAY_NAME, LIST_ORDER FROM TERMINOLOGY WHERE LIST_NAME = 'OPPORTUNITY_STATUS_DOM' AND DELETED = 0 AND NAME <> '' ORDER BY LIST_ORDER"   
    /> 
<asp:SqlDataSource ID="SqlDataSource_Accounts" runat="server"   
    ConnectionString="<%$ ConnectionStrings:SplendidCRM_EnterpriseConnectionString %>"   
    SelectCommand="SELECT ID, NAME AS COMPANY_NAME FROM ACCOUNTS WHERE ACCOUNT_TYPE = 'PORTFOLIO COMPANY' ORDER BY NAME"   
    /> 
      
<asp:SqlDataSource ID="SqlDataSource_DealEntry" runat="server"   
    ConnectionString="<%$ ConnectionStrings:SplendidCRM_EnterpriseConnectionString %>"   
    SelectCommand="SELECT * FROM vwDealEntry order by STATUS_C DESC, COMPANY_NAME"   
    ProviderName="System.Data.SqlClient"   
> 
</asp:SqlDataSource> 
 
0
Mike West
Top achievements
Rank 1
answered on 02 Jul 2010, 06:24 PM
CodeBehind:
using System;  
using System.IO;  
using System.Data;  
using System.Data.SqlClient;  
using System.Data.Common;  
using System.Drawing;  
using System.Web;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using System.Web.UI.HtmlControls;  
using System.Diagnostics;  
using System.Collections;  
using System.Configuration;  
using System.Web.Security;  
using System.Web.UI.WebControls.WebParts;  
 
using Telerik.Web.UI;  
 
namespace SplendidCRM.Opportunities  
{  
    public partial class DealEntry : SplendidControl  
    {  
        public static string connString = ConfigurationManager.ConnectionStrings["SplendidCRM_EnterpriseConnectionString"].ConnectionString;  
        public string selectStatement = "SELECT * FROM vwDealEntry {0} order by STATUS_C DESC, COMPANY_NAME";  
 
        protected void Page_Load(object sender, EventArgs e)  
        {  
            if (!Page.IsPostBack)  
            {  
                Literal_JS_Lists.Text = "<script>\n";  
                Literal_JS_Lists.Text += "var team_list_id = '" + HiddenField_TeamIdList.ClientID + "';\n";  
                Literal_JS_Lists.Text += "var source_list_id = '" + HiddenField_SourceIdList.ClientID + "';\n";  
                Literal_JS_Lists.Text += "</script>\n";  
            }  
        }  
 
        protected void Account_DataBound(object sender, EventArgs e)  
        {  
            if (ViewState["COMPANY_NAME"] != null)  
            {  
                object objContainer = ((RadComboBox)sender).NamingContainer;  
                System.Type thisType = objContainer.GetType();  
                if (thisType.Name == "GridDataInsertItem")  
                {  
                    ((RadComboBox)sender).Text = ViewState["COMPANY_NAME"] + "";  
                    ViewState["COMPANY_NAME"] = null;  
                }  
            }  
        }  
 
        protected void Industry_DataBound(object sender, EventArgs e)  
        {  
            if (ViewState["INDUSTRY"] != null)  
            {  
                object objContainer = ((RadComboBox)sender).NamingContainer;  
                System.Type thisType = objContainer.GetType();  
                if (thisType.Name == "GridDataInsertItem")  
                {  
                    ((RadComboBox)sender).Text = ViewState["INDUSTRY"] + "";  
                    ViewState["INDUSTRY"] = null;  
                }  
            }  
        }  
 
        protected void Description_DataBound(object sender, EventArgs e)  
        {  
            if (ViewState["SHORT_DESCRIPTION_C"] != null)  
            {  
                object objContainer = ((TextBox)sender).NamingContainer;  
                System.Type thisType = objContainer.GetType();  
                if (thisType.Name == "GridDataInsertItem")  
                {  
                    ((TextBox)sender).Text = ViewState["SHORT_DESCRIPTION_C"] + "";  
                    ViewState["SHORT_DESCRIPTION_C"] = null;  
                }  
            }  
        }  
 
        //protected void RadGrid1_Load(object sender, EventArgs e)  
        //{  
        //    if (ViewState["SHOW_FILTER_ROW"] == null)  
        //    {  
        //        RadGrid1.MasterTableView.IsFilterItemExpanded = false;  
        //    }  
        //    else  
        //    {  
        //        RadGrid1.MasterTableView.FilterExpression = "";  
        //        RadGrid1.MasterTableView.IsFilterItemExpanded = true;  
        //    }  
        //}  
 
        protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
        {  
            if (e.CommandName == "Cancel")  
            {  
                RadGrid1.MasterTableView.FilterExpression = "";  
            }  
            if (e.CommandName == "PerformInsert")  
            {  
                RadGrid1.MasterTableView.FilterExpression = "";  
            }  
            if (e.CommandName == "InitInsert")  
            {  
 
                e.Item.OwnerTableView.FilterExpression = "";  
                e.Item.OwnerTableView.IsFilterItemExpanded = true;  
                ViewState["COMPANY_NAME"] = null;  
                ViewState["INDUSTRY"] = null;  
                ViewState["SHORT_DESCRIPTION_C"] = null;  
 
            }  
            if (e.CommandName == "Filter")  
            {  
                RadGrid1.MasterTableView.IsFilterItemExpanded = false;  
                  
                GridFilteringItem filterItem = (GridFilteringItem)e.CommandSource;  
                RadComboBox rcb = ((Telerik.Web.UI.RadComboBox)filterItem.FindControl("RadComboBox1TemplateColumn2"));  
                String rcbText = rcb.Text.Trim();  
 
                GridEditableItem insertItem = RadGrid1.MasterTableView.GetInsertItem();  
                
                DataTable dt = GetDataTable(String.Format(selectStatement, " where COMPANY_NAME = '" + rcbText + "' "));  
                if (dt.Rows.Count > 0)  
                {  
                    DataRow dr = dt.Rows[0];  
                    ((Telerik.Web.UI.RadComboBox)insertItem.FindControl("ACCOUNT_ID")).Text = dr["COMPANY_NAME"].ToString();  
                    ViewState["COMPANY_NAME"] = dr["COMPANY_NAME"].ToString();  
                    ((TextBox)insertItem.FindControl("SHORT_DESCRIPTION_C")).Text = dr["DESCRIPTION"].ToString();  
                    ViewState["SHORT_DESCRIPTION_C"] = dr["DESCRIPTION"].ToString();  
                    ((Telerik.Web.UI.RadComboBox)insertItem.FindControl("INDUSTRY")).Text = dr["INDUSTRY"].ToString();  
                    ViewState["INDUSTRY"] = dr["INDUSTRY"].ToString();  
                }  
 
            }  
        }  
 
        protected void list_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)  
        {  
 
            GridDataInsertItem filterItem = (GridDataInsertItem)((RadComboBox)o).NamingContainer;  
              
            //filtering for string column type  
            try 
            {  
                filterItem.FireCommandEvent("Filter"new Pair("Contains""COMPANY_NAME"));  
            }  
            catch (Exception e1) { string err = e1.ToString(); }  
        }  
 
 
        public string ShortDate(string p, bool defaultToday)  
        {  
            try 
            {  
                DateTime dateval = Convert.ToDateTime(p);  
                return dateval.ToShortDateString();  
            }  
            catch 
            {  
                return defaultToday ? DateTime.Now.ToShortDateString() : "";  
            }  
        }  
 
        private string GetRadComboBoxValue(Telerik.Web.UI.GridEditableItem item, string cbname)  
        {  
            string retval = "";  
            if (((Telerik.Web.UI.RadComboBox)item.FindControl(cbname)).Text.Trim() != "")  
            {  
                try 
                {  
                    retval = ((Telerik.Web.UI.RadComboBox)item.FindControl(cbname)).FindItemByText(((Telerik.Web.UI.RadComboBox)item.FindControl(cbname)).Text).Value;  
                }  
                catch 
                {  
                    //do nothing, allow retval = ""  
                }  
            }  
            return retval;  
        }  
 
        private string GetRadComboBoxText(Telerik.Web.UI.GridEditableItem item, string cbname)  
        {  
            string retval = "";  
            if (((Telerik.Web.UI.RadComboBox)item.FindControl(cbname)).Text.Trim() != "")  
            {  
                try 
                {  
                    retval = ((Telerik.Web.UI.RadComboBox)item.FindControl(cbname)).Text;  
                }  
                catch 
                {  
                    //do nothing, allow retval = ""  
                }  
            }  
            return retval;  
        }  
 
        private string EmptyStringToEmptyGuid(string s_in)  
        {  
            return (s_in == "") ? "00000000-0000-0000-0000-000000000000" : s_in;  
        }  
 
        protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)  
        {  
            DataTable dt = GetDataTable(String.Format(selectStatement, ""));  
            this.RadGrid1.DataSource = dt;  
        }  
 
        protected void RadGrid1_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)  
        {  
            Telerik.Web.UI.GridEditableItem item = (Telerik.Web.UI.GridEditableItem)e.Item;  
 
            string p_ID = "", p_ACCOUNT_ID = "", p_MODIFIED_USER_ID = "", p_STATUS_C = "", p_DEAL_DATE_C = "";  
            string p_ACCOUNT_NAME = "", p_SHORT_DESCRIPTION_C = "", p_INDUSTRY = "", p_ASSIGNED_USER_ID = "";  
            string p_TEAM_ID_LIST = "", p_TYPE_C = "", p_ROUND_C = "", p_SOURCE_ID_LIST = "";   
 
            p_ID = item.GetDataKeyValue("OPPORTUNITY_ID").ToString();  
            p_ACCOUNT_ID = GetRadComboBoxValue(item, "ACCOUNT_ID");  
            p_MODIFIED_USER_ID = Security.USER_ID.ToString();  
            p_STATUS_C = GetRadComboBoxValue(item, "STATUS_C");  
            p_DEAL_DATE_C = ((TextBox)item.FindControl("DEAL_DATE_C")).Text;  
            p_ACCOUNT_NAME = GetRadComboBoxText(item, "ACCOUNT_ID");  
            p_SHORT_DESCRIPTION_C = ((TextBox)item.FindControl("SHORT_DESCRIPTION_C")).Text;  
            p_INDUSTRY = GetRadComboBoxValue(item, "INDUSTRY");  
            p_ASSIGNED_USER_ID = GetRadComboBoxValue(item, "ASSIGNED_USER_ID");  
            p_TEAM_ID_LIST = ((HiddenField)item.FindControl("HiddenField_TeamInitials")).Value;  
            p_TYPE_C = GetRadComboBoxValue(item, "TYPE_C");  
            p_ROUND_C = GetRadComboBoxValue(item, "ROUND_C");  
            p_SOURCE_ID_LIST = ((HiddenField)item.FindControl("HiddenField_SourceInitials")).Value;  
 
            UpdateRow(p_ID, p_ACCOUNT_ID, p_STATUS_C, p_DEAL_DATE_C, p_ACCOUNT_NAME, p_SHORT_DESCRIPTION_C, p_INDUSTRY, p_ASSIGNED_USER_ID, p_TEAM_ID_LIST, p_TYPE_C, p_ROUND_C, p_SOURCE_ID_LIST);  
 
        }  
 
        protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)  
        {  
            Telerik.Web.UI.GridEditableItem item = (Telerik.Web.UI.GridEditableItem)e.Item;  
 
            string p_ID = "", p_ACCOUNT_ID = "", p_MODIFIED_USER_ID = "", p_STATUS_C = "", p_DEAL_DATE_C = "";  
            string p_ACCOUNT_NAME = "", p_SHORT_DESCRIPTION_C = "", p_INDUSTRY = "", p_ASSIGNED_USER_ID = "";  
            string p_TEAM_ID_LIST = "", p_TYPE_C = "", p_ROUND_C = "", p_SOURCE_ID_LIST = "";  
 
            //p_ID = item.GetDataKeyValue("OPPORTUNITY_ID").ToString();  
            p_ACCOUNT_ID = GetRadComboBoxValue(item, "ACCOUNT_ID");  
            p_MODIFIED_USER_ID = Security.USER_ID.ToString();  
            p_STATUS_C = GetRadComboBoxValue(item, "STATUS_C");  
            p_DEAL_DATE_C = ((TextBox)item.FindControl("DEAL_DATE_C")).Text;  
            p_ACCOUNT_NAME = GetRadComboBoxText(item, "ACCOUNT_ID");  
            p_SHORT_DESCRIPTION_C = ((TextBox)item.FindControl("SHORT_DESCRIPTION_C")).Text;  
            p_INDUSTRY = GetRadComboBoxValue(item, "INDUSTRY");  
            p_ASSIGNED_USER_ID = GetRadComboBoxValue(item, "ASSIGNED_USER_ID");  
            p_TEAM_ID_LIST = ((HiddenField)item.FindControl("HiddenField_TeamInitials")).Value;  
            p_TYPE_C = GetRadComboBoxValue(item, "TYPE_C");  
            p_ROUND_C = GetRadComboBoxValue(item, "ROUND_C");  
            p_SOURCE_ID_LIST = ((HiddenField)item.FindControl("HiddenField_SourceInitials")).Value;  
 
            UpdateRow(p_ID, p_ACCOUNT_ID, p_STATUS_C, p_DEAL_DATE_C, p_ACCOUNT_NAME, p_SHORT_DESCRIPTION_C, p_INDUSTRY, p_ASSIGNED_USER_ID, p_TEAM_ID_LIST, p_TYPE_C, p_ROUND_C, p_SOURCE_ID_LIST);  
 
        }  
 
        public string GetAccountUrl(System.Guid m_accountid)  
        {  
            return "~/Accounts/view.aspx?ID=" + m_accountid.ToString();  
        }  
 
        public void ShowMessage(string m_message)  
        {  
            try 
            {  
                UpdatePanel upd = (UpdatePanel)Page.Form.FindControl("UpdatePanel_Message");  
                SplendidCRM.Usercontrols.FadingMessage fm = (SplendidCRM.Usercontrols.FadingMessage)LoadControl("~/usercontrols/FadingMessage.ascx");  
                fm.ID = "FadingMessage_1";  
                fm.Message = m_message;  
                upd.ContentTemplateContainer.Controls.Add(fm);  
            }  
            catch 
            {  
            }  
        }  
 
        public string EmptyToString(string s_in, string s_replace)  
        {  
            return ((s_in == String.Empty) ? s_replace : s_in);  
        }  
 
        public string s_OPPORTUNITY_ID_INSERTED = "";  
   
        protected void RadGrid1_ItemInserted(object source, Telerik.Web.UI.GridInsertedEventArgs e)  
        {  
            string id = s_OPPORTUNITY_ID_INSERTED;  
        }  
 
        protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)  
        {  
            string id = s_OPPORTUNITY_ID_INSERTED;  
        }  
 
        protected int UpdateRow(string m_ID, string m_ACCOUNT_ID, string m_STATUS_C, string m_DEAL_DATE_C,   
            string m_ACCOUNT_NAME, string m_SHORT_DESCRIPTION_C, string m_INDUSTRY, string m_ASSIGNED_USER_ID,  
            string m_TEAM_ID_LIST, string m_TYPE_C, string m_ROUND_C, string m_SOURCE_ID_LIST)  
        {  
            int m_success = 0;  
            DbProviderFactory dbf = DbProviderFactories.GetFactory();  
            using ( IDbConnection con = dbf.CreateConnection() )  
            {  
                con.Open();  
                using ( IDbTransaction trn = Sql.BeginTransaction(con) )  
                {  
                    try 
                    {  
                        // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.   
                        // 12/29/2007 Paul.  TEAM_ID is now in the stored procedure.   
                        // 04/07/2010 Paul.  Add EXCHANGE_FOLDER.   
          
                        SqlProcs.spOPPORTUNITIES_UpdateRow  
                            ( m_ACCOUNT_NAME                              
                            , Sql.ToGuid(m_ID)  
                            , Sql.ToGuid(m_ACCOUNT_ID)  
                            , m_STATUS_C  
                            , Sql.ToDateTime(m_DEAL_DATE_C)  
                            , m_SHORT_DESCRIPTION_C  
                            , m_INDUSTRY  
                            , Sql.ToGuid(m_ASSIGNED_USER_ID)  
                            , m_TEAM_ID_LIST  
                            , m_TYPE_C  
                            , m_ROUND_C  
                            , m_SOURCE_ID_LIST  
                            , ref m_success  
                            , trn  
                            );  
                        if (m_success.Equals(1))  
                            trn.Commit();  
                        else throw new Exception("procedure returned an error");  
                    }  
                    catch(Exception ex)  
                    {  
                        trn.Rollback();  
                        SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);  
                    }  
                }  
            }  
            return m_success;  
        }  
 
        public static DataTable GetDataTable(string query)  
        {  
            SqlConnection conn = new SqlConnection(connString);  
            SqlDataAdapter adapter = new SqlDataAdapter();  
            adapter.SelectCommand = new SqlCommand(query, conn);  
            DataTable myDataTable = new DataTable();  
            conn.Open();  
            try 
            {  
                adapter.Fill(myDataTable);  
            }  
            finally 
            {  
                conn.Close();  
            }  
            return myDataTable;  
        }  
 
 
 
    }  
0
Mike West
Top achievements
Rank 1
answered on 02 Jul 2010, 06:26 PM
Screenshots attached:
0
Veli
Telerik team
answered on 06 Jul 2010, 11:11 AM
Hi Mike,

You need to set a boolean flag in RadGrid's ItemCommand event if your command is InitInsert or filter:

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.InitInsertCommandName)
    {
        hideFilterItem = false;
    }
 
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        hideFilterItem = true;
    }
}


You can then use the ItemCreated event to check the flag and set the filter and edit form item visibility:

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridFilteringItem)
    {
        e.Item.Visible = !hideFilterItem;
    }
 
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        e.Item.Visible = hideFilterItem;
    }
}

Following the scenario, when the Add New Record button is pressed, the filter item is shown instead of the edit form item. The user applies a filter, the filter item itself is hidden and the edit form item is shown.


Regards,
Veli
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
Mike West
Top achievements
Rank 1
Answers by
Mike West
Top achievements
Rank 1
Veli
Telerik team
Share this question
or