I wanted to create a function that determine the value when inserting the value to the sqldatasource. I have a checkbox in radgrid which the user will check the checkbox. If the checkbox is checked then the current date and time value will be inserted. Previously i can do it using the code as below:
Dim
checkbox1 As CheckBox = GridView1.FooterRow.FindControl("checkbox1")
If checkbox1.Checked = True Then
e.InputParameters(
"endapps0") = DateTime.Now()
End If
How can i do this in RadGrid?
Thanks
7 Answers, 1 is accepted
A possible approach is to put the CheckBox in a CommandItemTemplate.
<MasterTableView CommandItemDisplay="Bottom"> |
<CommandItemTemplate> |
<asp:CheckBox ID="CheckBox1" runat="server" /> |
</CommandItemTemplate> |
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) |
If TypeOf e.Item Is GridCommandItem Then |
Dim cb As CheckBox = TryCast(e.Item.FindControl("CheckBox1"), CheckBox) |
If cb.Checked Then |
'your code |
End If |
End If |
End Sub |
You can then save the value in session for example.
Kind regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

Correct me if i'm wrong. Do you mean that i can only do it in Command Item??? I was planning to put the checkbox in the Edit Item where the user enter all the require data which checking the checkbox will determine the datetime.now.
Another question for you is, how can i do " e.InputParameters("endapps0") = DateTime.Now() " in radgrid? When i include the line, the compiler show an error. I'm trying to mean that how do the grid find the column in that particular row to enter the data to?
Thanks, your help is much needed.
As I mentioned before using ItemDataBound is a possible approach, which doesn't mean it's the only one.
Please check whether the approach shown in the attached website is acceptable for your scenario.
Best regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

Fantastic sample that you send to me. You are one step closer in solving my problem.
I have notice that your sample work great but i still need to few modification.
1. I found out that the line
Dim
item As GridEditFormItem = TryCast(checkbox1.Parent.Parent, GridEditFormItem)Dim textbox As TextBox = TryCast(item("CategoryName").Controls(0), TextBox)
works but once i convert the column into a Template Column, the line doesn't work anymore. The error show "Object reference not set to an instance of an object"
2. I notice that you have added a checkbox to control the textbox in "CategoryName" column but what i need is to change the textbox control in "Categoryname" column into a checkbox control which checking the checkbox will enter the datetime instead of adding another control.
Hope you can solve my problems. Thanks in advance and good job!
I modified the code and reattached the archive to the ticket. Please test it and let me know whether it fits your scenario.
Kind regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

It works but there are some slight error, when I trigger insert, the data in "CategoryName" textbox won't be inserted into the database.
Thanks.
I accidentally sent you another version of the same project. Please excuse me for the inconvenience. You can find the correct version attached to the thread.
Let us know if you have more question about this matter
Regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.