This is a migrated thread and some comments may be shown as answers.

RadGrid with checkbox contains input parameter

7 Answers 96 Views
Grid
This is a migrated thread and some comments may be shown as answers.
bEnDi
Top achievements
Rank 2
bEnDi asked on 07 Oct 2008, 08:00 AM
Hi,

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

Sort by
0
Daniel
Telerik team
answered on 07 Oct 2008, 11:41 AM
Hello Lendi,

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 ObjectByVal 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.
0
bEnDi
Top achievements
Rank 2
answered on 07 Oct 2008, 04:36 PM
Hi Daniel,

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.
0
Daniel
Telerik team
answered on 10 Oct 2008, 01:50 PM
Hello Lendi,

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.
0
bEnDi
Top achievements
Rank 2
answered on 12 Oct 2008, 10:29 AM
Hi Daniel,

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!

 

 

0
Daniel
Telerik team
answered on 14 Oct 2008, 05:03 PM
Hello Lendi,

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.
0
bEnDi
Top achievements
Rank 2
answered on 14 Oct 2008, 11:46 PM
Hi Daniel,
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.
0
Daniel
Telerik team
answered on 15 Oct 2008, 05:47 PM
Hello Lendi,

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.
Tags
Grid
Asked by
bEnDi
Top achievements
Rank 2
Answers by
Daniel
Telerik team
bEnDi
Top achievements
Rank 2
Share this question
or