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

Get the Value of Checkbox in Edit Form

10 Answers 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 11 Apr 2009, 03:22 AM
I have a radgrid with autogenerated edit form. The edit form has three controls  Accepted-Checkbox, Rejected-Checkbox, Notes-TextBox.

I need to send an email to a user if the rejected checkbox is selected.

What I am needing to do is check the value of the rejected check box when the update button is press and if it is true send the email.

Can anyone give a clue as how to get this value on RadGrid4_ItemUpdated Sub. I code in VB.

10 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 13 Apr 2009, 02:05 PM
Hi Robert,

Please, find below the code to access the checkbox control and inspect its value:

If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then   
      
    Dim item As GridEditableItem = TryCast(e.Item, GridEditableItem)   
    Dim checkBox As CheckBox = item("ColumnUniqueName").FindControl("CheckBoxID")   
      
    If checkBox.Checked Then   
      
    Else           
          
    End If   
 
End If  

I hope this helps.

Regards,
Tsvetoslav
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Robert
Top achievements
Rank 1
answered on 13 Apr 2009, 02:35 PM
Thanks, But how do I know what the checkbox ID would be it is a autogenarated edit form. I assume the Column Name is Rejected because that is the fieldname being updated. 

 

If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then

 

 

Dim item As GridEditableItem = TryCast(e.Item, GridEditableItem)

 

 

Dim checkBox As CheckBox = item("Rejected").FindControl("checkbox2")<----??????????

 

 

If checkBox.Checked Then

 

MsgBox(

" Job was Rejected")

 

 

End If

 

0
Tsvetoslav
Telerik team
answered on 13 Apr 2009, 03:25 PM
Hello Robert,

Could you, please, post your aspx for the column.

Thank you.

Kind regards,
Tsvetoslav
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Robert
Top achievements
Rank 1
answered on 13 Apr 2009, 05:17 PM

Here is the radgrid that contains the rejected checkbox the edit form is auto generated. 

 


 

 

<telerik:RadGrid

 

 

ID="RadGrid4" runat="server" AllowFilteringByColumn="True"

 

 

AllowPaging="True" AllowSorting="True" DataSourceID="SqlDataPending"

 

 

GridLines="None" Skin="Black" AllowAutomaticUpdates="True"

 

 

AutoGenerateColumns="False" AutoGenerateEditColumn="True">

 

 

 

 

 

 

<MasterTableView DataKeyNames="JobNumber"

 

 

DataSourceID="SqlDataPending" pagesize="20" CellSpacing="-1"><RowIndicatorColumn><HeaderStyle Width="20px" /></RowIndicatorColumn><ExpandCollapseColumn><HeaderStyle Width="20px" /></ExpandCollapseColumn>

 

 

 

 

 

 

 

<Columns><telerik:GridEditCommandColumn HeaderText="Edit"></telerik:GridEditCommandColumn><telerik:GridCheckBoxColumn DataField="approved" DataType="System.Boolean"

 

 

HeaderText="approved" SortExpression="approved" UniqueName="approved"

 

 

Visible="False"></telerik:GridCheckBoxColumn><telerik:GridCheckBoxColumn DataField="rejected" DataType="System.Boolean"

 

 

HeaderText="rejected" SortExpression="rejected" UniqueName="rejected"

 

 

Visible="False"></telerik:GridCheckBoxColumn><telerik:GridBoundColumn DataField="notes" HeaderText="notes"

 

 

SortExpression="notes" UniqueName="notes" Visible="False"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="JobNumber" DataType="System.Int32"

 

 

HeaderText="JobNumber" ReadOnly="True" SortExpression="JobNumber"

 

 

UniqueName="JobNumber"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="Juvenile" DataType="System.Double"

 

 

HeaderText="Juvenile" ReadOnly="True" SortExpression="Juvenile"

 

 

UniqueName="Juvenile"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="Stat" DataType="System.Int16"

 

 

HeaderText="Stat" ReadOnly="True" SortExpression="Stat" UniqueName="Stat"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="Case #" HeaderText="Case #" ReadOnly="True"

 

 

SortExpression="Case #" UniqueName="Case #"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="Dictating Officer"

 

 

HeaderText="Dictating Officer" ReadOnly="True"

 

 

SortExpression="Dictating Officer" UniqueName="Dictating Officer"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="Date Dictated" DataType="System.DateTime"

 

 

HeaderText="Date Dictated" ReadOnly="True" SortExpression="Date Dictated"

 

 

UniqueName="Date Dictated"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="Date Typed" DataType="System.DateTime"

 

 

HeaderText="Date Typed" ReadOnly="True" SortExpression="Date Typed"

 

 

UniqueName="Date Typed"></telerik:GridBoundColumn></Columns><EditFormSettings><EditColumn UniqueName="EditCommandColumn1"></EditColumn></EditFormSettings><ItemStyle

 

 

