Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

Convert VB.NET to C#

Hi,

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
0
Takeoutdinner
Asked:
Takeoutdinner
  • 2
  • 2
1 Solution
 
dj_alikCommented:
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

0
 
TakeoutdinnerAuthor Commented:
Thanks. It is with (..).
TextBox NewWorkDate = (TextBox)gvWorkSheet.FooterRow.FindControl("NewWorkDate");
0
 
TakeoutdinnerAuthor Commented:
Thanks.
0
 
dj_alikCommented:
OR
gvWorkSheet.FooterRow.FindControl("NewWorkDate") as TextBox;
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now