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

update control outside of nestedviewtemplate

9 Answers 199 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brett Sturgis
Top achievements
Rank 1
Brett Sturgis asked on 09 Jul 2010, 10:05 PM

Hello.  I have a radgrid with a nestedviewtemplate set up so that another rad grid is shown when each row of data is expanded.  I have a button within each row on the grid inside the nestedviewtemplate, and that button needs to make a div visible that is outside of both radgrids.  However, I cannot for the life of me get the div to appear.  I currently have the following for the RadAjaxManager:

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="pnlAddEdit" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting AjaxControlID="RadGrid2">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="RadAjaxLoadingPanel2" />
                <telerik:AjaxUpdatedControl ControlID="pnlAddEdit" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>

Is this correct or do I need that second setting?  There is also a button on each row in the outer grid that makes the pnlAddEdit div visible.  The button on the outer grid does make the div appear, but the button on the inner grid does not.  What else do I need to do?

9 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 14 Jul 2010, 01:15 PM
Hi Brett,

You do not need the second setting. Could you show how you are showing the div? Could you paste your entire aspx and code-behind?

Greetings,
Tsvetoslav
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
Brett Sturgis
Top achievements
Rank 1
answered on 20 Jul 2010, 08:42 PM
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="domaindns.aspx.cs" Inherits="ssl128cert.domaindns" MasterPageFile="MasterPages/Portal1.Master" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
  
<asp:Content ID="Content1" ContentPlaceHolderID="MainPlaceHolder" runat="server"
        <div id="pnlAddEdit" runat="server" visible="false">
            <table><tr><td><asp:Label runat="server">Domain: </asp:Label></td><td><asp:TextBox ID="tbDomain" runat="server"></asp:TextBox></td></tr>
            <tr><td><asp:Label runat="server">Data: </asp:Label></td><td><asp:TextBox ID="tbData" runat="server"></asp:TextBox></td></tr></table>
            <asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" />   <asp:Button 
                ID="btnCancel" runat="server" onclick="btnCancel_Click" Text="Cancel" /><br />
            <asp:Label ID="lblMsg" runat="server" style="color: Red"></asp:Label>
        </div><br />
        <asp:Label ID="lblHoldType" runat="server" Visible="false"></asp:Label><asp:Label ID="lblHoldAddEdit" runat="server" Visible="false"></asp:Label>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="pnlAddEdit" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadGrid2">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="RadAjaxLoadingPanel2" />
                        <telerik:AjaxUpdatedControl ControlID="pnlAddEdit" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>        
 <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Transparency="100" />
        <telerik:RadGrid ID="RadGrid1"
            runat="server" AutoGenerateColumns="False" AllowSorting="True" 
            AllowMultiRowSelection="False" Width="700"
            AllowPaging="True" PageSize="5" GridLines="None" ShowGroupPanel="true" OnItemCreated="RadGrid1_ItemCreated"
            OnItemCommand="RadGrid1_ItemCommand">
            <PagerStyle Mode="NumericPages"></PagerStyle>
            <MasterTableView DataKeyNames="Type" AllowMultiColumnSorting="True"
                GroupLoadMode="Server">
                <NestedViewTemplate>
                <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel2" runat="server" Transparency="100" />
                    <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="False" AllowSorting="True" AllowMultiRowSelection="False"
                        AllowPaging="True" PageSize="5" GridLines="None" ShowGroupPanel="true"
                        OnItemCommand="RadGrid2_ItemCommand">
                        <PagerStyle Mode="NumericPages"></PagerStyle>
                        <MasterTableView DataKeyNames="Type" AllowMultiColumnSorting="True"
                            GroupLoadMode="Server">
                            <Columns>
                                <telerik:GridBoundColumn SortExpression="Domain" HeaderText="Domain" HeaderButtonType="TextButton"
                                    DataField="Domain" UniqueName="Domain"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn SortExpression="Data" HeaderText="Data" HeaderButtonType="TextButton"
                                    DataField="Data" UniqueName="Data"></telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn>
                                    <ItemTemplate>
<%--                                        <asp:Button id="btnEdit" Runat="server" Text="Edit" CssClass="flatbutton" 
                                            CommandName="Edit"></asp:Button>--%>
                                                        <asp:imageButton ImageUrl="images/editgreen.gif" ID="btnEdit" 
                                                        runat="server" Width="55" Height="18" CommandName="Edit" />
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn>
                                    <ItemTemplate>
                                        <asp:Button id="btnDelete" Runat="server" Text="Delete" CssClass="flatbutton" CommandName="Delete"></asp:Button>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>                                    
                            </Columns>            
                        </MasterTableView>
                    </telerik:RadGrid>
                </NestedViewTemplate>
                <Columns>
                    <telerik:GridBoundColumn SortExpression="Type" HeaderText="Type" HeaderButtonType="TextButton"
                        DataField="Type" UniqueName="Type"><HeaderStyle Width="550" /></telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn>
                                    <ItemTemplate>
                                        <asp:Button id="btnAdd" Runat="server" Text="Add" CssClass="flatbutton" CommandName="Add"></asp:Button>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>                                       
                </Columns>
            </MasterTableView>
        </telerik:RadGrid
</asp:Content>
  
     


and codebehind:
 

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
  
namespace ssl128cert
{
    public partial class domaindns : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //dt = QueryHandler.GetDataTable("select * from [domain_dns]", CommandType.Text);
  
