エラーを入力して 'System.Web.UI.WebControls.Button' タイプのオブジェクトをキャストすることができません:'System.Web.UI.WebControls.DropDownList'
Unable to cast object of type 'System.Web.UI.WebControls.Button' to type 'System.Web.UI.WebControls.DropDownList'
はなぜ?
<EditFormSettings EditFormType="Template">
<FormTemplate>
<asp:Label ID="Assign_t" runat="server" Font-Bold="True" ForeColor="#3366CC">Assign</asp:Label>
<telerik:RadDropDownList ID="dd_Assign" runat="server" RenderMode="Lightweight" Skin="Bootstrap" SelectedValue='<%#Bind("Assign_to") %>'>
<Items>
<telerik:DropDownListItem runat="server" Text="No Assign" Value="0" />
<telerik:DropDownListItem runat="server" Text="name1" Value="[email protected]" />
<telerik:DropDownListItem runat="server" Text="name2" Value="[email protected]" />
</Items>
</telerik:RadDropDownList>
<asp:Button ID="btnUpdate" Text='<%# IIf((TypeOf (Container) Is GridEditFormInsertItem), "Insert", "Update") %>' OnClick = "SendMail"
runat="server" CommandName='<%# IIf((TypeOf (Container) Is GridEditFormInsertItem), "PerformInsert", "Update")%>' ></asp:Button>
<asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
CommandName="Cancel"></asp:Button>
</FormTemplate>
</EditFormSettings>
Protected Sub SendMail(ByVal sender As Object, ByVal e As EventArgs)
Dim ddlSection As DropDownList = DirectCast(sender, DropDownList)
Dim editItem As GridEditFormItem = DirectCast(ddlSection.NamingContainer, GridEditFormItem)
Dim dd_Assign As DropDownList = DirectCast(editItem.FindControl("dd_Assign"), DropDownList)
Dim strFrom As String = "[email protected]"
Dim strCC As String = dd_Assign.SelectedItem.ToString
Dim strBCC As String = "[email protected]" 'BCC
Dim strSubject As String = "Request JOB Verification Approval"
Dim strBody As String = "test"
Dim mailMessage As New System.Net.Mail.MailMessage(strFrom, strCC, strSubject, strBody)
Dim mailClient As New System.Net.Mail.SmtpClient("xx.xx.xx.xx", 25)
mailClient.Credentials = New System.Net.NetworkCredential("[email protected]", "pass")
mailClient.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
mailClient.UseDefaultCredentials = True
mailClient.Send(mailMessage)
End Sub
'sender'パラメータは、イベントを発生させたオブジェクトです。明らかに 'Button'の' Click'イベントを処理しているので、なぜ 'sender'が他のものになるのでしょうか? – jmcilhinney