Technical support This forum is closed.
Version 1.x > Technical support > SelectedIndexChanged -- DataGrid on User Control View modes: 
User avatar
Guest
norashlea - 4/5/2006 3:14:53 AM
   
SelectedIndexChanged -- DataGrid on User Control
Hello,

How do I get SelectedIndexChanged() to fire on a datagrid that I have on a user control that I have placed on a page created within CMSDesk?

I've created two pages within CMSDesk, with the following paths:
-- [app root]/Admin/Maintain-Lookups/Job-Networks.aspx
-- [app root]/Admin/Maintain-Lookups/Job-Networks/Edit.aspx

I have two user controls:
--JobNetworks.ascx, which has been placed on the Job-Networks page within CMSDesk. It contains a button column, with CommandName="Select", and the *.ascx.cs contains the following code for SelectedIndexChanged:

Response.Redirect("Admin/Maintain-Lookups/Job-Networks/Edit.aspx?id=" + this.dtg.SelectedItem.Cells[0].Text + "&mode=1", false);

--JobNetworkDetails.ascx, which has been placed on the Edit page within CMSDesk. It contains fields which display the selected record details.

When the Job-Networks page that was created within CMSDesk loads, all the data is displayed correctly, but if I click the Edit button for a row, the Job-Networks.aspx page loads again, with no data displayed on it.

I created a standard aspx page, zzTest.aspx, and placed the JobNetworks.ascx control on it. When I view this page, the data is displayed exactly as it is on Job-Networks.aspx that was created within CMSDesk, and if I click the Edit button for a row, the ../Job-Networks/Edit.aspx page that was created within CMSDesk loads, and displays all the data for the selected row correctly.

I've tried this with both a MS Datagrid and the BasicDataGrid, and I get the same thing with both of them.

Regards,
Sharon



User avatar
Guest
admin - 4/5/2006 2:00:08 PM
   
Re: SelectedIndexChanged -- DataGrid on User Control
Hi Sharon,

I'm not sure why this doesn't work for you, but you may want to see some of the CMS Desk pages, such as cmsdesk\Administration\Roles\RoleList.aspx and use it as a template for your own administration page.

Best Regards,

User avatar
Guest
norashlea - 4/5/2006 2:12:02 PM
   
Re: SelectedIndexChanged -- DataGrid on User Control
Thanks Petr,

I can see how you've achieved actions with a template column and javascript, and it obviously works, so will change how I've done it.

btw -- there's an error in the location of the <style> on that page (RoleList.aspx). It is located within the <body> tag rather than <head>, and so you can't get to design until you correct it.

Thanks,
Sharon.

User avatar
Guest
norashlea - 4/12/2006 12:08:25 AM
   
Re: SelectedIndexChanged -- DataGrid on User Control
Hi Petr,

I'm still having hassles with the dtg commands on a user control that is added to a page created via the CMS.

This is VS2005 (asp.net 2.0) and C#. If I create a new aspx page in VS, drop the user control that contains a datagrid onto the aspx page in VS, register the page in CMSDesk as a new template, and then create a page from the template, everything is fine.

But ...

If I create a page in CMSDesk based on an existing "blank" template that doesn't already contain the user control, and then add the user control to the editable region on the page, all the datagrid commands (OnDelete, OnSort, OnSelectedIndexChanged etc) are completely ignored. Other click events on the user control function properly (eg, a click event for a button on the user control). It is only the datagrid commands that don't seem to be accessible.

Is there something else that I have to do differently when the datagrid is on a user control?

Regards,
Sharon

User avatar
Member
Member
Martin_Kentico - 4/13/2006 9:44:13 AM
   
Re: SelectedIndexChanged -- DataGrid on User Control
Hello Sharon,

The bad thing about inserting control in Editable Regions (well, not exactly bad but sure unpleasant) is that the control is generated through macro recognition. That must be unfortunately done latest time possible and that is in most cases in the PreRender event. That causes that some of the control processing events are skipped and that's why it does not fire certain events or even does not load the data, so you need to explicitly make the data load(reload).

Here is an example of using the QueryDataGrid control that will be able to catch the Command events, it displays the Latest News just like the control from the sample Corporate Site so if you don't use the News or your data structure is different, you will need to change the data columns displayed:

Grid.ascx file content:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="grid.ascx.cs" Inherits="grid" %>
<%@ Register TagPrefix="cc1" Namespace="Kentico.CMS.CMSControls" Assembly="Kentico.CMS.CMSControls" %>
<div>
<asp:Label ID="lblCurrent" runat="server" ForeColor="red">
</asp:Label>
<cc1:QueryDataGrid id="Grid1" runat="server" QueryName="cms.news.selectlatest" AutoGenerateColumns="False" OnItemCommand="Grid_Command" CellPadding="4" ForeColor="#333333" GridLines="None" HideControlForZeroRows="False" ProcessSorting="False">
<Columns>
<asp:ButtonColumn CommandName="select" Text="Select" ></asp:ButtonColumn>
<asp:ButtonColumn CommandName="edit" Text="Edit" ></asp:ButtonColumn>
<asp:ButtonColumn CommandName="delete" Text="Delete" ></asp:ButtonColumn>
<asp:BoundColumn DataField="NewsTitle">
</asp:BoundColumn>
<asp:BoundColumn DataField="NewsSummary">
</asp:BoundColumn>
<asp:BoundColumn DataField="NewsText">
</asp:BoundColumn>
<asp:BoundColumn DataField="NewsReleaseDate">
</asp:BoundColumn>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<ItemStyle BackColor="#EFF3FB" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditItemStyle BackColor="#2461BF" />
<AlternatingItemStyle BackColor="White" />
</cc1:QueryDataGrid>
</div>


Grid.ascx.cs file content:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class grid : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if ( this.IsPostBack )
{
this.Grid1.LoadData();
}
this.Grid1.EnableViewState = true;
}

protected void Grid_Command(object sender, DataGridCommandEventArgs e)
{
this.lblCurrent.Text = ">> Command \"" + e.CommandName + "\" has been processed <<";
}

}


Hope this will help.
If you need any further help with that, please let me know.

Best Regards

User avatar
Guest
norashlea - 4/13/2006 10:51:15 PM
   
Re: SelectedIndexChanged -- DataGrid on User Control
Hi Martin,

Thanks for the detailed example, but this is, actually, almost exactly what I'm doing anyway, except I am using the standard DataGrid rather than the Kentico QueryDataGrid, and I'm binding a dataview. But I am loading the data with Page_Load().

This application has quite an extensive private area, for administration of all the client's data. I was going to create user controls for each component, register them in CMSDesk, and then add them to the pages created in CMSDesk, giving the user additional functionality of being able to add extra content to the pages if they wish. But I think that I will change this, and create them as aspx's and then register templates rather than user controls, creating the pages from each template.

But I don't want the user to see all these additional templates on the list, when they go to create a new page. It looks as though I can register all the templates, create the pages I need based on each individual template, and then delete them from the Page Templates section of Development, which prevents them from displaying on the Page Template Catalog dialog.

But is there a better way to stop the templates from displaying on the Page Template Catalog?

User avatar
Member
Member
Martin_Kentico - 4/14/2006 8:39:48 AM
   
Re: SelectedIndexChanged -- DataGrid on User Control
Hi,

I just did the same with an ASP.NET Datagrid and it works just fine, just for sure if you wanted to try, here's the code:

<asp:DataGrid ID="datGrid" runat="server" AutoGenerateColumns="False" OnItemCommand="Grid_Command" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3">
<Columns>
<asp:ButtonColumn CommandName="select" Text="Select" ></asp:ButtonColumn>
<asp:ButtonColumn CommandName="edit" Text="Edit" ></asp:ButtonColumn>
<asp:ButtonColumn CommandName="delete" Text="Delete" ></asp:ButtonColumn>
<asp:BoundColumn DataField="Title">
</asp:BoundColumn>
<asp:BoundColumn DataField="Text">
</asp:BoundColumn>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<SelectedItemStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" Mode="NumericPages" />
<ItemStyle ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:DataGrid>


protected void Page_Load(object sender, EventArgs e)
{
if ( this.IsPostBack )
{
this.Grid1.LoadData();
}
this.Grid1.EnableViewState = true;

DataTable dt = new DataTable("News");
dt.Columns.Add("Title", typeof(string));
dt.Columns.Add("Text", typeof(string));
DataRow dr = dt.NewRow();
dr["Title"] = "xxx";
dr["Text"] = "yyy";
dt.Rows.Add(dr);
this.datGrid.DataSource = dt;
this.datGrid.DataBind();
}

protected void Grid_Command(object sender, DataGridCommandEventArgs e)
{
this.lblCurrent.Text = ">> Command \"" + e.CommandName + "\" has been processed <<";
}


I guess there could be an issue with the data loading in your code, I used just the simple DataTable to get the data easily.

If your code is like:

DataView dv = new DataView();
...
Grid.DataSource = dv;

You might want to try this assignment instead:

Grid.DataSource = dv.Table;


Regarding the PageTemplates catalog:

No, I am afraid that you cannot easily make several sets of templates, for that you will probably need to edit the ~/cmsdesk/content/SelectTemplateListing.aspx page to get this extended functionality ...

Best Regards