            //RadGrid1.MasterTableView.DataSource = dt;
            //RadGrid1.MasterTableView.DataBind();
            //RadGrid1.DataSource = dt;
            //RadGrid1.DataBind();
            InitializeComponent();
            bindData();
        }
  
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }
  
        private void InitializeComponent()
        {
            this.RadGrid1.ItemCommand += new Telerik.Web.UI.GridCommandEventHandler(this.RadGrid1_ItemCommand);
            this.RadGrid1.PageIndexChanged += new Telerik.Web.UI.GridPageChangedEventHandler(this.RadGrid1_PageIndexChanged);
            this.RadGrid1.SortCommand += new Telerik.Web.UI.GridSortCommandEventHandler(this.RadGrid1_SortCommand);
        }
  
        //private void RadGrid2_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        //{
        //    if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Item || e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem)
        //    {
        //        Button btnAdd = (Button)e.Item.FindControl("btnAdd");
  
        //        //btnAdd.CommandArgument = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Domain"));
        //        btnAdd.CommandName = "Add";
        //    }
        //}
  
        private void bindData()
        {
            DataTable dt = new DataTable();
            ArrayList names = new ArrayList();
            ArrayList values = new ArrayList();
            ArrayList types = new ArrayList();
  
            dt = QueryHandler.GetDataTable("select distinct Type as Type from [domain_dns]", CommandType.Text);
  
            DataView viewPages = dt.DefaultView;
            viewPages.Sort = Convert.ToString(ViewState["vs_SortOrderBy"]);
            this.RadGrid1.DataSource = viewPages;
            RadGrid1.MasterTableView.DataKeyNames = new string[] { "Type" };
            RadGrid1.DataBind();
            RadGrid1.SelectedIndexes.Clear();
            //ViewState["vs_IndexSelected"]=-1;
            ViewState["vs_dtPages"] = dt;
        }
  
        protected void RadGrid1_PreRender(object sender, EventArgs e)
        {
            //if (!Page.IsPostBack)
            //{
            //    RadGrid1.MasterTableView.Items[0].Expanded = true;
            //    RadGrid1.MasterTableView.Items[0].ChildItem.FindControl("InnerContainer").Visible = true;
            //}
        }
  
        protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.ExpandCollapseCommandName)
            {
                ((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2").Visible =
                    !e.Item.Expanded;
  
                GridEditableItem gridItem = e.Item as GridEditableItem;
                DataTable dt = QueryHandler.GetDataTable("select * from [domain_dns] where Type = '" + gridItem["Type"].Text + "'", CommandType.Text);
                  
                ((((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2")) as RadGrid).MasterTableView.DataSource = dt;
                ((((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2")) as RadGrid).MasterTableView.DataBind();
                ((((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2")) as RadGrid).DataSource = dt;
                ((((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2")) as RadGrid).DataBind();
            }
            if (e.CommandName == "Add")
            {
                GridEditableItem editItem = e.Item as GridEditableItem;
                this.pnlAddEdit.Visible = true;
                lblHoldType.Text = editItem["Type"].Text;
                lblHoldAddEdit.Text = "Add";
            }
        }
  
        protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            //GridPagerItem gridItem = e.Item as GridPagerItem;
            //DataTable dt = QueryHandler.GetDataTable("select * from [domain_dns] where Type = " + (GridEditableItem)gridItem, CommandType.Text);
  
            //if (e.Item is GridNestedViewItem)
            //{
            //    (e.Item.FindControl("RadGrid2") as RadGrid).MasterTableView.DataSource = dt;
            //    (e.Item.FindControl("RadGrid2") as RadGrid).MasterTableView.DataBind();
            //    (e.Item.FindControl("RadGrid2") as RadGrid).DataSource = dt;
            //    (e.Item.FindControl("RadGrid2") as RadGrid).DataBind();
            //}
        }
  
        protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e)
        {
            GridEditableItem editItem = e.Item as GridEditableItem;
            if (e.CommandName == "Edit")
            {
                AjaxSetting setOne = new AjaxSetting();
                setOne.AjaxControlID = "RadGrid2";
                AjaxUpdatedControl updOne = new AjaxUpdatedControl();
                updOne.ControlID = "RadGrid2";
                updOne.LoadingPanelID = "RadAjaxLoadingPanel2";
                AjaxUpdatedControl updTwo = new AjaxUpdatedControl();
                updTwo.ControlID = "pnlAddEdit";
                setOne.UpdatedControls.Add(updOne);
                setOne.UpdatedControls.Add(updTwo);
                RadAjaxManager1.AjaxSettings.Add(setOne);
  
                RadAjaxManager1.Controls.Add(((((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2")) as RadGrid));
  
                this.pnlAddEdit.Visible = true;
                tbDomain.Text = editItem["Domain"].Text;
                tbData.Text = editItem["Data"].Text;
                lblHoldAddEdit.Text = "Edit";
            }
            if (e.CommandName == "Delete")
            {
                string[] names = new string[1];
                ArrayList values = new ArrayList();
                SqlDbType[] types = new SqlDbType[1];
  
                names[0] = "@Domain";
                values.Add(editItem["Domain"].Text);
                types[0] = SqlDbType.NVarChar;
  
                //int iRes = QueryHandler.ExecuteSQL("delete from email_map where EmailMapId=" + iID, CommandType.Text);
                int iRes = QueryHandler.ExecuteSQL("secure128_dt_delDomainDns", ref names, ref values, ref types);
            }
        }
  
        private void RadGrid1_SortCommand(object source, Telerik.Web.UI.GridSortCommandEventArgs e)
        {
            if (e.SortExpression.ToString() == Convert.ToString(ViewState["vs_SortField"]))
            {
                if (Convert.ToString(ViewState["vs_SortOrder"]) == "ASC")
                {
                    ViewState["vs_SortOrderBy"] = e.SortExpression.ToString() + " DESC";
                    ViewState["vs_SortOrder"] = "DESC";
                }
                else
                {
                    ViewState["vs_SortOrderBy"] = e.SortExpression.ToString() + " ASC";
                    ViewState["vs_SortOrder"] = "ASC";
                }
            }
            else
            {
                ViewState["vs_SortOrderBy"] = e.SortExpression.ToString() + " ASC";
                ViewState["vs_SortOrder"] = "ASC";
            }
            ViewState["vs_SortField"] = e.SortExpression.ToString();
            this.bindData();
        }
  
        private void RadGrid1_PageIndexChanged(object source, Telerik.Web.UI.GridPageChangedEventArgs e)
        {
            RadGrid1.CurrentPageIndex = e.NewPageIndex;
            RadGrid1.SelectedIndexes.Clear();
            RadGrid1.DataSource = (DataTable)ViewState["vs_dtPages"];
            bindData();
        }
  
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            tbDomain.Text = "";
            tbData.Text = "";
            pnlAddEdit.Visible = false;
        }
  
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string[] names = new string[3];
                ArrayList values = new ArrayList();
                SqlDbType[] types = new SqlDbType[3];
  
                names[0] = "@Domain";
                names[1] = "@Type";
                names[2] = "@Data";
  
                types[0] = SqlDbType.NVarChar;
                types[1] = SqlDbType.NVarChar;
                types[2] = SqlDbType.NVarChar;
  
                values.Add(tbDomain.Text);
                values.Add(lblHoldType.Text);
                values.Add(tbData.Text);
  
                if (lblHoldAddEdit.Text == "Add")
                {
                    QueryHandler.ExecuteSQL("secure128_dt_addDomainDns", ref names, ref values, ref types);
                }
                if (lblHoldAddEdit.Text == "Edit")
                {
                    QueryHandler.ExecuteSQL("secure128_dt_updDomainDns", ref names, ref values, ref types);
                }
                lblMsg.Text = "Update Successful";
            }
            catch (Exception ex)
            {
                string strMsg = ex.ToString();
            }
  
        }
  
        //protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        //{
        //    if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Item || e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem)
        //    {
        //        Button btnDelete = (Button)e.Item.FindControl("btnDelete");
        //        Button btnEdit = (Button)e.Item.FindControl("btnEdit");
  
        //        btnDelete.CommandArgument = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Domain"));
        //        btnDelete.CommandName = "Delete";
  
        //        btnEdit.CommandArgument = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Domain"));
        //        btnEdit.CommandName = "Edit";
  
        //    }
        //}
    }
}
0
Brett Sturgis
Top achievements
Rank 1
answered on 21 Jul 2010, 05:43 PM
Something else I am running into now is I am trying to bind the datasource for the RadGrid2 on the

 

RadGrid1_ItemCreated procedure.  However, I need to get a value from a specific column on the RadGrid1 in order to set the datasource for the RadGrid2.  However, I can only define the incoming value as follows:

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    GridPagerItem gridItem = e.Item as GridPagerItem;

I cannot figure out how to get a value from a specific column from the GridPagerItem.  Is this possible?
0
Tsvetoslav
Telerik team
answered on 23 Jul 2010, 12:09 PM
Hi Brett,

I'd like to pay your attention to a couple of points:

1. You need to use only Advanced databinding vs Simple databinding, therefore, try reworking the code along the lines of the former one.

2. You must remove all declarative and programmatic ajax settings for the second grid and leave those just for the first one.

Regards,
Tsvetoslav
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
Brett Sturgis
Top achievements
Rank 1
answered on 26 Jul 2010, 08:26 PM
Tsvetoslav, I thank you for your help.  I now have a new problem.  I don't know if you will be able to tell what's going on just by looking at it, but i will attach my updated code as well.  The problem is now that when I click on one of the buttons in the nested RadGrid, for some odd reason the div at the top with the textboxes appears on the row that I click on.  I am not sure what's causing that.  Maybe you can look and see if you have any ideas.  Thanks.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="domaindns.aspx.cs" Inherits="ssl128cert.domaindns" MasterPageFile="MasterPages/Main.Master" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
  
<asp:Content ID="Content1" ContentPlaceHolderID="MainPlaceHolder" runat="server">                 
        <div id="pnlAddEdit" runat="server" visible="false">
            <table><tr><td><asp:Label runat="server">Domain: </asp:Label></td><td><asp:TextBox ID="tbDomain" runat="server"></asp:TextBox></td></tr>
            <tr><td><asp:Label runat="server">Data: </asp:Label></td><td><asp:TextBox ID="tbData" runat="server"></asp:TextBox></td></tr></table>
            <asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" />   <asp:Button 
                ID="btnCancel" runat="server" onclick="btnCancel_Click" Text="Cancel" /><br />
            <asp:Label ID="lblMsg" runat="server" style="color: Red"></asp:Label>
        </div><br />
        <asp:Label ID="lblHoldType" runat="server" Visible="false"></asp:Label><asp:Label ID="lblHoldAddEdit" runat="server" Visible="false"></asp:Label>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />    
                        <telerik:AjaxUpdatedControl ControlID="pnlAddEdit" />                    
                    </UpdatedControls>
                </telerik:AjaxSetting>
<%--                <telerik:AjaxSetting AjaxControlID="RadGrid2">
                    <UpdatedControls>
  
                        <telerik:AjaxUpdatedControl ControlID="pnlAddEdit" />
                    </UpdatedControls>
                </telerik:AjaxSetting>--%>
            </AjaxSettings>
        </telerik:RadAjaxManager>        
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Transparency="100" />        
        <telerik:RadGrid ID="RadGrid1"
            runat="server" AutoGenerateColumns="False" AllowSorting="True" 
            AllowMultiRowSelection="False" Width="700"
            AllowPaging="True" PageSize="5" GridLines="None" ShowGroupPanel="true" OnItemCreated="RadGrid1_ItemCreated"
            OnItemCommand="RadGrid1_ItemCommand" 
            onitemdatabound="RadGrid1_ItemDataBound" 
            oniteminserted="RadGrid1_ItemInserted">
            <PagerStyle Mode="NumericPages"></PagerStyle>
            <MasterTableView DataKeyNames="Type" AllowMultiColumnSorting="True"
                GroupLoadMode="Server">
                <NestedViewTemplate>
                    <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="False" AllowSorting="True" AllowMultiRowSelection="False"
                        AllowPaging="True" PageSize="5" GridLines="None" ShowGroupPanel="true"
                        OnItemCommand="RadGrid2_ItemCommand">
                        <ClientSettings EnablePostBackOnRowClick="true" ></ClientSettings>
                        <PagerStyle Mode="NumericPages"></PagerStyle>
                        <MasterTableView>
                            <Columns>
                                <telerik:GridBoundColumn SortExpression="Domain" HeaderText="Domain" HeaderButtonType="TextButton"
                                    DataField="Domain" UniqueName="Domain"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn SortExpression="Data" HeaderText="Data" HeaderButtonType="TextButton"
                                    DataField="Data" UniqueName="Data"></telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn>
                                    <ItemTemplate>
<%--                                        <asp:Button id="btnEdit" Runat="server" Text="Edit" CssClass="flatbutton" 
                                            CommandName="Edit"></asp:Button>--%>
                                                        <asp:imageButton ImageUrl="images/editgreen.gif" ID="btnEdit" 
                                                        runat="server" Width="55" Height="18" CommandName="Edit" />
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn>
                                    <ItemTemplate>
                                        <asp:Button id="btnDelete" Runat="server" Text="Delete" CssClass="flatbutton" CommandName="Delete"></asp:Button>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>                                    
                            </Columns>            
                        </MasterTableView>
                    </telerik:RadGrid>
                </NestedViewTemplate>
                <Columns>
                    <telerik:GridBoundColumn SortExpression="Type" HeaderText="Type" HeaderButtonType="TextButton"
                        DataField="Type" UniqueName="Type"><HeaderStyle Width="550" /></telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn>
                                    <ItemTemplate>
                                        <asp:Button id="btnAdd" Runat="server" Text="Add" CssClass="flatbutton" CommandName="Add"></asp:Button>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>                                       
                </Columns>
            </MasterTableView>
        </telerik:RadGrid
</asp:Content>
  
     


codebehind:

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
  
namespace ssl128cert
{
    public partial class domaindns : System.Web.UI.Page
    {
        DataTable dtInside;
        RadGrid RadGrid2;
  
        protected void Page_Load(object sender, EventArgs e)
        {
            //dt = QueryHandler.GetDataTable("select * from [domain_dns]", CommandType.Text);
  
            //RadGrid1.MasterTableView.DataSource = dt;
            //RadGrid1.MasterTableView.DataBind();
            //RadGrid1.DataSource = dt;
            //RadGrid1.DataBind();
            InitializeComponent();
            //bindData();
  
            if (!IsPostBack)
            {
                DataTable dt = new DataTable();
                ArrayList names = new ArrayList();
                ArrayList values = new ArrayList();
                ArrayList types = new ArrayList();
  
                dt = QueryHandler.GetDataTable("select distinct Type as Type from [domain_dns]", CommandType.Text);
  
                DataView viewPages = dt.DefaultView;
                viewPages.Sort = Convert.ToString(ViewState["vs_SortOrderBy"]);
                this.RadGrid1.DataSource = viewPages;
                RadGrid1.MasterTableView.DataKeyNames = new string[] { "Type" };
                RadGrid1.DataBind();
                RadGrid1.SelectedIndexes.Clear();
                //ViewState["vs_IndexSelected"]=-1;
                ViewState["vs_dtPages"] = dt;
            }
  
  
        }
  
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }
  
        private void InitializeComponent()
        {
            this.RadGrid1.ItemCommand += new Telerik.Web.UI.GridCommandEventHandler(this.RadGrid1_ItemCommand);
            this.RadGrid1.PageIndexChanged += new Telerik.Web.UI.GridPageChangedEventHandler(this.RadGrid1_PageIndexChanged);
            this.RadGrid1.SortCommand += new Telerik.Web.UI.GridSortCommandEventHandler(this.RadGrid1_SortCommand);
            //this.RadGrid2.ItemCommand += new Telerik.Web.UI.GridCommandEventHandler(this.RadGrid2_ItemCommand);
        }
  
        //private void RadGrid2_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        //{
        //    if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Item || e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem)
        //    {
        //        Button btnAdd = (Button)e.Item.FindControl("btnAdd");
  
        //        //btnAdd.CommandArgument = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Domain"));
        //        btnAdd.CommandName = "Add";
        //    }
        //}
  
        private void bindData()
        {
            DataTable dt = new DataTable();
            ArrayList names = new ArrayList();
            ArrayList values = new ArrayList();
            ArrayList types = new ArrayList();
  
            dt = QueryHandler.GetDataTable("select distinct Type as Type from [domain_dns]", CommandType.Text);
  
            DataView viewPages = dt.DefaultView;
            viewPages.Sort = Convert.ToString(ViewState["vs_SortOrderBy"]);
            this.RadGrid1.DataSource = viewPages;
            RadGrid1.MasterTableView.DataKeyNames = new string[] { "Type" };
            RadGrid1.DataBind();
            RadGrid1.SelectedIndexes.Clear();
            //ViewState["vs_IndexSelected"]=-1;
            ViewState["vs_dtPages"] = dt;
        }
  
        protected void RadGrid1_PreRender(object sender, EventArgs e)
        {
            //if (!Page.IsPostBack)
            //{
            //    RadGrid1.MasterTableView.Items[0].Expanded = true;
            //    RadGrid1.MasterTableView.Items[0].ChildItem.FindControl("InnerContainer").Visible = true;
            //}
        }
  
        protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.ExpandCollapseCommandName)
            {
                ((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2").Visible =
                    !e.Item.Expanded;
  
                GridEditableItem gridItem = e.Item as GridEditableItem;
                dtInside = QueryHandler.GetDataTable("select * from [domain_dns] where Type = '" + gridItem["Type"].Text + "'", CommandType.Text);
                RadGrid2 = (((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2") as RadGrid);
                //(((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2") as RadGrid).Rebind();
                RadGrid2.DataSource = dtInside;
                RadGrid2.DataBind();
                //((((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2")) as RadGrid).MasterTableView.DataSource = dt;
                //((((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2")) as RadGrid).MasterTableView.DataBind();
                //((((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2")) as RadGrid).DataSource = dt;
                //((((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2")) as RadGrid).DataBind();
            }
            if (e.CommandName == "Add")
            {
                GridEditableItem editItem = e.Item as GridEditableItem;
                this.pnlAddEdit.Visible = true;
                lblHoldType.Text = editItem["Type"].Text;
                lblHoldAddEdit.Text = "Add";
            }
        }
  
        protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            //GridItem gridItem = e.Item as GridItem;
            //dtInside = QueryHandler.GetDataTable("select * from [domain_dns] where Type = '" + ((GridEditableItem)gridItem)["Type"].Text + "'", CommandType.Text);
  
            //if (e.Item is GridNestedViewItem)
            //{
            //    (e.Item.FindControl("RadGrid2") as RadGrid).MasterTableView.DataSource = dt;
            //    (e.Item.FindControl("RadGrid2") as RadGrid).MasterTableView.DataBind();
            //    (e.Item.FindControl("RadGrid2") as RadGrid).DataSource = dt;
            //    (e.Item.FindControl("RadGrid2") as RadGrid).DataBind();
            //}
  
            if (e.Item is GridNestedViewItem)
            {
                //RadGrid2 = (e.Item.FindControl("RadGrid2") as RadGrid);
                //(e.Item.FindControl("RadGrid2") as RadGrid).NeedDataSource += new GridNeedDataSourceEventHandler(this.RadGrid2_NeedDataSource);
                (e.Item.FindControl("RadGrid2") as RadGrid).ItemCommand += new GridCommandEventHandler(this.RadGrid2_ItemCommand);
                //RadGrid2.Rebind();
            }
        }
  
        protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e)
        {
            GridEditableItem editItem = e.Item as GridEditableItem;
            if (e.CommandName == "Edit")
            {
                //AjaxSetting setOne = new AjaxSetting();
                //setOne.AjaxControlID = "RadGrid2";
                //AjaxUpdatedControl updOne = new AjaxUpdatedControl();
                //updOne.ControlID = "RadGrid2";
                //updOne.LoadingPanelID = "RadAjaxLoadingPanel2";
                //AjaxUpdatedControl updTwo = new AjaxUpdatedControl();
                //updTwo.ControlID = "pnlAddEdit";
                //setOne.UpdatedControls.Add(updOne);
                //setOne.UpdatedControls.Add(updTwo);
                //RadAjaxManager1.AjaxSettings.Add(setOne);
  
                //RadAjaxManager1.Controls.Add(((((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2")) as RadGrid));
  
                this.pnlAddEdit.Visible = true;
                tbDomain.Text = editItem["Domain"].Text;
                tbData.Text = editItem["Data"].Text;
                lblHoldAddEdit.Text = "Edit";
            }
            if (e.CommandName == "Delete")
            {
                string[] names = new string[1];
                ArrayList values = new ArrayList();
                SqlDbType[] types = new SqlDbType[1];
  
                names[0] = "@Domain";
                values.Add(editItem["Domain"].Text);
                types[0] = SqlDbType.NVarChar;
  
                //int iRes = QueryHandler.ExecuteSQL("delete from email_map where EmailMapId=" + iID, CommandType.Text);
                int iRes = QueryHandler.ExecuteSQL("secure128_dt_delDomainDns", ref names, ref values, ref types);
            }
        }
  
        private void RadGrid1_SortCommand(object source, Telerik.Web.UI.GridSortCommandEventArgs e)
        {
            if (e.SortExpression.ToString() == Convert.ToString(ViewState["vs_SortField"]))
            {
                if (Convert.ToString(ViewState["vs_SortOrder"]) == "ASC")
                {
                    ViewState["vs_SortOrderBy"] = e.SortExpression.ToString() + " DESC";
                    ViewState["vs_SortOrder"] = "DESC";
                }
                else
                {
                    ViewState["vs_SortOrderBy"] = e.SortExpression.ToString() + " ASC";
                    ViewState["vs_SortOrder"] = "ASC";
                }
            }
            else
            {
                ViewState["vs_SortOrderBy"] = e.SortExpression.ToString() + " ASC";
                ViewState["vs_SortOrder"] = "ASC";
            }
            ViewState["vs_SortField"] = e.SortExpression.ToString();
            this.bindData();
        }
  
        private void RadGrid1_PageIndexChanged(object source, Telerik.Web.UI.GridPageChangedEventArgs e)
        {
            RadGrid1.CurrentPageIndex = e.NewPageIndex;
            RadGrid1.SelectedIndexes.Clear();
            RadGrid1.DataSource = (DataTable)ViewState["vs_dtPages"];
            bindData();
        }
  
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            tbDomain.Text = "";
            tbData.Text = "";
            pnlAddEdit.Visible = false;
        }
  
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string[] names = new string[3];
                ArrayList values = new ArrayList();
                SqlDbType[] types = new SqlDbType[3];
  
                names[0] = "@Domain";
                names[1] = "@Type";
                names[2] = "@Data";
  
                types[0] = SqlDbType.NVarChar;
                types[1] = SqlDbType.NVarChar;
                types[2] = SqlDbType.NVarChar;
  
                values.Add(tbDomain.Text);
                values.Add(lblHoldType.Text);
                values.Add(tbData.Text);
  
                if (lblHoldAddEdit.Text == "Add")
                {
                    QueryHandler.ExecuteSQL("secure128_dt_addDomainDns", ref names, ref values, ref types);
                }
                if (lblHoldAddEdit.Text == "Edit")
                {
                    QueryHandler.ExecuteSQL("secure128_dt_updDomainDns", ref names, ref values, ref types);
                }
                lblMsg.Text = "Update Successful";
            }
            catch (Exception ex)
            {
                string strMsg = ex.ToString();
            }
  
        }
  
        protected void RadGrid1_ItemInserted(object source, GridInsertedEventArgs e)
        {
            //GridEditableItem editItem = e.Item as GridEditableItem;
  
            //DataTable dt = QueryHandler.GetDataTable("select * from [domain_dns] where Type = '" + ((GridEditableItem)editItem)["Type"].Text + "'", CommandType.Text);
        }
  
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            //GridEditableItem editItem = e.Item as GridEditableItem;
  
            //DataTable dt = QueryHandler.GetDataTable("select * from [domain_dns] where Type = '" + ((GridEditableItem)editItem)["Type"].Text + "'", CommandType.Text);
        }
  
        //protected DataTable
  
        //protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        //{
        //    if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Item || e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem)
        //    {
        //        Button btnDelete = (Button)e.Item.FindControl("btnDelete");
        //        Button btnEdit = (Button)e.Item.FindControl("btnEdit");
  
        //        btnDelete.CommandArgument = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Domain"));
        //        btnDelete.CommandName = "Delete";
  
        //        btnEdit.CommandArgument = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Domain"));
        //        btnEdit.CommandName = "Edit";
  
        //    }
        //}
    }
}
0
Tsvetoslav
Telerik team
answered on 29 Jul 2010, 09:56 AM
Hi Brett,

I do not see your having reworked your code to use Advanced databinding - one of the requirements for that is to not bind the grid on PageLoad(). What happens I suspect is that upon clicking the row the grid posts back as you have EnablePostBackOnRowClick = true. And upon the post back your code behind makes the div visible. But still the main culprit is the Simple databinding that you are using all over the code-behind. Do make a careful review of the examples and the related help topics pointed to in my previous post.

All the best,
Tsvetoslav
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
Brett Sturgis
Top achievements
Rank 1
answered on 29 Jul 2010, 07:16 PM
Ok.  Thank you.  I will rework it to incorporate the advanced databinding.
0
Brett Sturgis
Top achievements
Rank 1
answered on 29 Jul 2010, 09:56 PM
Ok.  Lol.  New problem.  I now have the expansions working correctly, but I want to just implement an editform so that when the user clicks "edit" on a row in the inside grid they can change the values in the textboxes then click the "update" link button and then update the record in the database.  However, right now when I click "update" I cannot figure out why neither the "RadGrid2_ItemUpdated" or "RadGrid2_UpdateCommand" procedures are being triggered.  Which one should be triggered?  I found an example on the telerik website that is similar to this, but the datasource is specified within the .aspx file.  I do not want to do that.  Does that have anything to do with why my events are not being triggered?  I just want to be able to get the correct event to be triggered so I can call an executesql in the codebehind and update the table in that manner.  I will attach my .aspx and codebehind.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="domaindns.aspx.cs" Inherits="ssl128cert.domaindns" MasterPageFile="MasterPages/Main.Master" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
  
<asp:Content ID="Content1" ContentPlaceHolderID="MainPlaceHolder" runat="server">                 
        <asp:Label ID="lblHoldType" runat="server" Visible="false"></asp:Label><asp:Label ID="lblHoldAddEdit" runat="server" Visible="false"></asp:Label>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />    
                        <telerik:AjaxUpdatedControl ControlID="pnlAddEdit" />                    
                    </UpdatedControls>
                </telerik:AjaxSetting>
<%--                <telerik:AjaxSetting AjaxControlID="RadGrid2">
                    <UpdatedControls>
  
                        <telerik:AjaxUpdatedControl ControlID="pnlAddEdit" />
                    </UpdatedControls>
                </telerik:AjaxSetting>--%>
            </AjaxSettings>
        </telerik:RadAjaxManager>        
        <div id="divMsg" runat="server"><asp:Label id="label1" runat="server"></asp:Label></div>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Transparency="100" />        
        <telerik:RadGrid ID="RadGrid1"
            runat="server" AutoGenerateColumns="False" AllowSorting="True" 
            AllowMultiRowSelection="False" Width="700"
            AllowPaging="True" PageSize="5" GridLines="None" ShowGroupPanel="true" OnItemCreated="RadGrid1_ItemCreated"
            OnItemCommand="RadGrid1_ItemCommand" 
            onitemdatabound="RadGrid1_ItemDataBound" 
            oniteminserted="RadGrid1_ItemInserted" 
            onneeddatasource="RadGrid1_NeedDataSource"
            OnItemUpdated="RadGrid2_ItemUpdated"
            OnUpdateCommand="RadGrid2_UpdateCommand">
            <PagerStyle Mode="NumericPages"></PagerStyle>
            <MasterTableView DataKeyNames="Type" AllowMultiColumnSorting="True"
                GroupLoadMode="Server">
                <NestedViewTemplate>
                    <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="False" AllowSorting="True" AllowMultiRowSelection="False"
                        AllowPaging="True" PageSize="5" GridLines="None" ShowGroupPanel="true"
                        OnItemCommand="RadGrid2_ItemCommand"
                        OnItemUpdated="RadGrid2_ItemUpdated"
                        OnUpdateCommand="RadGrid2_UpdateCommand">
                        <PagerStyle Mode="NumericPages"></PagerStyle>
                        <MasterTableView>
                            <Columns>
                                <telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
                                </telerik:GridEditCommandColumn>                            
                                <telerik:GridBoundColumn SortExpression="Domain" HeaderText="Domain" HeaderButtonType="TextButton"
                                    DataField="Domain" UniqueName="Domain"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn SortExpression="Data" HeaderText="Data" HeaderButtonType="TextButton"
                                    DataField="Data" UniqueName="Data"></telerik:GridBoundColumn>
<%--                                <telerik:GridTemplateColumn>
                                    <ItemTemplate>
                                        <asp:Button id="btnEdit" Runat="server" Text="Edit" CssClass="flatbutton" 
                                            CommandName="Edit"></asp:Button>
                                                        <asp:imageButton ImageUrl="images/editgreen.gif" ID="btnEdit" 
                                                        runat="server" Width="55" Height="18" CommandName="Edit" />
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>--%>
                                <telerik:GridTemplateColumn>
                                    <ItemTemplate>
                                        <asp:Button id="btnDelete" Runat="server" Text="Delete" CssClass="flatbutton" CommandName="Delete"></asp:Button>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>                                    
                            </Columns>           
            <EditFormSettings ColumnNumber="3" CaptionFormatString=""
                CaptionDataField="">
                <FormTableItemStyle Wrap="False"></FormTableItemStyle>
                <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
                <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" Width="100%" />
                <FormTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="2" CssClass="module"
                    Height="110px" Width="100%" />
                <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                <FormStyle Width="100%" BackColor="#eef2ea"></FormStyle>
                <EditColumn UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit">
                </EditColumn>
                <FormTableButtonRowStyle HorizontalAlign="Left" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
            </EditFormSettings>
            <ExpandCollapseColumn ButtonType="ImageButton" Visible="False" UniqueName="ExpandColumn">
                <HeaderStyle Width="19px"></HeaderStyle>
            </ExpandCollapseColumn>                             
                        </MasterTableView>
                    </telerik:RadGrid>
                </NestedViewTemplate>
                <Columns>
                    <telerik:GridBoundColumn SortExpression="Type" HeaderText="Type" HeaderButtonType="TextButton"
                        DataField="Type" UniqueName="Type"><HeaderStyle Width="550" /></telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn>
                                    <ItemTemplate>
                                        <asp:Button id="btnAdd" Runat="server" Text="Add" CssClass="flatbutton" CommandName="Add"></asp:Button>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>                                       
                </Columns>
            </MasterTableView>
        </telerik:RadGrid
</asp:Content>
  
     


codebehind:

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
using System.Drawing;
  
namespace ssl128cert
{
    public partial class domaindns : System.Web.UI.Page
    {
        DataTable dtInside;
        //RadGrid RadGrid2;
  
        protected void Page_Load(object sender, EventArgs e)
        {
            bool bSuccess = true;
            string strRedirect = "SignIn.aspx";
            string strRedirectAfterSignIn = "domainlist.aspx";
  
            InitializeComponent();
  
            if (Common.IsActive())
            {
                if (!IsPostBack)
                {
                    DataTable dt = new DataTable();
  
                    dt = QueryHandler.GetDataTable("select distinct Type as Type from [domain_dns]", CommandType.Text);
                    if (dt.Rows.Count > 0)
                    {
                        populatepage(dt);
                    }
                    else
                    {
                        bSuccess = false;
                    }
                }
            }
            else
                bSuccess = false;
  
            if (!bSuccess)
            {
                Session["PageAfterSignIn"] = strRedirectAfterSignIn;
                Response.Redirect(strRedirect);
            }
        }
  
        private void populatepage(DataTable dt)
        {
  
        }
  
        protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            DataTable dt = QueryHandler.GetDataTable("select distinct Type as Type from [domain_dns]", CommandType.Text);
            DataView viewPages = dt.DefaultView;
            viewPages.Sort = Convert.ToString(ViewState["vs_SortOrderBy"]);
            this.RadGrid1.DataSource = viewPages;
            RadGrid1.MasterTableView.DataKeyNames = new string[] { "Type" };
            //RadGrid1.DataBind();
            RadGrid1.SelectedIndexes.Clear();
            ViewState["vs_dtPages"] = dt;
        }
  
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }
  
        private void InitializeComponent()
        {
            this.RadGrid1.ItemCommand += new Telerik.Web.UI.GridCommandEventHandler(this.RadGrid1_ItemCommand);
            this.RadGrid1.PageIndexChanged += new Telerik.Web.UI.GridPageChangedEventHandler(this.RadGrid1_PageIndexChanged);
            this.RadGrid1.SortCommand += new Telerik.Web.UI.GridSortCommandEventHandler(this.RadGrid1_SortCommand);
            //this.RadGrid2.ItemCommand += new Telerik.Web.UI.GridCommandEventHandler(this.RadGrid2_ItemCommand);
        }
  
        //private void RadGrid2_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        //{
        //    if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Item || e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem)
        //    {
        //        Button btnAdd = (Button)e.Item.FindControl("btnAdd");
  
        //        //btnAdd.CommandArgument = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Domain"));
        //        btnAdd.CommandName = "Add";
        //    }
        //}
  
        private void bindData()
        {
            DataTable dt = new DataTable();
            ArrayList names = new ArrayList();
            ArrayList values = new ArrayList();
            ArrayList types = new ArrayList();
  
            dt = QueryHandler.GetDataTable("select distinct Type as Type from [domain_dns]", CommandType.Text);
  
            DataView viewPages = dt.DefaultView;
            viewPages.Sort = Convert.ToString(ViewState["vs_SortOrderBy"]);
            this.RadGrid1.DataSource = viewPages;
            RadGrid1.MasterTableView.DataKeyNames = new string[] { "Type" };
            RadGrid1.DataBind();
            RadGrid1.SelectedIndexes.Clear();
            //ViewState["vs_IndexSelected"]=-1;
            ViewState["vs_dtPages"] = dt;
        }
  
        protected void RadGrid1_PreRender(object sender, EventArgs e)
        {
            //if (!Page.IsPostBack)
            //{
            //    RadGrid1.MasterTableView.Items[0].Expanded = true;
            //    RadGrid1.MasterTableView.Items[0].ChildItem.FindControl("InnerContainer").Visible = true;
            //}
        }
  
        protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.ExpandCollapseCommandName)
            {
                ((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2").Visible =
                    !e.Item.Expanded;
  
                //GridEditableItem gridItem = e.Item as GridEditableItem;
                //dtInside = QueryHandler.GetDataTable("select * from [domain_dns] where Type = '" + gridItem["Type"].Text + "'", CommandType.Text);
                //RadGrid2 = (((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2") as RadGrid);
                ////(((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2") as RadGrid).Rebind();
                //RadGrid2.DataSource = dtInside;
                //RadGrid2.DataBind();
                //((((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2")) as RadGrid).MasterTableView.DataSource = dt;
                //((((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2")) as RadGrid).MasterTableView.DataBind();
                //((((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2")) as RadGrid).DataSource = dt;
                //((((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2")) as RadGrid).DataBind();
            }
            if (e.CommandName == "Add")
            {
                GridEditableItem editItem = e.Item as GridEditableItem;
                lblHoldType.Text = editItem["Type"].Text;
                lblHoldAddEdit.Text = "Add";
            }
        }
  
        protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            //GridItem gridItem = e.Item as GridItem;
            //dtInside = QueryHandler.GetDataTable("select * from [domain_dns] where Type = '" + ((GridEditableItem)gridItem)["Type"].Text + "'", CommandType.Text);
  
            //if (e.Item is GridNestedViewItem)
            //{
            //    (e.Item.FindControl("RadGrid2") as RadGrid).MasterTableView.DataSource = dt;
            //    (e.Item.FindControl("RadGrid2") as RadGrid).MasterTableView.DataBind();
            //    (e.Item.FindControl("RadGrid2") as RadGrid).DataSource = dt;
            //    (e.Item.FindControl("RadGrid2") as RadGrid).DataBind();
            //}
  
            if (e.Item is GridNestedViewItem)
            {
                //RadGrid2 = (e.Item.FindControl("RadGrid2") as RadGrid);
                //(e.Item.FindControl("RadGrid2") as RadGrid).NeedDataSource += new GridNeedDataSourceEventHandler(this.RadGrid2_NeedDataSource);
                (e.Item.FindControl("RadGrid2") as RadGrid).ItemCommand += new GridCommandEventHandler(this.RadGrid2_ItemCommand);
                (e.Item.FindControl("RadGrid2") as RadGrid).NeedDataSource += new GridNeedDataSourceEventHandler(this.RadGrid2_NeedDataSource);
                (e.Item.FindControl("RadGrid2") as RadGrid).ItemUpdated += new GridUpdatedEventHandler(this.RadGrid2_ItemUpdated);
                (e.Item.FindControl("RadGrid2") as RadGrid).UpdateCommand += new GridCommandEventHandler(this.RadGrid2_UpdateCommand);
                (e.Item.FindControl("RadGrid2") as RadGrid).Rebind();
                //RadGrid2.Rebind();
            }
        }
  
        protected void RadGrid2_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            try
            {
                GridNestedViewItem nestedItem = (GridNestedViewItem)((source as RadGrid).NamingContainer);
                object dataKeyValue = nestedItem.ParentItem.GetDataKeyValue("Type");
                DataTable dtInside = QueryHandler.GetDataTable("select * from [domain_dns] where Type = '" + dataKeyValue.ToString() + "'", CommandType.Text);
                (source as RadGrid).DataSource = dtInside;
            }
            catch (Exception ex)
            {
            }
        }
  
        protected void RadGrid2_UpdateCommand(object source, GridCommandEventArgs e)
        {
            try
            {
                DisplayMessage(false, "Domain " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Domain"] + " updated");
            }
            catch
            {
            }
        }
  
        protected void RadGrid2_ItemUpdated(object source, GridUpdatedEventArgs e)
        {
            if (e.Exception != null)
            {
                e.KeepInEditMode = true;
                e.ExceptionHandled = true;
                //DisplayMessage(true, "Employee " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["EmployeeID"] + " cannot be updated. Reason: " + e.Exception.Message);
            }
            else
            {
                DisplayMessage(false, "Domain " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Domain"] + " updated");
            }
        }
  
        private void DisplayMessage(bool isError, string text)
        {
            this.label1.Font.Bold = true;
            this.label1.Visible = true;
            if (isError)
            {
                this.label1.ForeColor = Color.Red;
            }
            else
            {
                this.label1.ForeColor = Color.Green;
            }
  
            this.label1.Text = text;
        }
  
  
        protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e)
        {
            GridEditableItem editItem = e.Item as GridEditableItem;
            if (e.CommandName == "Edit")
            {
                //AjaxSetting setOne = new AjaxSetting();
                //setOne.AjaxControlID = "RadGrid2";
                //AjaxUpdatedControl updOne = new AjaxUpdatedControl();
                //updOne.ControlID = "RadGrid2";
                //updOne.LoadingPanelID = "RadAjaxLoadingPanel2";
                //AjaxUpdatedControl updTwo = new AjaxUpdatedControl();
                //updTwo.ControlID = "pnlAddEdit";
                //setOne.UpdatedControls.Add(updOne);
                //setOne.UpdatedControls.Add(updTwo);
                //RadAjaxManager1.AjaxSettings.Add(setOne);
  
                //RadAjaxManager1.Controls.Add(((((GridDataItem)e.Item).ChildItem.FindControl("RadGrid2")) as RadGrid));
  
                //tbDomain.Text = editItem["Domain"].Text;
                //tbData.Text = editItem["Data"].Text;
                lblHoldAddEdit.Text = "Edit";
            }
            if (e.CommandName == "Delete")
            {
                string[] names = new string[1];
                ArrayList values = new ArrayList();
                SqlDbType[] types = new SqlDbType[1];
  
                names[0] = "@Domain";
                values.Add(editItem["Domain"].Text);
                types[0] = SqlDbType.NVarChar;
  
                //int iRes = QueryHandler.ExecuteSQL("delete from email_map where EmailMapId=" + iID, CommandType.Text);
                int iRes = QueryHandler.ExecuteSQL("secure128_dt_delDomainDns", ref names, ref values, ref types);
            }
        }
  
        private void RadGrid1_SortCommand(object source, Telerik.Web.UI.GridSortCommandEventArgs e)
        {
            if (e.SortExpression.ToString() == Convert.ToString(ViewState["vs_SortField"]))
            {
                if (Convert.ToString(ViewState["vs_SortOrder"]) == "ASC")
                {
                    ViewState["vs_SortOrderBy"] = e.SortExpression.ToString() + " DESC";
                    ViewState["vs_SortOrder"] = "DESC";
                }
                else
                {
                    ViewState["vs_SortOrderBy"] = e.SortExpression.ToString() + " ASC";
                    ViewState["vs_SortOrder"] = "ASC";
                }
            }
            else
            {
                ViewState["vs_SortOrderBy"] = e.SortExpression.ToString() + " ASC";
                ViewState["vs_SortOrder"] = "ASC";
            }
            ViewState["vs_SortField"] = e.SortExpression.ToString();
            this.bindData();
        }
  
        private void RadGrid1_PageIndexChanged(object source, Telerik.Web.UI.GridPageChangedEventArgs e)
        {
            RadGrid1.CurrentPageIndex = e.NewPageIndex;
            RadGrid1.SelectedIndexes.Clear();
            RadGrid1.DataSource = (DataTable)ViewState["vs_dtPages"];
            bindData();
        }
  
        protected void btnCancel_Click(object sender, EventArgs e)
        {
  
        }
  
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string[] names = new string[3];
                ArrayList values = new ArrayList();
                SqlDbType[] types = new SqlDbType[3];
  
                names[0] = "@Domain";
                names[1] = "@Type";
                names[2] = "@Data";
  
                types[0] = SqlDbType.NVarChar;
                types[1] = SqlDbType.NVarChar;
                types[2] = SqlDbType.NVarChar;
  
                //values.Add(tbDomain.Text);
                values.Add(lblHoldType.Text);
                //values.Add(tbData.Text);
  
                if (lblHoldAddEdit.Text == "Add")
                {
                    QueryHandler.ExecuteSQL("secure128_dt_addDomainDns", ref names, ref values, ref types);
                }
                if (lblHoldAddEdit.Text == "Edit")
                {
                    QueryHandler.ExecuteSQL("secure128_dt_updDomainDns", ref names, ref values, ref types);
                }
                //lblMsg.Text = "Update Successful";
            }
            catch (Exception ex)
            {
                string strMsg = ex.ToString();
            }
  
        }
  
        protected void RadGrid1_ItemInserted(object source, GridInsertedEventArgs e)
        {
            //GridEditableItem editItem = e.Item as GridEditableItem;
  
            //DataTable dt = QueryHandler.GetDataTable("select * from [domain_dns] where Type = '" + ((GridEditableItem)editItem)["Type"].Text + "'", CommandType.Text);
        }
  
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            //GridEditableItem editItem = e.Item as GridEditableItem;
  
            //DataTable dt = QueryHandler.GetDataTable("select * from [domain_dns] where Type = '" + ((GridEditableItem)editItem)["Type"].Text + "'", CommandType.Text);
        }
  
        //protected DataTable
  
        //protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        //{
        //    if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Item || e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem)
        //    {
        //        Button btnDelete = (Button)e.Item.FindControl("btnDelete");
        //        Button btnEdit = (Button)e.Item.FindControl("btnEdit");
  
        //        btnDelete.CommandArgument = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Domain"));
        //        btnDelete.CommandName = "Delete";
  
        //        btnEdit.CommandArgument = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Domain"));
        //        btnEdit.CommandName = "Edit";
  
        //    }
        //}
    }
}
0
Tsvetoslav
Telerik team
answered on 30 Jul 2010, 11:14 AM
Hi Brett,

I could not notice any reason for the described issue in your code - at least the troublesome code spots are commented out. Please, open up a formal support ticket and send a runnable sample of your implementation. I'll debug it and get back to you with the result. Thanks in advance.

All the best,
Tsvetoslav
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
Brett Sturgis
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Brett Sturgis
Top achievements
Rank 1
Share this question
or