GDPR_erased
Top achievements
Rank 1
GDPR_erased
asked on 30 Nov 2009, 01:43 AM
I have a checkbox column that is bound to a datasource, everything works fine on edit, but if I "insert" a new record, I want the checkbox to defualt as checked = true. Is there a way to do this?
If I create a template column, I have to bind the checkbox control in the edit item template and the item template part, but on insert, I want it to default it to checked, I guess unbound?. Is there a way?
Thanks
If I create a template column, I have to bind the checkbox control in the edit item template and the item template part, but on insert, I want it to default it to checked, I guess unbound?. Is there a way?
Thanks
8 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 30 Nov 2009, 04:59 AM
Hello Bill,
You can set a default value for the checkboxcolumn on InitInsertCommand as shown in the example below:
aspx:
c#:
Thanks
Princy.
You can set a default value for the checkboxcolumn on InitInsertCommand as shown in the example below:
aspx:
<telerik:GridCheckBoxColumn UniqueName="CheckBoxColumn" DataField="Condition"> |
</telerik:GridCheckBoxColumn> |
c#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) |
{ |
if (e.CommandName == RadGrid.InitInsertCommandName) |
{ |
//Add new" button clicked |
e.Canceled = true; |
//Prepare an IDictionary with the predefined values |
System.Collections.Specialized.ListDictionary newValues = new |
System.Collections.Specialized.ListDictionary(); |
newValues["Condition"] = "True"; |
//Insert the item and rebind |
e.Item.OwnerTableView.InsertItem(newValues); |
} |
} |
Thanks
Princy.
0
Kevin
Top achievements
Rank 1
answered on 21 Mar 2013, 03:53 PM
I have a Checkbox in a GridView and I'd like for all the checkboxes to be checked when I bind the datasource (including the ItemTemplate).
how do I do that?
how do I do that?
0
Princy
Top achievements
Rank 2
answered on 22 Mar 2013, 03:39 AM
Hi Kevin,
I guess you want to check all the CheckBox in the Template column to be checked. Please take a look into the following code snippet I tried to check the CheckBox in the Template column on ItemDataBound event.
ASPX:
C#:
Thanks,
Princy.
I guess you want to check all the CheckBox in the Template column to be checked. Please take a look into the following code snippet I tried to check the CheckBox in the Template column on ItemDataBound event.
ASPX:
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:CheckBox
ID
=
"CheckBox1"
runat
=
"server"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem DataItem = (GridDataItem)e.Item;
CheckBox Check = (CheckBox)DataItem.FindControl(
"CheckBox1"
);
//accessing the checkbox
Check.Checked =
true
;
}
}
Thanks,
Princy.
0
Kevin
Top achievements
Rank 1
answered on 22 Mar 2013, 12:16 PM
Hi Princy,
Thanks for the response. Yes, that is good.
The only thing is, I want it to happen only once, when the Grid is INITIALLY loaded – not when it reloads, for instance, when the user hits next page on the grid.
Thanks for the response. Yes, that is good.
The only thing is, I want it to happen only once, when the Grid is INITIALLY loaded – not when it reloads, for instance, when the user hits next page on the grid.
0
Princy
Top achievements
Rank 2
answered on 27 Mar 2013, 04:05 AM
Hi,
Please try the following code snippet.
C#:
Thanks,
Princy.
Please try the following code snippet.
C#:
protected
void
RadGrid1_PreRender(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
foreach
(GridDataItem item
in
RadGrid1.MasterTableView.Items)
{
CheckBox Check = (CheckBox)item.FindControl(
"CheckBox1"
);
Check.Checked =
true
;
}
}
}
Thanks,
Princy.
0
Kevin
Top achievements
Rank 1
answered on 27 Mar 2013, 05:48 PM
Yes that is good... However, that only does the first page in the grid -- what about the other pages?
I don't see how this references the other pages... when I limit my grid to 5 rows and there are other pages in the grid, I don't see ANY object in the RADGrid that allows me to reference All The Rows.
even when I use the Telerik built in type: GridClientSelectColumn which is supposed to have all this funcitonality built in (as opposed to using GridTemplateColumn), it still behaves the same way... I think this is a Bug cause as I said, I don't see ANY object in the Grid control that gives me access to ALL the rows contained in the grid for the datasrouce -- however many pages there may be.
but thanks for the feedback, we're getting closer... :)
I don't see how this references the other pages... when I limit my grid to 5 rows and there are other pages in the grid, I don't see ANY object in the RADGrid that allows me to reference All The Rows.
even when I use the Telerik built in type: GridClientSelectColumn which is supposed to have all this funcitonality built in (as opposed to using GridTemplateColumn), it still behaves the same way... I think this is a Bug cause as I said, I don't see ANY object in the Grid control that gives me access to ALL the rows contained in the grid for the datasrouce -- however many pages there may be.
but thanks for the feedback, we're getting closer... :)
0
Hi Kevin,
I am afraid you can traverse only the items that exist on the current page - there is no direct way to get the rest of the items. Simply because just the visible rows are loaded from the datasource at that exact moment. You will need to Rebind your grid in order to achieve the requested functionality:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/647760-get-selected-items-through-all-pages.aspx
Additionally, keep in mind that in master/content page scenario, the ClientIDs of the controls get modified. Therefore, you will need to slightly modify the javascript:
Also, when using script functions with ajaxified controls, it is recommended to wrap the scripts in RadScriptBlock.
Hope this helps.
Greetings,
Eyup
the Telerik team
I am afraid you can traverse only the items that exist on the current page - there is no direct way to get the rest of the items. Simply because just the visible rows are loaded from the datasource at that exact moment. You will need to Rebind your grid in order to achieve the requested functionality:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/647760-get-selected-items-through-all-pages.aspx
Additionally, keep in mind that in master/content page scenario, the ClientIDs of the controls get modified. Therefore, you will need to slightly modify the javascript:
Copy Code
function
saveSelected() {
$get(
"<%=HiddenField1.ClientID%>"
).value = Object.keys(selected).join();
}
Also, when using script functions with ajaxified controls, it is recommended to wrap the scripts in RadScriptBlock.
Hope this helps.
Greetings,
Eyup
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.
1
SMc
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 27 Jun 2022, 02:48 PM
I know this is an older thread, but it was the first one to show up when I Googled this question.
With the build 2021.1.119.45 what works is a setting in the aspx code: DefaultInsertValue="True"
<telerik:GridCheckBoxColumn DataField="dataFieldName" DataType="System.Boolean" FilterControlAltText="Filter dataFieldName column" HeaderText="Active" SortExpression="dataFieldName" UniqueName="dataFieldName" DefaultInsertValue="true">
</telerik:GridCheckBoxColumn>