We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Cascading dropdowns in Grid

Thread ID:

Created:

Updated:

Platform:

Replies:

82642 Jun 18,2009 08:35 AM UTC Jul 6,2009 05:32 AM UTC ASP.NET Web Forms (Classic) 4
loading
Tags: GridGroupingControl
Ruslan Gasanbekov
Asked On June 18, 2009 08:35 AM UTC

Hello,

I have a grid which is databount to datatable.
When user enters an edit mode some of the fileds are changing to dropdowns.

onload:

gridColumnDescriptorCollection.FindByMappingName("Title").Appearance.AnyRecordFieldCell.CellType = comboBox;
gridColumnDescriptorCollection.FindByMappingName("City").Appearance.AnyRecordFieldCell.CellType = comboBox;
gridColumnDescriptorCollection.FindByMappingName("Country").Appearance.AnyRecordFieldCell.CellType = comboBox;
gridColumnDescriptorCollection.FindByMappingName("Region").Appearance.AnyRecordFieldCell.CellType = comboBox;


Those drop downs are boung to datasources

GridGroupingControl1_QueryCellStyleInfo:

setDataSourceToEditCell(e, "Country", filterDataTable(this.Session[this.r_DataSourceEmloyeesKey] as DataTable, "Country") );
setDataSourceToEditCell(e, "City", filterDataTable(this.Session[this.r_DataSourceEmloyeesKey] as DataTable, "City") );
setDataSourceToEditCell(e, "Title", filterDataTable(this.Session[this.r_DataSourceEmloyeesKey] as DataTable, "Title") );
setDataSourceToEditCell(e, "Region", filterDataTable(this.Session[this.r_DataSourceEmloyeesKey] as DataTable, "Region"));

Now, what i would like to happen is: when user picks a region option the dropdown of cities would get updated and display only the relevant cities to the region.

So what is the best way to do this (is there a buitl in mechanism or maybe the is an event raised by the "Regions" dropdown...).

10x.





Rekha P [Syncfusion]
Replied On June 22, 2009 01:00 PM UTC

Hi Ruslan,

Thank you for your interest in Syncfusion Products.

In order to get the update the dropdown, we would suggest you to use custom Template controls where you can trigger the events to achieve this. DropDownList control can be embedded in Grid as EditItemTemplate and using this selected value, we can customize another column values. Updating the record values using custom cell types ComboBox selection is not possible, as we cannot raise postback. Please refer a code snippet below to achieve this.






AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">






Refer a simple sample from below illustrating this requirement.

http://files.syncfusion.com/support/GGC.Web/7.2.0.37/F82642/Sample.zip

Please let me know if you have any concerns.

Thanks,
Rekha

Ruslan Gasanbekov
Replied On June 25, 2009 08:58 AM UTC

10x for the answer.

I have some other questions:

1.How to access the currently selected row's child controls.
Lets say a user selected a row and entered edit mode.
A dropdown was loaded with certain values and a certain value was selected, now i would like to get to another dropdown in the same row and fill it with data.
In asp.net GridView it was something like this:

this.GridView1.Rows[this.GridView1.EditIndex].FindControl("someContorlsId")...

How to achieve same functionality with GGC ?

2.Is there a way to "tell" the grid to take the SelectedValue from a dropdown and put it in a certain cell of the underlying datasource entry and to put the SelectedText in another cell of the underlying datasource entry (kind of advanced datamapping)?
If not, then is the DataSourceRowUpdating the right place to do so, programaticaly ?

3.I need the grid to add a new row via certain rules (when creating a new row).
For example : I would like it to set newrow[col1] = new GUID() ,newrow[col2] = string.empty ,newrow[col3] = int.max...
Is there a way to achieve this kind of functionality?

4.I am having some perfomance issues during design time.
I am running win xp on core-duo(32) with 2gig ram vs 2008 sp1 3.5 .
When I edit the grid the pc freezes for some time , also happens on other workstations.
Syncfusion version is 7.2.0.20 .
Any ideas about this ?

10q very much for the help.

Ruslan Gasanbekov
Replied On June 28, 2009 07:25 AM UTC

anyone ?

Rekha P [Syncfusion]
Replied On July 6, 2009 05:32 AM UTC

Hi Ruslan,

1.How to access the currently selected row's child controls.

The embedded child controls (EditItemTemplate) can be accessed by iterating through Grid top level row. Please refer a code snippet below to achieve this using DataSourceControlRowUpdating event.

void GridGroupingControl1_DataSourceControlRowUpdating(object sender, GridDataSourceControlRowUpdateEventArgs e)
{
Label1.Text = "";

DropDownList dropdown = null;
foreach (TableRow row in this.GridGroupingControl1.TopLevelTable.Rows)
{
if (row is GridRow)
{
GridRow gridRow = row as GridRow;

if (gridRow.Record != null)
{
foreach (GridCell gridCell in gridRow.Cells)
{
if (gridCell.ColumnDescriptor.Name == "Country")
{
foreach (Control cntl in gridCell.Controls[0].Controls)
{
if (cntl is DropDownList)
{
dropdown = cntl as DropDownList;
GridCellTemplated grid = (GridCellTemplated)dropdown.Parent.Parent;
GridRow gridrow1 = grid.Row;

Label1.Text += gridrow1.Record.GetValue("EmployeeID") + "--" + gridrow1.Record.GetValue("FirstName") + "--" + dropdown.SelectedItem.Text + "
";
gridRow.Record.SetValue("Country", dropdown.SelectedItem.Text);
}
}
}
}
}
}
}
}


The steps followed here are,
- Get the TableRow in the TopLevelTable
- Check if that Row is GridRow if so Iterate the Gridcells
- Find the TemplatedControl and the value.

2.Is there a way to "tell" the grid to take the SelectedValue from a dropdown and put it in a certain cell of the underlying datasource entry and to put the SelectedText in another cell of the underlying datasource entry.

This can achieved through DataSourceControlRowUpdating event by getting New values of items that ready to be updated. The custom controls value can be accessed using the above code snippet.

3.I need the grid to add a new row via certain rules

The AddNewRecords can be monitored using DataSourceControlRowAdding where you can access the currenly inserting records and customizing it.

void GridGroupingControl1_DataSourceControlRowAdding(object sender, GridDataSourceControlRowAddingEventArgs e)
{
//e.NewValues[0]
//you can access the newly inserted records through e.NewValues[0] with the corresponding index numbers.
}


AddNewRecords can also be checked by its type of elements using DisplayKind as AddNewRecord.

void GridGroupingControl1_CurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e)
{
if (e.Action == CurrentRecordAction.BeginEditComplete || e.Action == CurrentRecordAction.EnterRecordComplete
&& e.Record != null
&& e.Record.Kind == DisplayElementKind.AddNewRecord)
{
//customize values for AddNewRecord
}
}


Refer a sample illustrating the above queries.
http://files.syncfusion.com/support/GGC.Web/7.2.0.20/F82642_1/Sample.zip

4.I am having some perfomance issues during design time.

We would like to suggest you to install VS2008 SP1.

http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&displaylang=en

and the Javascript intellisense patch.

http://weblogs.asp.net/scottgu/archive/2008/11/21/jquery-intellisense-in-vs-2008.aspx

We appreciate your patience and please let us know if you have any other concerns.

Thanks,
Rekha

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;