jialiang_liu
Top achievements
Rank 1
jialiang_liu
asked on 28 Apr 2009, 04:30 PM
I have a grid that contains the following checkbox:
<
telerik:GridCheckBoxColumn DataField="IsDisplayed" DataType="System.Boolean" HeaderText="Display" UniqueName="IsDisplayed"></telerik:GridCheckBoxColumn>
The checkbox is data binded to the database, currently I have a editing button that allow me to allow the checkbox's value, thus the database's value. However, for fast changing, is it possible, that the checkbox is not grey out on the grid, and can be changed right on the grid instead of the editing template?
Thanks!
8 Answers, 1 is accepted
0
Hello Jialiang_liu,
The easiest way would be to keep all items in edit mode:
Default edit mode for grid items on initial load
Put all items in edit mode without additional rebind
Let us know whether this approach is suitable for your scenario.
Regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
The easiest way would be to keep all items in edit mode:
Default edit mode for grid items on initial load
Put all items in edit mode without additional rebind
Let us know whether this approach is suitable for your scenario.
Regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
jialiang_liu
Top achievements
Rank 1
answered on 28 Apr 2009, 04:44 PM
I don't think the solution is suitable for me. The grid has some other data field that are harder to edit, so I have a custom edit control for it. I would like just to edit the checkbox on the fly fast. Is it possible?
Thanks!
Thanks!
0
Princy
Top achievements
Rank 2
answered on 29 Apr 2009, 07:04 AM
Hello Jialiang_liu,
You can place the checkbox in a TemplateColumn and bind it to the required DataField and update the database on the CheckChanged event of the checkbox. Check out the code below to understand better:
aspx:
c#:
Thanks
Princy.
You can place the checkbox in a TemplateColumn and bind it to the required DataField and update the database on the CheckChanged event of the checkbox. Check out the code below to understand better:
aspx:
<telerik:GridTemplateColumn DataType="System.Int16" UniqueName="Integer"> |
<ItemTemplate> |
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%#Eval("IsDisplayed")%>' AutoPostBack="True" OnCheckedChanged="CheckBox1_CheckedChanged" /> |
</ItemTemplate> |
</telerik:GridTemplateColumn> |
c#:
protected void CheckBox1_CheckedChanged(object sender, EventArgs e) |
{ |
CheckBox check = (CheckBox)sender; |
string value = check.Checked.ToString(); |
// query to update the database |
} |
Thanks
Princy.
0
jialiang_liu
Top achievements
Rank 1
answered on 29 Apr 2009, 02:55 PM
Using the code you provided, I got a specific cast is not valid error, and have tried various things without any luck. How should I solve this error?
0
Accepted
Princy
Top achievements
Rank 2
answered on 30 Apr 2009, 06:06 AM
Hello Jialiang_liu,
To bind the Checked attribute value for your checkbox instance you need to specify a Yes/No column (when using Access data source) or boolean column (using SQL data source) which does not contain null values. You may probably get this error when the Checked property of the CheckBox is being set to null (or DBNull). So try using the following code for the checkbox to avoid the error:
aspx:
Thus if the IsDisplayed field is null, the checkbox will be unchecked.
Thanks
Princy.
To bind the Checked attribute value for your checkbox instance you need to specify a Yes/No column (when using Access data source) or boolean column (using SQL data source) which does not contain null values. You may probably get this error when the Checked property of the CheckBox is being set to null (or DBNull). So try using the following code for the checkbox to avoid the error:
aspx:
<asp:CheckBox ID="CheckBox1" runat="server" |
Checked='<%# (DataBinder.Eval(Container.DataItem,"IsDisplayed") is DBNull ?false:Eval("IsDisplayed")) %>' |
AutoPostBack="True" OnCheckedChanged="CheckBox1_CheckedChanged" /> |
Thanks
Princy.
0
jialiang_liu
Top achievements
Rank 1
answered on 30 Apr 2009, 12:53 PM
Thanks! It works perfect.
0
jialiang_liu
Top achievements
Rank 1
answered on 30 Apr 2009, 01:17 PM
Another question I have is in the checkbox change event, how to get the row id of the row that is clicked? Thanks!
0
Hello Jialiang_liu,
You could try the following approach:
Regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
You could try the following approach:
protected void CheckBox1_CheckedChanged(object sender, EventArgs e) |
{ |
GridItem item = (sender as CheckBox).Parent.Parent as GridItem; |
int currentItemNumber = item.ItemIndex; |
} |
Regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.