Hello all,
I have a scenario that I'm hoping will be relatively painless for those who are better versed in radgrid than I am. I have a grid which I'm using to record component replacement serial numbers but in this scenario it is up to the user to determine if the component will be replaced or not meaning some of the serial numbers change while others do not. I would like the grid to come up with the old serial numbers (as shown in the attached picture) and empty fields for all of the new serial # column (the last column). If the user determines that a part is being kept then they'll click the "keeping" checkbox which will copy the old serial to the new serial field and disable the new serial field so it cannot be edited. When they're all done they'll click a submit button which will then submit the data to be saved. My problem is that I have no idea how to get just the last column with text entry fields that are editable as soon as the grid loads. The same goes for the checkboxes. I followed the article about putting all items in edit mode during pre-render but it only seems to work on the last row, not all of the rows. I'm at a loss. Any help guiding me in the right direction would be very much appreciated!
FYI - this site is currently using RadControls 2010 Q3 but we're considering upgrading it to 2012 Q2. It's more of a cost/benefit question right now but if it'll help make this process any easier then the upgrade to 2012 Q2 will definitely be approved.
Regards,
Tim
I have a scenario that I'm hoping will be relatively painless for those who are better versed in radgrid than I am. I have a grid which I'm using to record component replacement serial numbers but in this scenario it is up to the user to determine if the component will be replaced or not meaning some of the serial numbers change while others do not. I would like the grid to come up with the old serial numbers (as shown in the attached picture) and empty fields for all of the new serial # column (the last column). If the user determines that a part is being kept then they'll click the "keeping" checkbox which will copy the old serial to the new serial field and disable the new serial field so it cannot be edited. When they're all done they'll click a submit button which will then submit the data to be saved. My problem is that I have no idea how to get just the last column with text entry fields that are editable as soon as the grid loads. The same goes for the checkboxes. I followed the article about putting all items in edit mode during pre-render but it only seems to work on the last row, not all of the rows. I'm at a loss. Any help guiding me in the right direction would be very much appreciated!
FYI - this site is currently using RadControls 2010 Q3 but we're considering upgrading it to 2012 Q2. It's more of a cost/benefit question right now but if it'll help make this process any easier then the upgrade to 2012 Q2 will definitely be approved.
Regards,
Tim
11 Answers, 1 is accepted
0
Tim
Top achievements
Rank 1
answered on 26 Jul 2012, 10:33 PM
Does anyone have any ideas on this?
0
Hi Tim,
You can use the PreRender approach for putting items in edit mode from this topic:
http://www.telerik.com/help/aspnet-ajax/grid-put-all-items-in-edit-mode-no-additional-rebind.html
To get all items in edit mode, make sure you have set RadGrid.AllowMultiRowEdit to true.
You can use a GridTemplateColumn to declare an unbound checkbox. You can make it AutoPostBack="true" and in its CheckedChanged event populate the textbox with the serial number and then disable it.
Let me know if you need sample code snippets and for which part of the approach exactly.
Greetings,
Tsvetina
the Telerik team
You can use the PreRender approach for putting items in edit mode from this topic:
http://www.telerik.com/help/aspnet-ajax/grid-put-all-items-in-edit-mode-no-additional-rebind.html
To get all items in edit mode, make sure you have set RadGrid.AllowMultiRowEdit to true.
You can use a GridTemplateColumn to declare an unbound checkbox. You can make it AutoPostBack="true" and in its CheckedChanged event populate the textbox with the serial number and then disable it.
Let me know if you need sample code snippets and for which part of the approach exactly.
Greetings,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Tim
Top achievements
Rank 1
answered on 02 Aug 2012, 10:38 AM
Thank you very much for the help Tsvetina!
I understand what you're recommending and I've got it setup except for one part. In the CheckChanged sub how do I access the bound fields in the grid in the same row? Or do I change those from bound to template columns too? There is one event that fires for all of the CheckChanged events but it's only passing in two arguments as shown here:
I'm not sure how to access the other bound data columns in that particular row based on what's being passed in. Do you have any ideas on to handle this?
Thanks again,
Tim
I understand what you're recommending and I've got it setup except for one part. In the CheckChanged sub how do I access the bound fields in the grid in the same row? Or do I change those from bound to template columns too? There is one event that fires for all of the CheckChanged events but it's only passing in two arguments as shown here:
Protected
Sub
chkKeep_CheckChanged(sender
As
Object
, e
As
System.EventArgs)
'Copying data over
End
Sub
I'm not sure how to access the other bound data columns in that particular row based on what's being passed in. Do you have any ideas on to handle this?
Thanks again,
Tim
0
Shinu
Top achievements
Rank 2
answered on 02 Aug 2012, 11:26 AM
Hi Tim,
Try the following code to access column values in CheckChanged event.
VB:
Thanks,
Shinu.
Try the following code to access column values in CheckChanged event.
VB:
Protected
Sub
CheckBox1_CheckedChanged(sender
As
Object
, e
As
EventArgs)
Dim
chk
As
CheckBox =
DirectCast
(sender, CheckBox)
Dim
item
As
GridDataItem =
DirectCast
(chk.NamingContainer, GridDataItem)
Dim
value
As
String
= item(
"UniqueName"
).Text
End
Sub
Thanks,
Shinu.
0
Tim
Top achievements
Rank 1
answered on 03 Aug 2012, 09:41 AM
Hi Shinu,
Thank you for your reply. When trying out your code sample I end up getting an empty space returned for the "value" variable. Technically I get " " as a return on all of the columns. I'm thinking because the entire grid is in edit mode so technically there is no text, right?
Thank you!
Tim
Thank you for your reply. When trying out your code sample I end up getting an empty space returned for the "value" variable. Technically I get " " as a return on all of the columns. I'm thinking because the entire grid is in edit mode so technically there is no text, right?
Thank you!
Tim
0
Accepted
Shinu
Top achievements
Rank 2
answered on 03 Aug 2012, 10:50 AM
Hello Tim,
I apologize for giving the code for accessing the column value in normal mode. Here is the sample code for accessing the column value in edit mode.
VB:
Thanks,
Shinu.
I apologize for giving the code for accessing the column value in normal mode. Here is the sample code for accessing the column value in edit mode.
VB:
Protected
Sub
CheckBox1_CheckedChanged(sender
As
Object
, e
As
EventArgs)
Dim
chk
As
CheckBox =
DirectCast
(sender, CheckBox)
Dim
item
As
GridEditableItem =
DirectCast
(chk.NamingContainer, GridEditableItem)
Dim
txt
As
TextBox =
DirectCast
(item(
"UniqueName"
).Controls(0), TextBox)
Dim
value
As
String
= txt.Text
End
Sub
Thanks,
Shinu.
0
Tim
Top achievements
Rank 1
answered on 03 Aug 2012, 11:23 AM
Thank you so much for your help Shinu! That did the trick. I wasn't having much success in getting the editable item data and I can see by your approach that I was getting closer but you helped clear up what I was missing. I think I have everything I need now.
Thanks again!
Tim
Thanks again!
Tim
0
Tim
Top achievements
Rank 1
answered on 07 Aug 2012, 08:09 AM
I do have one more question that I'm sure you would be able to answer. When putting an entire grid into edit mode using the PreRender event, is it possible to mark certain columns as not editable? So if you have four columns with the ID's col1, col2, col3, col4 and you wanted all of them to be editable except col1?
0
Shinu
Top achievements
Rank 2
answered on 07 Aug 2012, 09:42 AM
Hi,
Try setting ReadOnly property for the column.
aspx:
Thanks,
Shinu.
Try setting ReadOnly property for the column.
aspx:
<
telerik:GridBoundColumn
DataField
=
"EmployeeID"
ReadOnly
=
"true"
UniqueName
=
"EmployeeID"
HeaderText
=
"EmployeeID"
>
</
telerik:GridBoundColumn
>
Thanks,
Shinu.
0
Tim
Top achievements
Rank 1
answered on 07 Aug 2012, 09:45 AM
Hello, thank you for your suggestion but I already tried it. It was the first thing I tried but when I use the "put all items in edit mode" as described using the prerender event in the link below I still end up with all fields being editable.
http://www.telerik.com/help/aspnet-ajax/grid-put-all-items-in-edit-mode-no-additional-rebind.html
http://www.telerik.com/help/aspnet-ajax/grid-put-all-items-in-edit-mode-no-additional-rebind.html
0
Shinu
Top achievements
Rank 2
answered on 08 Aug 2012, 05:52 AM
Hi,
ReadOnly property concerns whether the column editor is visible in edit mode. This property is available for column types that allow editing. Here is the sample code that I tried which worked as expected.
aspx:
C#:
Thanks,
Shinu.
ReadOnly property concerns whether the column editor is visible in edit mode. This property is available for column types that allow editing. Here is the sample code that I tried which worked as expected.
aspx:
<
telerik:RadGrid
AllowAutomaticUpdates
=
"true"
AllowMultiRowEdit
=
"true"
ID
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"false"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
OnPreRender
=
"RadGrid1_PreRender"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"FirstName"
UniqueName
=
"FirstName"
HeaderText
=
"FirstName"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"EmployeeID"
ReadOnly
=
"true"
SortExpression
=
"EmployeeID"
UniqueName
=
"EmployeeID"
HeaderText
=
"EmployeeID"
></
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
protected
void
RadGrid1_PreRender(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
foreach
(GridItem item
in
RadGrid1.MasterTableView.Items)
{
if
(item
is
GridEditableItem)
{
GridEditableItem editableItem = item
as
GridDataItem;
editableItem.Edit =
true
;
}
}
RadGrid1.Rebind();
}
}
Thanks,
Shinu.