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. Image for the cookie policy date
close icon

Dynamic adding a row to GridGroupingControl in ASP.Net

Hi. I am trying to figure out how to dynamically add a record with 3 columns, one of which is a DropDownList, to a GridGroupingControl in ASP.Net. Does a GridGroupingControl in Web support this feature? First record will be hard-coded and others thereafter will be dynamically added.

Thanks in advance.



2 Replies

CI Christopher Issac Sunder K Syncfusion Team May 24, 2011 03:33 PM UTC

Hi Santhosh,

Regret for the delay.

Your query belongs to ASP.Net Grid Team and we have forwarded your query to that team. They will update you the details further.

Appreciate your patience.

Regards,
Christo.



SN Sridhar N Syncfusion Team May 25, 2011 05:28 AM UTC

Hi Santhosh,

Thanks for your interest in Syncfusion products.

Query #1"I am trying to figure out how to dynamically add a record with 3 columns, one of which is a DropDownList"

Your requirement can be achieved by adding the record to grid in button click event using AddNewRecord dynamically. The value for the record is set using SetValue() method.DropDownList can be added as ItemTemplate in QueryCellStyleInfo. Please refer the below code snippet.

[Code behind - C#]

void GridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Web.UI.WebControls.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell || e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell)
{
if (e.TableCellIdentity.Column.MappingName == "Category")
{// ItemTemplate Creation.
DropDownList ddl = new DropDownList();
string[] controls = { "Level1", "Level2", "Level3" };
ddl.DataSource = controls;
ddl.DataBind();
ddl.SelectedValue = Convert.ToString(e.Style.CellValue);
TemplateClass temp = new TemplateClass(ddl);
e.TableCellIdentity.Column.ItemTemplate = temp;
}
}
}
//Add button click event for adding record
protected void RecordAdd(object sender, EventArgs e)
{
this.GridGroupingControl1.CurrentTable.AddNewRecord.BeginEdit();
this.GridGroupingControl1.CurrentTable.AddNewRecord.SetValue("ID", 2);
this.GridGroupingControl1.CurrentTable.AddNewRecord.SetValue("Name", "Company2");
this.GridGroupingControl1.CurrentTable.AddNewRecord.SetValue("Category", "Level2");
this.GridGroupingControl1.CurrentTable.AddNewRecord.EndEdit();
}


For your convenience, we have created sample and the same can be downloaded from the following link.

Forum44425044.zip

Please let me know if you have any other questions or concerns.

Regards,
Sridhar.N



Loader.
Live Chat Icon For mobile
Up arrow icon