Hello All,
In my radgrid I have two edit columns, I am following the example shown here http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/form-template-update/defaultcs.aspx
each edit column is created programmatically as follows:
Edit Column one
C#
The second Edit Column:
C#
And OnEditCommand="RadGrid1_EditCommand"
C#
In the Detail.aspx I have some text boxes and an Update Button and things look good until I click on the update button.
OnClick of the update button inside Detail.aspx the button click is not fired, but the interesting thing is that the grid reloads and shows the values a default edit button in Radgrid displays. It shows the column values of the radgrid and not the values in the details.aspx.
For some reason I cannot fathom why would the grid reload and show the default edit page in the radgrid
Any help is really appreciated.
Thank you
In my radgrid I have two edit columns, I am following the example shown here http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/form-template-update/defaultcs.aspx
each edit column is created programmatically as follows:
Edit Column one
C#
GridEditCommandColumn EditColumn =
new
GridEditCommandColumn();
RadGrid1.MasterTableView.Columns.Add(EditColumn);
EditColumn.ButtonType = GridButtonColumnType.ImageButton;
EditColumn.UniqueName =
"EditCommandColumn"
;
EditColumn.HeaderText =
"SingleAction"
;
EditColumn.ColumnGroupName =
"SingleAction"
;
EditColumn.HeaderStyle.CssClass =
"RadHeader"
;
C#
GridButtonColumn DetailColumn =
new
GridButtonColumn();
RadGrid1.MasterTableView.Columns.Add(DetailColumn);
DetailColumn.CommandName =
"Edit"
;
DetailColumn.Text =
"Detail"
;
DetailColumn.ButtonType = GridButtonColumnType.ImageButton;
DetailColumn.UniqueName =
"EditCommandColumn1"
;
DetailColumn.HeaderText =
"SingleAction"
;
DetailColumn.ColumnGroupName =
"SingleAction"
;
DetailColumn.HeaderStyle.CssClass =
"RadHeader"
;
C#
protected
void
RadGrid1_EditCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
if
(((ImageButton)e.CommandSource).AlternateText ==
"Detail"
)
{
dynamic DItem = e.Item.DataItem;
Session.Add(
"PropValue"
, DItem.SisUserId);
Session.Add(
"ExistingUser"
, ExistingUsers);
Session.Add(
"UserEnrollment"
, UserEnrollment);
RadGrid1.MasterTableView.EditFormSettings.UserControlName =
"DesktopModules/MyModule/Detail.ascx"
;
RadGrid1.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl;
RadGrid1.MasterTableView.EditFormSettings.EditColumn.UniqueName =
"EditCommandColumn2"
;
}
GridEditFormItem FormItem = (e.Item
as
GridDataItem).EditFormItem
as
GridEditFormItem;
}
// }
}
OnClick of the update button inside Detail.aspx the button click is not fired, but the interesting thing is that the grid reloads and shows the values a default edit button in Radgrid displays. It shows the column values of the radgrid and not the values in the details.aspx.
For some reason I cannot fathom why would the grid reload and show the default edit page in the radgrid
Any help is really appreciated.
Thank you
11 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 19 Nov 2013, 09:13 AM
Hi,
I guess you want to add a WebUserControl editform for your detail table. Please try the following code snippet.
C#:
Thanks,
Princy
I guess you want to add a WebUserControl editform for your detail table. Please try the following code snippet.
C#:
GridTableView tableViewOrders =
new
GridTableView(grid);
tableViewOrders.DataSourceID =
"SqlDataSource2"
;
tableViewOrders.DataKeyNames =
new
string
[] {
"OrderID"
};
tableViewOrders.Name =
"Details"
;
// Adding the WebUserControl form
tableViewOrders.EditFormSettings.EditFormType = GridEditFormType.WebUserControl;
tableViewOrders.EditFormSettings.UserControlName =
"DetailsCS.ascx"
;
tableViewOrders.EditFormSettings.EditColumn.UniqueName =
"EditCommandDetail"
;
GridRelationFields relationFields =
new
GridRelationFields();
relationFields.MasterKeyField =
"DataFieldName"
;
relationFields.DetailKeyField =
"DataFieldName"
;
tableViewOrders.ParentTableRelation.Add(relationFields);
grid.MasterTableView.DetailTables.Add(tableViewOrders);
GridButtonColumn DetailColumn =
new
GridButtonColumn();
DetailColumn.CommandName =
"Edit"
;
DetailColumn.Text =
"Detail"
;
DetailColumn.ButtonType = GridButtonColumnType.ImageButton;
DetailColumn.UniqueName =
"EditCommand"
;
DetailColumn.HeaderText =
"SingleAction"
;
DetailColumn.ColumnGroupName =
"SingleAction"
;
tableViewOrders.Columns.Add(DetailColumn);
Thanks,
Princy
0
Smart
Top achievements
Rank 1
answered on 19 Nov 2013, 02:48 PM
Hi Princy,
Thank you for the reply, but let me try to explain the situation a little better. I am able to show the controls in the form and display some values in them depending on the row selected. But, when I click on the Update button (control that I added) the radgrid reloads and displays only the default controls a edit button would show and not the controls that I added in my Detail.ascx. Now does this explanation change anything in your answer?
Cheers
Thank you for the reply, but let me try to explain the situation a little better. I am able to show the controls in the form and display some values in them depending on the row selected. But, when I click on the Update button (control that I added) the radgrid reloads and displays only the default controls a edit button would show and not the controls that I added in my Detail.ascx. Now does this explanation change anything in your answer?
Cheers
0
Princy
Top achievements
Rank 2
answered on 20 Nov 2013, 06:32 AM
Hi,
I tried your code and it works fine at my end. I guess you have two buttons for edit, one button you want to open UserControlEditForm and on the other normal editform. Please try the following code snippet. If this doesn't help, provide your full code snippet and the exact steps to reproduce the issue.
C#:
Thanks,
Princy
I tried your code and it works fine at my end. I guess you have two buttons for edit, one button you want to open UserControlEditForm and on the other normal editform. Please try the following code snippet. If this doesn't help, provide your full code snippet and the exact steps to reproduce the issue.
C#:
void
grid_EditCommand(
object
sender, GridCommandEventArgs e)
{
if
(((ImageButton)e.CommandSource).AlternateText ==
"Detail"
)
{
grid.MasterTableView.EditFormSettings.UserControlName =
"DesktopModules/MyModule/Detail.ascx"
;
grid.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl;
grid.MasterTableView.EditFormSettings.EditColumn.UniqueName =
"EditCommandColumn2"
;
}
else
{
grid.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.AutoGenerated;
}
}
Thanks,
Princy
0
Smart
Top achievements
Rank 1
answered on 20 Nov 2013, 02:20 PM
Hi Princy,
Yes you are correct. And I am successful in creating a UserControlForm that open when I click on one edit button and the autogenerated form when I click on the other button. Inside the UserControlFrom I have an Update Button when clicked I want to perform some operation. The issue is that when I click on this Update button in the UserControl Form it open the autogenerated form and doesnot trigger the onclick event of the Update button. I hope I am clear. The code below is what I want to trigger on clicking the update button in the UserControlForm, but the radgrid open the autogenerated edit form and this does not make sense to me.
Thank you
Yes you are correct. And I am successful in creating a UserControlForm that open when I click on one edit button and the autogenerated form when I click on the other button. Inside the UserControlFrom I have an Update Button when clicked I want to perform some operation. The issue is that when I click on this Update button in the UserControl Form it open the autogenerated form and doesnot trigger the onclick event of the Update button. I hope I am clear. The code below is what I want to trigger on clicking the update button in the UserControlForm, but the radgrid open the autogenerated edit form and this does not make sense to me.
Thank you
protected
void
DetailUpdate_Click(
object
sender, EventArgs e)
{
var host =
new
Host();
host.Url =
"http://test.com"
;
host.AccessToken =
"1234"
;
string
SisUserId = Session[
"PropValue"
].ToString();
List<User> ExistingUser = (List<User>)Session[
"ExistingUser"
];
List<Enrollment> UserEnrollment = (List<Enrollment>)Session[
"UserEnrollment"
];
var CoursesEnrolled = UserEnrollment.FindAll(u => u.User.SisUserId == SisUserId);
var UpdateCourse =
new
UpdateCoursesAccessPoint();
foreach
(var course
in
CoursesEnrolled)
{
TextBox txt = PlaceHolder1.FindControl(
"CourseText"
)
as
TextBox;
string
value = txt.Text;
}
}
0
Princy
Top achievements
Rank 2
answered on 21 Nov 2013, 04:53 AM
Hi,
Can you move the code to ItemCommand and see if it works, also change the DetailColumn.CommandName = "EditDetail" . Please try the following code snippet.
C#:
Thanks,
Princy
Can you move the code to ItemCommand and see if it works, also change the DetailColumn.CommandName = "EditDetail" . Please try the following code snippet.
C#:
void
grid_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName ==
"EditDetail"
)
{
e.Item.Edit =
true
;
grid.MasterTableView.EditFormSettings.UserControlName =
"~/DesktopModules/MyModule/Detail.ascx"
;
grid.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl;
grid.MasterTableView.EditFormSettings.EditColumn.UniqueName =
"EditCommandColumn2"
;
grid.Rebind();
}
else
{
grid.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.AutoGenerated;
}
}
Thanks,
Princy
0
Smart
Top achievements
Rank 1
answered on 21 Nov 2013, 02:45 PM
Hi Princy,
Thank you for your time,but, unfortunately the problem persists. When I click on the Update button inside the Detail.ascx, the default edit form open up.
The relevant code is here
C# loading format of the radgrid
The aspx of the radgrid
C# for the need data source of the radgrid
C# for Radgrid Item Command
Now here is the Detail.ascx
Here is C# for the Details.cs
Please look at it and see where I am going wrong. For some reason when I click on the Update1 button in the Details.ascx it open up the default edit form.
Thank you
Thank you for your time,but, unfortunately the problem persists. When I click on the Update button inside the Detail.ascx, the default edit form open up.
The relevant code is here
C# loading format of the radgrid
protected
void
LoadFormat()
{
RadGrid1.AutoGenerateColumns =
false
;
// RadGrid1.ID = "RadGrid1";
// RadGrid1.AllowPaging = true;
RadGrid1.AllowSorting =
true
;
RadGrid1.Skin =
"WebBlue"
;
RadGrid1.AllowMultiRowSelection =
true
;
RadGrid1.EnableLinqExpressions =
false
;
RadGrid1.PageSize = 50;
RadGrid1.EnableViewState =
true
;
RadGrid1.AllowCustomPaging =
true
;
RadGrid1.AllowPaging =
true
;
GridClientSelectColumn SelectColumn =
new
GridClientSelectColumn();
SelectColumn.UniqueName =
"ClientSelectColumn"
;
SelectColumn.HeaderText =
"Select"
;
RadGrid1.MasterTableView.Columns.Add(SelectColumn);
RadGrid1.ClientSettings.Selecting.AllowRowSelect =
true
;
RadGrid1.ClientSettings.Selecting.EnableDragToSelectRows =
true
;
GridBoundColumn boundColumn;
boundColumn =
new
GridBoundColumn();
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField =
"SisUserId"
;
boundColumn.HeaderText =
"SIS ID"
;
boundColumn.ShowFilterIcon =
false
;
boundColumn =
new
GridBoundColumn();
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField =
"LoginId"
;
boundColumn.HeaderText =
"Login ID"
;
boundColumn.ShowFilterIcon =
false
;
boundColumn =
new
GridBoundColumn();
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField =
"SortableName"
;
boundColumn.HeaderText =
"Lastname,Firstname"
;
boundColumn.ShowFilterIcon =
false
;
boundColumn =
new
GridBoundColumn();
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField =
"Email"
;
boundColumn.HeaderText =
"Email"
;
boundColumn.ShowFilterIcon =
false
;
boundColumn =
new
GridBoundColumn();
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField =
"LastLogin"
;
boundColumn.HeaderText =
"Last Login"
;
boundColumn.ShowFilterIcon =
false
;
boundColumn.ReadOnly =
true
;
GridColumnGroup SectionGroup =
new
GridColumnGroup();
RadGrid1.MasterTableView.ColumnGroups.Add(SectionGroup);
SectionGroup.HeaderText =
"View Section Only"
;
SectionGroup.Name =
"View Section Only"
;
SectionGroup.HeaderStyle.Width = 1;
boundColumn =
new
GridBoundColumn();
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.ColumnGroupName =
"View Section Only"
;
boundColumn.HeaderText =
"View Section Only"
;
boundColumn.DataField =
"SectionPrivilageNo"
;
boundColumn.ShowFilterIcon =
false
;
boundColumn.HeaderStyle.CssClass =
"RadHeader"
;
boundColumn.ReadOnly =
true
;
boundColumn =
new
GridBoundColumn();
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.ColumnGroupName =
"View Section Only"
;
boundColumn.HeaderText =
"View Section Only"
;
boundColumn.DataField =
"SectionPrivilageYes"
;
boundColumn.ShowFilterIcon =
false
;
boundColumn.HeaderStyle.CssClass =
"RadHeader"
;
boundColumn.ReadOnly =
true
;
GridColumnGroup columnGroup =
new
GridColumnGroup();
RadGrid1.MasterTableView.ColumnGroups.Add(columnGroup);
columnGroup.HeaderText =
"Single Action"
;
columnGroup.Name =
"SingleAction"
;
GridEditCommandColumn EditColumn =
new
GridEditCommandColumn();
RadGrid1.MasterTableView.Columns.Add(EditColumn);
EditColumn.ButtonType = GridButtonColumnType.ImageButton;
EditColumn.UniqueName =
"EditCommandColumn"
;
EditColumn.HeaderText =
"SingleAction"
;
EditColumn.ColumnGroupName =
"SingleAction"
;
EditColumn.HeaderStyle.CssClass =
"RadHeader"
;
GridButtonColumn DetailColumn =
new
GridButtonColumn();
RadGrid1.MasterTableView.Columns.Add(DetailColumn);
DetailColumn.CommandName =
"EditDetail"
;
DetailColumn.Text =
"Detail"
;
DetailColumn.ButtonType = GridButtonColumnType.ImageButton;
DetailColumn.UniqueName =
"EditCommandColumn1"
;
//DetailColumn.ConfirmDialogType = GridConfirmDialogType.Classic;
DetailColumn.HeaderText =
"SingleAction"
;
//DetailColumn.ConfirmText = "Do you really want to delete?";
DetailColumn.ColumnGroupName =
"SingleAction"
;
DetailColumn.HeaderStyle.CssClass =
"RadHeader"
;
GridButtonColumn DeleteColumn =
new
GridButtonColumn();
RadGrid1.MasterTableView.Columns.Add(DeleteColumn);
DeleteColumn.CommandName =
"Delete"
;
DeleteColumn.ButtonType = GridButtonColumnType.ImageButton;
DeleteColumn.UniqueName =
"DeleteCommandColumn"
;
DeleteColumn.ConfirmDialogType = GridConfirmDialogType.Classic;
DeleteColumn.HeaderText =
"SingleAction"
;
DeleteColumn.ConfirmText =
"Do you really want to delete?"
;
DeleteColumn.ColumnGroupName =
"SingleAction"
;
DeleteColumn.HeaderStyle.CssClass =
"RadHeader"
;
}
<
telerik:RadGrid
runat
=
"server"
ID
=
"RadGrid1"
AllowSorting
=
"true"
skin
=
"WebBlue"
AllowMultiRowSelection
=
"true"
EnableLinqExpressions
=
"False"
PageSize
=
"50"
OnPageIndexChanged
=
"RadGrid1_PageIndexChanged"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
ShowStatusBar
=
"true"
EnableViewState
=
"true"
OnItemCommand
=
"RadGrid1_ItemCommand"
>
<
mastertableview
autogeneratecolumns
=
"false"
onneeddatasource
=
"RadGrid1_NeedDataSource"
autogeneratedeletecolumn
=
"true"
ShowFilterIcon
=
"false"
AllowMultiRowSelection
=
"true"
>
<
columns
>
</
columns
>
</
mastertableview
>
protected
void
RadGrid1_NeedDataSource(
object
sender,Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
var host =
new
Host();
host.Url =
"https://test.com"
;
host.AccessToken =
"1234"
;
string
SessionId = HttpContext.Current.Session.SessionID;
int
i = 1;
//int index = 0;
DataTable DTable =
new
DataTable();
var getaccount =
new
GetSubAccountAccessPoint();
getaccount.AccountId = 1;
UserEnrollment.Clear();
while
(i != 0)
{
var accounts = host.Execute(getaccount, 1);
foreach
(var account
in
accounts)
{
if
(account.Name ==
"Something goes here"
)
{
var ListUsers =
new
ListUsersAccessPoint();
var ListUserEnrollment =
new
ListSisUserEnollmentAccessPoint();
ListUsers.AccountId = account.Id;
ExistingUsers = host.Execute(ListUsers, index + 1);
foreach
(var UserExist
in
ExistingUsers)
{
ListUserEnrollment.SisUserId = UserExist.SisUserId;
UserEnrollment.AddRange(host.Execute(ListUserEnrollment, 1));
}
var res = CreateData(ExistingUsers, UserEnrollment);
RadGrid1.DataSource = res;
var AccountStats =
new
GetAccountStatisticsAccessPoint();
AccountStats.AccountId = account.Id;
var Stats = host.Execute(AccountStats, 1);
RadGrid1.VirtualItemCount = Stats.Students + Stats.Teachers;
}
}
i = 0;
}
}
protected
void
RadGrid1_ItemCommand(
object
source, GridCommandEventArgs e)
{
if
(e.CommandName ==
"EditDetail"
)
{
dynamic DItem = e.Item.DataItem;
Session.Add(
"PropValue"
, DItem.SisUserId);
Session.Add(
"ExistingUser"
, ExistingUsers);
Session.Add(
"UserEnrollment"
, UserEnrollment);
e.Item.Edit =
true
;
RadGrid1.MasterTableView.EditFormSettings.UserControlName =
"DesktopModules/MyModule/Detail.ascx"
;
RadGrid1.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl;
RadGrid1.MasterTableView.EditFormSettings.EditColumn.UniqueName =
"EditCommandColumn2"
;
RadGrid1.Rebind();
}
else
{
RadGrid1.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.AutoGenerated;
}
<
asp:Table
ID
=
"DetailTable"
runat
=
"server"
>
<
asp:TableHeaderRow
id
=
"Table1HeaderRow"
BackColor
=
"LightBlue"
runat
=
"server"
>
<
asp:TableHeaderCell
Scope
=
"Column"
Text
=
"Course Name"
/>
<
asp:TableHeaderCell
Scope
=
"Column"
Text
=
"Section Name"
/>
<
asp:TableHeaderCell
Scope
=
"Column"
Text
=
"Enrollment Type"
/>
<
asp:TableHeaderCell
Scope
=
"Column"
Text
=
"View Access"
/>
</
asp:TableHeaderRow
>
<
asp:TableRow
>
<
asp:TableCell
><
asp:PlaceHolder
ID
=
"PlaceHolder1"
runat
=
"server"
></
asp:PlaceHolder
></
asp:TableCell
>
<
asp:TableCell
><
asp:PlaceHolder
ID
=
"PlaceHodler2"
runat
=
"server"
></
asp:PlaceHolder
></
asp:TableCell
>
<
asp:TableCell
><
asp:PlaceHolder
ID
=
"PlaceHolder3"
runat
=
"server"
></
asp:PlaceHolder
></
asp:TableCell
>
<
asp:TableCell
VerticalAlign
=
"Middle"
HorizontalAlign
=
"Center"
><
asp:PlaceHolder
ID
=
"PlaceHolder4"
runat
=
"server"
></
asp:PlaceHolder
></
asp:TableCell
>
</
asp:TableRow
>
<
asp:TableRow
></
asp:TableRow
>
<
asp:TableRow
>
<
asp:TableCell
>
<
asp:Button
ID
=
"DetailUpdate"
runat
=
"server"
Text
=
"Update1"
CommandName
=
"Update"
/>
</
asp:TableCell
>
</
asp:TableRow
>
</
asp:Table
>
protected
void
Page_Load(
object
sender, EventArgs e)
{
var host =
new
Host();
host.Url =
"https://test.com"
;
host.AccessToken =
"12234"
;
string
SisUserId =Session[
"PropValue"
].ToString();
List<User>ExistingUser = (List<User>)Session[
"ExistingUser"
];
List<Enrollment> UserEnrollment = (List<Enrollment>)Session[
"UserEnrollment"
];
var CoursesEnrolled = UserEnrollment.FindAll(u => u.User.SisUserId == SisUserId);
var SingleCourse =
new
GetSingleCourseAccessPoint();
var SectionInfo =
new
GetSectionsAccessPoint();
foreach
(var course
in
CoursesEnrolled)
{
TextBox CourseText =
new
TextBox();
SingleCourse.Id = course.CourseId;
SingleCourse.IncludeAllCourses =
true
;
var CourseDetail = host.Execute(SingleCourse, 1);
CourseText.Text = CourseDetail.Name;
PlaceHolder1.Controls.Add(CourseText);
PlaceHolder1.Controls.Add(
new
LiteralControl(
"<br>"
));
TextBox SectionText =
new
TextBox();
SectionInfo.Id = course.CourseSectionId;
var SectionDetail = host.Execute(SectionInfo, 1);
SectionText.Text = SectionDetail.Name;
PlaceHodler2.Controls.Add(SectionText);
PlaceHodler2.Controls.Add(
new
LiteralControl(
"<br>"
));
DropDownList EnrollTypeList =
new
DropDownList();
EnrollTypeList.DataSource = Enum.GetNames(
typeof
(EnrollmentType));
EnrollTypeList.DataBind();
EnrollTypeList.SelectedValue = course.type.ToString();
PlaceHolder3.Controls.Add(EnrollTypeList);
PlaceHolder3.Controls.Add(
new
LiteralControl(
"<br>"
));
CheckBox ViewAccessBox =
new
CheckBox();
//ViewAccessBox.Text = course.LimitPrivilegesToCourseSection.ToString();
ViewAccessBox.Checked = course.LimitPrivilegesToCourseSection;
ViewAccessBox.Style.Add(
"text-align"
,
"center"
);
ViewAccessBox.Style.Add(
"vertical-align"
,
"middle"
);
PlaceHolder4.Controls.Add(ViewAccessBox);
PlaceHolder4.Controls.Add(
new
LiteralControl(
"<br>"
));
PlaceHolder4.Controls.Add(
new
LiteralControl(
"<br>"
));
PlaceHolder4.Controls.Add(
new
LiteralControl(
"<br>"
));
}
Session.Clear();
}
protected
void
DetailUpdate_Click(
object
sender, EventArgs e)
{
var host =
new
Host();
host.Url =
"https://test.com"
;
host.AccessToken =
"1234"
;
string
SisUserId = Session[
"PropValue"
].ToString();
List<User> ExistingUser = (List<User>)Session[
"ExistingUser"
];
List<Enrollment> UserEnrollment = (List<Enrollment>)Session[
"UserEnrollment"
];
var CoursesEnrolled = UserEnrollment.FindAll(u => u.User.SisUserId == SisUserId);
var UpdateCourse =
new
UpdateCoursesAccessPoint();
foreach
(var course
in
CoursesEnrolled)
{
TextBox txt = PlaceHolder1.FindControl(
"CourseText"
)
as
TextBox;
string
value = txt.Text;
}
}
}
Thank you
0
Princy
Top achievements
Rank 2
answered on 22 Nov 2013, 06:46 AM
Hi ,
Make sure that you create the radgrid completely from code behind in Page_Init() event. Then the DetailUpdate button in the UserControl page didn't have the OnClick function attached. Please make these changes and see if it helps.Other than this,i couldn't find any issue.
ASPX:
C#:
ASCX:
Thanks,
Princy
Make sure that you create the radgrid completely from code behind in Page_Init() event. Then the DetailUpdate button in the UserControl page didn't have the OnClick function attached. Please make these changes and see if it helps.Other than this,i couldn't find any issue.
ASPX:
<
asp:PlaceHolder
ID
=
"PlaceHolder1"
runat
=
"server"
></
asp:PlaceHolder
>
C#:
RadGrid RadGrid1;
protected
void
Page_Init(
object
source, System.EventArgs e)
{
RadGrid1 =
new
RadGrid();
RadGrid1.AutoGenerateColumns =
false
;
RadGrid1.NeedDataSource+=
new
GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
RadGrid1.ItemCommand +=
new
GridCommandEventHandler(RadGrid1_ItemCommand);
. . . . .
this
.PlaceHolder1.Controls.Add(RadGrid1);
}
ASCX:
<
asp:Button
ID
=
"DetailUpdate"
runat
=
"server"
Text
=
"Update1"
CommandName
=
"Update"
OnClick
=
"DetailUpdate_Click1"
/>
Thanks,
Princy
0
Smart
Top achievements
Rank 1
answered on 22 Nov 2013, 04:23 PM
Hi Princy,
Before I go ahead and make those changes, I wanted to just make sure. How would creating the RadGrid in PageInit give the UserControl form detail button OnClick functionality. Please explain, I really appreciate your time.
Thank you
Before I go ahead and make those changes, I wanted to just make sure. How would creating the RadGrid in PageInit give the UserControl form detail button OnClick functionality. Please explain, I really appreciate your time.
Thank you
0
Smart
Top achievements
Rank 1
answered on 22 Nov 2013, 08:32 PM
Hey Princy
I went ahead and did what you suggested. But, this wont work too. I click on the update button in the UserControlForm and it open the default edit form. Now it is getting annoying because of the fact that, I can't figure out what is triggering the default web form to open.
Please try to see if there is something that I am missing.
Thank you
I went ahead and did what you suggested. But, this wont work too. I click on the update button in the UserControlForm and it open the default edit form. Now it is getting annoying because of the fact that, I can't figure out what is triggering the default web form to open.
Please try to see if there is something that I am missing.
Thank you
0
Princy
Top achievements
Rank 2
answered on 25 Nov 2013, 05:07 AM
Hi ,
In your code I see that you have created the Radgrid in ASPX page and its columns are created in code behind. Its better to create the entire RadGrid from CodeBehind in the Page_Init event. Next I see that you have set properties like ShowFilterIcon="false" AllowMultiRowSelection="true" etc in the MasterTableView tag, which are not part of the MasterTableView properties. Third in you ASCX page, you haven't added the OnClick event of the "DetailUpdate" button. The code works fine at my end when these changes are made. Below is a sample code snippet that i tried, please try to compare it with your code. Put breakpoints and see if all the events are fired properly.
ASPX:
ASPX:CS:
DetailCS.ASCX:
DetailCS.ASCX.CS:
Thanks,
Princy
In your code I see that you have created the Radgrid in ASPX page and its columns are created in code behind. Its better to create the entire RadGrid from CodeBehind in the Page_Init event. Next I see that you have set properties like ShowFilterIcon="false" AllowMultiRowSelection="true" etc in the MasterTableView tag, which are not part of the MasterTableView properties. Third in you ASCX page, you haven't added the OnClick event of the "DetailUpdate" button. The code works fine at my end when these changes are made. Below is a sample code snippet that i tried, please try to compare it with your code. Put breakpoints and see if all the events are fired properly.
ASPX:
<
asp:PlaceHolder
ID
=
"PlaceHolder1"
runat
=
"server"
></
asp:PlaceHolder
>
ASPX:CS:
RadGrid grid;
protected
void
Page_Init(
object
sender, EventArgs e)
{
grid=
new
RadGrid();
grid.AutoGenerateColumns =
false
;
grid.MasterTableView.DataKeyNames =
new
string
[] {
"CustomerID"
};
grid.AllowPaging =
true
;
grid.Skin =
"Outlook"
;
grid.NeedDataSource +=
new
GridNeedDataSourceEventHandler(grid_NeedDataSource);
grid.ItemCommand +=
new
GridCommandEventHandler(grid_ItemCommand);
GridBoundColumn boundColumn1 =
new
GridBoundColumn();
grid.MasterTableView.Columns.Add(boundColumn1);
boundColumn1.DataField =
"ContactName"
;
boundColumn1.UniqueName =
"ConactName"
;
boundColumn1.HeaderText =
"ConactName"
;
GridColumnGroup columnGroup =
new
GridColumnGroup();
grid.MasterTableView.ColumnGroups.Add(columnGroup);
columnGroup.HeaderText =
"Single Action"
;
columnGroup.Name =
"SingleAction"
;
GridEditCommandColumn EditColumn =
new
GridEditCommandColumn();
grid.MasterTableView.Columns.Add(EditColumn);
EditColumn.ButtonType = GridButtonColumnType.ImageButton;
EditColumn.UniqueName =
"EditCommandColumn"
;
EditColumn.HeaderText =
"SingleAction"
;
EditColumn.ColumnGroupName =
"SingleAction"
;
EditColumn.HeaderStyle.CssClass =
"header"
;
GridButtonColumn DetailColumn =
new
GridButtonColumn();
grid.MasterTableView.Columns.Add(DetailColumn);
DetailColumn.CommandName =
"EditDetail"
;
DetailColumn.Text =
"Detail"
;
DetailColumn.ButtonType = GridButtonColumnType.ImageButton;
DetailColumn.UniqueName =
"EditCommandColumn1"
;
DetailColumn.HeaderText =
"SingleAction"
;
DetailColumn.ColumnGroupName =
"SingleAction"
;
DetailColumn.HeaderStyle.CssClass =
"header"
;
GridButtonColumn DeleteColumn =
new
GridButtonColumn();
grid.MasterTableView.Columns.Add(DeleteColumn);
DeleteColumn.CommandName =
"Delete"
;
DeleteColumn.ButtonType = GridButtonColumnType.ImageButton;
DeleteColumn.UniqueName =
"DeleteCommandColumn"
;
DeleteColumn.ConfirmDialogType = GridConfirmDialogType.Classic;
DeleteColumn.HeaderText =
"SingleAction"
;
DeleteColumn.ConfirmText =
"Do you really want to delete?"
;
DeleteColumn.ColumnGroupName =
"SingleAction"
;
DeleteColumn.HeaderStyle.CssClass =
"header"
;
PlaceHolder1.Controls.Add(grid);
}
void
grid_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
grid.DataSource = GetDataTable(
"SELECT * FROM Customers"
);
}
void
grid_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName ==
"EditDetail"
)
{
e.Item.Edit =
true
;
grid.MasterTableView.EditFormSettings.UserControlName =
"DetailsCS.ascx"
;
grid.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl;
grid.MasterTableView.EditFormSettings.EditColumn.UniqueName =
"EditCommandColumn2"
;
grid.Rebind();
}
else
{
grid.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.AutoGenerated;
}
}
DetailCS.ASCX:
<%@ Register Assembly=
"Telerik.Web.UI"
Namespace=
"Telerik.Web.UI"
TagPrefix=
"telerik"
%>
<table id=
"Table2"
cellspacing=
"2"
cellpadding=
"1"
width=
"100%"
border=
"1"
rules=
"none"
style=
"border-collapse: collapse"
>
<tr>
<td>
Contact*Name:
</td>
<td>
<asp:TextBox ID=
"TextBox7"
runat=
"server"
Text=
'<%# DataBinder.Eval( Container, "DataItem.ContactName" ) %>'
>
</asp:TextBox>
</td>
</tr>
<tr>
<td align=
"right"
colspan=
"2"
>
<asp:Button ID=
"btnUpdate"
Text=
"Update"
runat=
"server"
CommandName=
"Update"
Visible=
'<%# !(DataItem is Telerik.Web.UI.GridInsertionObject) %>'
OnClick=
"btnUpdate_Click"
></asp:Button>
<asp:Button ID=
"btnCancel"
Text=
"Cancel"
runat=
"server"
CausesValidation=
"False"
CommandName=
"Cancel"
></asp:Button>
</td>
</tr>
</table>
DetailCS.ASCX.CS:
protected
void
btnUpdate_Click(
object
sender, EventArgs e)
{
//YourCode
}
Thanks,
Princy
0
Smart
Top achievements
Rank 1
answered on 25 Nov 2013, 06:20 PM
Hi Princy,
Thank you for your time and patience through this saga. This is what I did and it things are working now.
ASPX:
The code behind remains the same.
And this is the Detail.ascx. I have to say that I deleted the OnClick while pasting the code in the post. But, I agree, it would not have worked without the Onclick
The code behind for Detail.ascx also remains the same.
Thank you for you time.
Thank you for your time and patience through this saga. This is what I did and it things are working now.
ASPX:
<
telerik:RadGrid
runat
=
"server"
ID
=
"RadGrid1"
AllowSorting
=
"true"
skin
=
"WebBlue"
AllowMultiRowSelection
=
"true"
EnableLinqExpressions
=
"False"
PageSize
=
"50"
OnPageIndexChanged
=
"RadGrid1_PageIndexChanged"
OnPreRender
=
"RadGrid1_PreRender"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
ShowStatusBar
=
"true"
EnableViewState
=
"true"
OnItemCommand
=
"RadGrid1_ItemCommand"
>
<
mastertableview
>
<
columns
>
</
columns
>
//this is what I added
<
EditFormSettings
UserControlName
=
"DesktopModules/MyModule/Detail.ascx"
EditFormType
=
"WebUserControl"
>
<
EditColumn
UniqueName
=
"EditCommandColumn1"
>
</
EditColumn
>
</
EditFormSettings
>
</
mastertableview
>
<
/
telerik:RadGrid
>
And this is the Detail.ascx. I have to say that I deleted the OnClick while pasting the code in the post. But, I agree, it would not have worked without the Onclick
<
asp:Table
ID
=
"Table2"
runat
=
"server"
>
<
asp:TableHeaderRow
id
=
"Table1HeaderRow"
BackColor
=
"LightBlue"
runat
=
"server"
>
<
asp:TableHeaderCell
Scope
=
"Column"
Text
=
"Course Name"
/>
<
asp:TableHeaderCell
Scope
=
"Column"
Text
=
"Section Name"
/>
<
asp:TableHeaderCell
Scope
=
"Column"
Text
=
"Enrollment Type"
/>
<
asp:TableHeaderCell
Scope
=
"Column"
Text
=
"View Access"
/>
</
asp:TableHeaderRow
>
<
asp:TableRow
>
<
asp:TableCell
><
asp:PlaceHolder
ID
=
"PlaceHolder1"
runat
=
"server"
></
asp:PlaceHolder
></
asp:TableCell
>
<
asp:TableCell
><
asp:PlaceHolder
ID
=
"PlaceHodler2"
runat
=
"server"
></
asp:PlaceHolder
></
asp:TableCell
>
<
asp:TableCell
><
asp:PlaceHolder
ID
=
"PlaceHolder3"
runat
=
"server"
></
asp:PlaceHolder
></
asp:TableCell
>
<
asp:TableCell
VerticalAlign
=
"Middle"
HorizontalAlign
=
"Center"
><
asp:PlaceHolder
ID
=
"PlaceHolder4"
runat
=
"server"
></
asp:PlaceHolder
></
asp:TableCell
>
</
asp:TableRow
>
<
asp:TableRow
></
asp:TableRow
>
<
asp:TableRow
>
<
asp:TableCell
>
<
asp:Button
ID
=
"DetailUpdate"
runat
=
"server"
Text
=
"Update"
CommandName
=
"Update"
OnClick
=
"DetailUpdate_Click"
/>
</
asp:TableCell
>
</
asp:TableRow
>
</
asp:Table
>
Thank you for you time.