Convert VB.NET to C#

Posted on 2011-05-11
Last Modified: 2012-06-21

Please convert following VB.NET codes to C#.

    Protected Sub odsWorksheet_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles odsWorksheet.Inserting
        ' Programmatically reference Web controls in the inserting interface...
        Dim NewWorkDate As TextBox = gvWorkSheet.FooterRow.FindControl("NewWorkDate")
        Dim NewMemberID As DropDownList = gvWorkSheet.FooterRow.FindControl("NewMemberID")
        Dim NewAccountID As DropDownList = gvWorkSheet.FooterRow.FindControl("NewAccountID")
        Dim NewIncome As TextBox = gvWorkSheet.FooterRow.FindControl("NewIncome")
        Dim NewPayment As TextBox = gvWorkSheet.FooterRow.FindControl("NewPayment")
        Dim NewNotes As TextBox = gvWorkSheet.FooterRow.FindControl("NewNotes")
        Dim NewBankDate As TextBox = gvWorkSheet.FooterRow.FindControl("NewBankDate")

        ' Set the ObjectDataSource's InsertParameters values...
        Dim WorkDate As Nullable(Of Date) = Convert.ToDateTime(lblDateFr.Text)
        If Not String.IsNullOrEmpty(NewWorkDate.Text) Then
            WorkDate = Convert.ToDateTime(NewWorkDate.Text)
        End If
        e.InputParameters("WorkDate") = WorkDate

        e.InputParameters("MemberID") = Convert.ToInt32(NewMemberID.SelectedValue)
        e.InputParameters("AccountID") = Convert.ToInt32(NewAccountID.SelectedValue)

        Dim Income As Nullable(Of Decimal) = Nothing
        If Not String.IsNullOrEmpty(NewIncome.Text) Then
            Income = Convert.ToDecimal(NewIncome.Text)
        End If
        e.InputParameters("Income") = Income
        Dim Payment As Nullable(Of Decimal) = Nothing
        If Not String.IsNullOrEmpty(NewPayment.Text) Then
            Payment = Convert.ToDecimal(NewPayment.Text)
        End If
        e.InputParameters("Payment") = Payment

        e.InputParameters("Notes") = NewNotes.Text

        Dim BankDate As Nullable(Of Date) = #1/1/2001#
        If Not String.IsNullOrEmpty(NewBankDate.Text) Then
            BankDate = Convert.ToDateTime(NewBankDate.Text)
        End If
        e.InputParameters("BankDate") = BankDate
    End Sub
Question by:Takeoutdinner
    LVL 18

    Accepted Solution

    protected void odsWorksheet_Inserting(object sender, System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs e)
    	// Programmatically reference Web controls in the inserting interface...
    	TextBox NewWorkDate = gvWorkSheet.FooterRow.FindControl("NewWorkDate");
    	DropDownList NewMemberID = gvWorkSheet.FooterRow.FindControl("NewMemberID");
    	DropDownList NewAccountID = gvWorkSheet.FooterRow.FindControl("NewAccountID");
    	TextBox NewIncome = gvWorkSheet.FooterRow.FindControl("NewIncome");
    	TextBox NewPayment = gvWorkSheet.FooterRow.FindControl("NewPayment");
    	TextBox NewNotes = gvWorkSheet.FooterRow.FindControl("NewNotes");
    	TextBox NewBankDate = gvWorkSheet.FooterRow.FindControl("NewBankDate");
    	// Set the ObjectDataSource's InsertParameters values...
    	Nullable<System.DateTime> WorkDate = Convert.ToDateTime(lblDateFr.Text);
    	if (!string.IsNullOrEmpty(NewWorkDate.Text)) {
    		WorkDate = Convert.ToDateTime(NewWorkDate.Text);
    	e.InputParameters["WorkDate"] = WorkDate;
    	e.InputParameters["MemberID"] = Convert.ToInt32(NewMemberID.SelectedValue);
    	e.InputParameters["AccountID"] = Convert.ToInt32(NewAccountID.SelectedValue);
    	Nullable<decimal> Income = null;
    	if (!string.IsNullOrEmpty(NewIncome.Text)) {
    		Income = Convert.ToDecimal(NewIncome.Text);
    	e.InputParameters["Income"] = Income;
    	Nullable<decimal> Payment = null;
    	if (!string.IsNullOrEmpty(NewPayment.Text)) {
    		Payment = Convert.ToDecimal(NewPayment.Text);
    	e.InputParameters["Payment"] = Payment;
    	e.InputParameters["Notes"] = NewNotes.Text;
    	Nullable<System.DateTime> BankDate = 01/01/2001 00:00:00;
    	if (!string.IsNullOrEmpty(NewBankDate.Text)) {
    		BankDate = Convert.ToDateTime(NewBankDate.Text);
    	e.InputParameters["BankDate"] = BankDate;

    Open in new window

    LVL 29

    Expert Comment

    by:Paul Jackson

    Author Comment

    Thanks. It is with (..).
    TextBox NewWorkDate = (TextBox)gvWorkSheet.FooterRow.FindControl("NewWorkDate");

    Author Closing Comment

    LVL 18

    Expert Comment

    gvWorkSheet.FooterRow.FindControl("NewWorkDate") as TextBox;

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now