Hi ,
I am making a UserControl having Nested RadGrid, Everything is made dynamically in codebehind. I am adding Edit button to ParentTable in ItemDatabound. When i expand parentrow my ParentRow Edit button binding is gone.
NeedDataSource of ParentGrid is not firing. These are my Grid Event
This is my LoadGrid Event which is fired from Page_Load()
DataSource is passed from Page to the Control through properties of UserControl. So it is not available on Page_Init for the UserControl.
Attached are the screenshots : Beforeexpand - all looks fine. But AfterExpand, the ParentTableRow is not binded. So the images for the added buttons as well as click events are gone.
Please tell me what is missing and how to get it running.
Thanks a lot.
Best Regards,
Veenu Munjal
I am making a UserControl having Nested RadGrid, Everything is made dynamically in codebehind. I am adding Edit button to ParentTable in ItemDatabound. When i expand parentrow my ParentRow Edit button binding is gone.
NeedDataSource of ParentGrid is not firing. These are my Grid Event
#region Grid Events |
protected void RadGridNestedControl_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e) |
{ |
GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem; |
string strParentRelationID = dataItem.GetDataKeyValue(this.ParentRelationColumn).ToString(); |
e.DetailTableView.DataSource = Source.Tables[1].Select(ChildRelationColumn + "=" + strParentRelationID); |
RadGrid obj = (RadGrid)source ; |
//obj.Rebind(); |
} |
protected void RadGridNestedControl_ItemDataBound(object source, Telerik.Web.UI.GridItemEventArgs e) |
{ |
if (this.PageType == (int)PageName.HeaderFooterListing) |
{ |
if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "ParentView") |
{ |
GridDataItem dataItem = e.Item as GridDataItem; |
GridTableCell wgColEdit = (GridTableCell)dataItem["Edit"]; |
if (wgColEdit != null) |
{ |
//Creating QueryString |
string[] editParam = this.NavigationEditParameters; |
string strQueryString = string.Empty; |
foreach (string str in editParam) |
{ |
if (dataItem[str] != null) |
{ |
if (dataItem[str].Text != " ") |
strQueryString += str + "=" + dataItem[str].Text + "&"; |
else |
strQueryString += str + "=" + ServiceNet.BLL.Global.NullInteger.ToString() + "&"; |
} |
} |
strQueryString += "PKSourceClientID=" + intClientID; |
wgColEdit.HorizontalAlign = HorizontalAlign.Center; |
(wgColEdit.Controls[0] as ImageButton).Style.Add("Cursor", "Pointer"); |
wgColEdit.ToolTip = ResourceLang.GetString("C_Edit"); |
string url = ((ServiceNet.Web.BasePage)Page).ImagesLocation + "btn_edit_small" + ((ServiceNet.Web.BasePage)Page).ImageExtension; |
wgColEdit.Text = "<a href='" + this.NavigationEditURL + "?" + strQueryString + "' ><img src='" + url + "' OnMouseOver=ChangeImage(this,'btn_edit_small',1) OnMouseOut=ChangeImage(this,'btn_edit_small',2) OnMouseDown=ChangeImage(this,'btn_edit_small',3) OnMouseUp=ChangeImage(this,'btn_edit_small',4) onKeyDown=ChangeImage(this,'btn_edit_small',5) OnKeyUp=ChangeImage(this,'btn_edit_small',6)></a>"; |
} |
} |
if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "ChildView") |
{ |
GridDataItem dataItem = e.Item as GridDataItem; |
GridTableCell wgColPreview = (GridTableCell)dataItem["Add"]; |
if (wgColPreview != null) |
{ |
int intPKID = Convert.ToInt32(dataItem.GetDataKeyValue(this.ChildRelationColumn).ToString()); |
int intTypeValueID = ServiceNet.BLL.Global.NullInteger; |
int intPKUserSourceID = ServiceNet.BLL.Global.NullInteger; |
int intPopUpHeight = ServiceNet.BLL.Global.NullInteger; |
int intPopUpWidth = ServiceNet.BLL.Global.NullInteger; |
string strDisplayText = dataItem["DisplayText"].Text; |
//Getting ParentRow Data |
DataRow[] drParent = Source.Tables[0].Select("PKID =" + intPKID); |
if (drParent != null && drParent.Length > 0) |
{ |
intTypeValueID = DatabaseHelper.GetNullableInt32(drParent[0], "TypeValueID"); |
intPKUserSourceID = DatabaseHelper.GetNullableInt32(drParent[0], "PKUserSourceID"); |
intPopUpHeight = DatabaseHelper.GetNullableInt32(drParent[0], "PopUpHeight"); |
intPopUpWidth = DatabaseHelper.GetNullableInt32(drParent[0], "PopUpWidth"); |
} |
wgColPreview.HorizontalAlign = HorizontalAlign.Center; |
wgColPreview.ToolTip = ResourceLang.GetString("C_Preview"); |
string url = ((ServiceNet.Web.BasePage)Page).ImagesLocation + "btn_ViewSchedules" + ((ServiceNet.Web.BasePage)Page).ImageExtension; |
wgColPreview.Text = "<a href='# style=cursor:hand;'><img onclick=\"javascript:ShowDataPopUp('" + this.ControlSessionData.LoggedUserPreferences.LanguageID + "','" + intTypeValueID + "','" + strDisplayText + "','" + intPKUserSourceID + "','" + intPopUpHeight + "','" + intPopUpWidth + "');\" src='" + url + "' OnMouseOver=ChangeImage(this,'btn_ViewSchedules',1) OnMouseOut=ChangeImage(this,'btn_ViewSchedules',2) OnMouseDown=ChangeImage(this,'btn_ViewSchedules',3) OnMouseUp=ChangeImage(this,'btn_ViewSchedules',4) onKeyDown=ChangeImage(this,'btn_ViewSchedules',5) OnKeyUp=ChangeImage(this,'btn_ViewSchedules',6)></a>"; |
} |
} |
} |
} |
protected void RadGridNestedControl_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) |
{ |
//if (!e.IsFromDetailTable) |
//{ |
// LoadData(this.Source); |
//} |
} |
#endregion |
This is my LoadGrid Event which is fired from Page_Load()
public void LoadData(DataSet dsSource) |
{ |
this.RadGridNestedControl = new RadGrid(); |
this.RadGridNestedControl.ID = "RadGrid1"; |
this.RadGridNestedControl.NeedDataSource += new GridNeedDataSourceEventHandler(this.RadGridNestedControl_NeedDataSource); |
this.RadGridNestedControl.DetailTableDataBind += new GridDetailTableDataBindEventHandler(this.RadGridNestedControl_DetailTableDataBind); |
this.RadGridNestedControl.ItemDataBound += new GridItemEventHandler(this.RadGridNestedControl_ItemDataBound); |
this.RadGridNestedControl.EnableEmbeddedScripts = true; |
this.RadGridNestedControl.Width = Unit.Percentage(100); |
thisthis.RadGridNestedControl.PageSize = this.ParentNumberofRecords; |
this.RadGridNestedControl.AllowPaging = true; |
this.RadGridNestedControl.AllowSorting = true; |
this.RadGridNestedControl.AutoGenerateColumns = false; |
if (this.Source != null) |
{ |
RadGridNestedControl.DataSource = dsSource.Tables[0]; |
RadGridNestedControl.MasterTableView.DataKeyNames = new string[] { this.ParentRelationColumn }; |
RadGridNestedControl.MasterTableView.Name = "ParentView"; |
//Creating Columns |
foreach (DataColumn dcol in dsSource.Tables[0].Columns) |
{ |
if (this.ParentExcludedFields != ServiceNet.BLL.Global.NullString) |
{ |
if (this.ParentExcludedFields.IndexOf("," + dcol.ColumnName.ToUpper() + ",") < 0) |
{ |
if (this.ResourceLangPrefix != null && this.ResourceLangPrefix != "") |
dcol.Caption = ResourceLang.GetString(this.ResourceLangPrefix + "_" + dcol.ColumnName); |
else |
dcol.Caption = ResourceLang.GetString(dcol.ColumnName); |
if (dcol.Caption == string.Empty) |
dcoldcol.Caption = dcol.ColumnName; |
GridBoundColumn wgCol = new GridBoundColumn(); |
RadGridNestedControl.MasterTableView.Columns.Add(wgCol); |
wgCol.DataField = dcol.ColumnName; |
wgCol.HeaderText = dcol.Caption; |
wgCol.UniqueName = dcol.ColumnName; |
wgCol.AllowSorting = true; |
} |
else |
{ |
GridBoundColumn wgCol = new GridBoundColumn(); |
RadGridNestedControl.MasterTableView.Columns.Add(wgCol); |
wgCol.DataField = dcol.ColumnName; |
wgCol.Display = false; |
} |
} |
else |
{ |
dcol.Caption = ResourceLang.GetString(this.ResourceLangPrefix + "_" + dcol.ColumnName); |
if (dcol.Caption == string.Empty) |
dcoldcol.Caption = dcol.ColumnName; |
GridBoundColumn wgCol = new GridBoundColumn(); |
RadGridNestedControl.MasterTableView.Columns.Add(wgCol); |
wgCol.DataField = dcol.ColumnName; |
wgCol.HeaderText = dcol.Caption; |
wgCol.UniqueName = dcol.ColumnName; |
wgCol.AllowSorting = true; |
} |
} |
//Adding Buttons to ParentGrid |
if (this.IsParentRecordEditButton) |
AddButtonColumnsToGrid("Edit", ResourceLang.GetString("C_Edit")); |
if (this.IsParentRecordAddButton) |
AddButtonColumnsToGrid("Add", ResourceLang.GetString("C_Add")); |
if (this.IsParentRecordDeleteButton) |
AddButtonColumnsToGrid("Delete", ResourceLang.GetString("C_Delete")); |
//Detail Table |
GridTableView tableDetailView = new GridTableView(RadGridNestedControl); |
tableDetailView.Width = Unit.Percentage(100); |
tableDetailView.DataSource = dsSource.Tables[1]; |
tableDetailView.DataKeyNames = new string[] { this.ChildRelationColumn }; |
tableDetailView.PageSize = this.ChildNumberofRecords; |
tableDetailView.Name = "ChildView"; |
GridRelationFields relationFields = new GridRelationFields(); |
relationFields.MasterKeyField = this.ParentRelationColumn; |
relationFields.DetailKeyField = this.ChildRelationColumn; |
tableDetailView.ParentTableRelation.Add(relationFields); |
//Creating Child Columns |
foreach (DataColumn dcol in dsSource.Tables[1].Columns) |
{ |
if (this.ChildExcludedFields != ServiceNet.BLL.Global.NullString) |
{ |
if (this.ChildExcludedFields.IndexOf("," + dcol.ColumnName.ToUpper() + ",") < 0) |
{ |
if (this.ResourceLangPrefix != null && this.ResourceLangPrefix != "") |
dcol.Caption = ResourceLang.GetString(this.ResourceLangPrefix + "_" + dcol.ColumnName); |
else |
dcol.Caption = ResourceLang.GetString(dcol.ColumnName); |
if (dcol.Caption == string.Empty) |
dcoldcol.Caption = dcol.ColumnName; |
GridBoundColumn wgCol = new GridBoundColumn(); |
wgCol.DataField = dcol.ColumnName; |
wgCol.HeaderText = dcol.Caption; |
wgCol.UniqueName = dcol.ColumnName; |
wgCol.AllowSorting = true; |
tableDetailView.Columns.Add(wgCol); |
} |
else |
{ |
GridBoundColumn wgCol = new GridBoundColumn(); |
tableDetailView.Columns.Add(wgCol); |
wgCol.DataField = dcol.ColumnName; |
wgCol.Display = false; |
} |
} |
else |
{ |
dcol.Caption = ResourceLang.GetString(this.ResourceLangPrefix + "_" + dcol.ColumnName); |
if (dcol.Caption == string.Empty) |
dcoldcol.Caption = dcol.ColumnName; |
GridBoundColumn wgCol = new GridBoundColumn(); |
wgCol.DataField = dcol.ColumnName; |
wgCol.HeaderText = dcol.Caption; |
wgCol.UniqueName = dcol.ColumnName; |
wgCol.AllowSorting = true; |
tableDetailView.Columns.Add(wgCol); |
} |
} |
//Adding Buttons to ChildGrid |
if (this.IsChildRecordAddButton) |
AddButtonColumnsToChildGrid("Add", ResourceLang.GetString("C_Add"), tableDetailView); |
if (this.IsChildRecordEditButton) |
AddButtonColumnsToChildGrid("Edit", ResourceLang.GetString("C_Edit"), tableDetailView); |
if (this.IsChildRecordDeleteButton) |
AddButtonColumnsToChildGrid("Delete", ResourceLang.GetString("C_Delete"), tableDetailView); |
RadGridNestedControl.MasterTableView.DetailTables.Add(tableDetailView); |
this.PlaceHolder1.Controls.Add(RadGridNestedControl); |
} |
} |
DataSource is passed from Page to the Control through properties of UserControl. So it is not available on Page_Init for the UserControl.
Attached are the screenshots : Beforeexpand - all looks fine. But AfterExpand, the ParentTableRow is not binded. So the images for the added buttons as well as click events are gone.
Please tell me what is missing and how to get it running.
Thanks a lot.
Best Regards,
Veenu Munjal