Font-Bold="False" Font-Italic="False" Font-Overline="False"

 

 

Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left"

 

 

Wrap="True" /><GroupHeaderItemStyle Font-Bold="False" Font-Italic="False"

 

 

Font-Overline="False" Font-Strikeout="False" Font-Underline="False"

 

 

HorizontalAlign="Left" Wrap="True" /><AlternatingItemStyle

 

 

Font-Bold="False" Font-Italic="False" Font-Overline="False"

 

 

Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left"

 

 

Wrap="True" />

 

 

 

 

 

 

<PagerStyle Position="TopAndBottom" />

 

 

 

 

 

 

<HeaderStyle Font-Bold="False" Font-Italic="False"

 

 

Font-Overline="False" Font-Strikeout="False" Font-Underline="False"

 

 

HorizontalAlign="Left" Wrap="True" /></MasterTableView><ClientSettings><Selecting AllowRowSelect="True" /></ClientSettings><FilterMenu EnableTheming="True"><CollapseAnimation Duration="200" Type="OutQuint" /></FilterMenu></telerik:RadGrid>

 

0
Tsvetoslav
Telerik team
answered on 14 Apr 2009, 02:47 PM
Hi Robert,

In this case, you should access the first control in the table cells controls collection:

If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then      
         
    ....  
      
    Dim checkBox As CheckBox = TryCast(item("rejected").Controls(0),CheckBox)         
 
    ....   
            
             
End If     
 


Best Regards,
Tsvetoslav
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
Robert
Top achievements
Rank 1
answered on 14 Apr 2009, 03:12 PM
Thanks for the quick reply but I get  " Name "item" is not declared" in the  TryCast(item("rejected").Controls(0), CheckBox) section of the code.


 

Protected Sub RadGrid4_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid4.UpdateCommand

 

 

 

If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then

 

 

 

Dim checkBox As CheckBox = TryCast(item("rejected").Controls(0), CheckBox)

 

if checkbox.checked then

//Do my stuff here
End
If
End if
End Sub

 

0
Tsvetoslav
Telerik team
answered on 15 Apr 2009, 09:01 AM
Hi Robert,

The code snippet in my last post was meant to be an addition to the one in my previous post, so you still need the declaration statement:

Dim item As GridEditableItem = TryCast(e.Item, GridEditableItem)  
before doing the cast. I hope this helps.

Best Regards,

Tsvetoslav
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
Robert
Top achievements
Rank 1
answered on 15 Apr 2009, 01:11 PM

 

Great Thanks I don't get any errors anymore however it does not seem to be seeing that the rejected checkbox was checked and it is not sending an email out. I see that we are checking to make sure that we are in editmode should I be running this at Radgrid4_updatecommand or at some other point in the update process. I have tried this also at Radgrid4_Itemupdated as well and still get the same results it just updates the record and sends no email. I have checked the email routine by removing the if statement from it and it sends the email just fine. Again thanks for all your help. Below is the entire Sub.


Protected
Sub RadGrid4_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid4.UpdateCommand

 

 

 

If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then

 

 

 

Dim item As GridEditableItem = TryCast(e.Item, GridEditableItem)

 

 

Dim checkBox As CheckBox = TryCast(item("rejected").Controls(0), CheckBox)

 

 

If checkBox.Checked Then

 

 

 

 

 

 

Dim mailman As New Chilkat.MailMan()

 

 

' Any string passed to

 

 

Dim td

 

td =

Date.Today

 

 

 

mailman.UnlockComponent(

"Anything")

 

mailman.SmtpHost =

"smtp.charter.net"

 

mailman.SmtpUsername =

"myusername"

 

mailman.SmtpPassword =

"mypassword"

 

 

Dim email As New Chilkat.Email()

 

email.Subject =

"" 'Subjecttxt

 

email.Body = ((

"Hello Todays Date is ") + td)

 

email.AddTo(

"test@test.com")

 

email.From = (

me@somewhere.com)

 

 

If (Not mailman.SendEmail(email)) Then

 

MsgBox(mailman.LastErrorXml)

 

Else

 

MsgBox(

"Mail Sent!")

 

mailman.CloseSmtpConnection()

 

End If

 

 

End If

 

 

End If

 

 

 

End Sub

 

0
Accepted
Tsvetoslav
Telerik team
answered on 16 Apr 2009, 12:44 PM
Hi Robert,

I could not reproduce this problem.

Please, take a look at the attached sample and see if you can reproduce the problem with it.

Thank you.

Best Regards,
Tsvetoslav
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
Robert
Top achievements
Rank 1
answered on 19 Apr 2009, 09:31 PM
Thank you very much for the help it works fine now apparently the Uniquename is case sensitive.
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Robert
Top achievements
Rank 1
Share this question
or