Skip to content

VB.Net Code translation to C# Code

skagita

Asked Oct 11, 2004, 9:40 PM EDT3 answers
Share
LinkedInX
Hi all, I would like to translate the following VB .net code lines to c# If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then Dim txtHdnEmpID As TextBox = e.Item.FindControl("txtHEmpID") txtHdnEmpID.Text = e.Item.Cells(1).Text Dim linkCell As TableCell linkCell = (e.Item.Cells(1)) Dim strEmpID = e.Item.Cells(1).Text Dim strForm As String = "EmpDetails.aspx" linkCell.Text = e.Item.Cells(1).Text End If Thanks a Lot in Advance. Cheers, Kagita Srihari

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Assuming all these classes exist in C#... if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { TextBox txtHdnEmpID = e.Item.FindControl("txtHEmpID"); txtHdnEmpID.Text = e.Item.Cells[1].Text; TableCell linkCell = (e.Item.Cells[1]); string strEmpID = e.Item.Cells(1).Text; string strForm = "EmpDetails.aspx"; linkCell.Text = e.Item.Cells(1).Text }
    0
  • 0
    I ran this through the Instant C# vb.net to c# converter and got: if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType == ListItemType.AlternatingItem) { TextBox txtHdnEmpID = e.Item.FindControl("txtHEmpID"); txtHdnEmpID.Text = e.Item.Cells[1].Text; TableCell linkCell = null; linkCell = (e.Item.Cells[1]); object strEmpID = e.Item.Cells[1].Text; string strForm = "EmpDetails.aspx"; linkCell.Text = e.Item.Cells[1].Text; }
    0
  • 0
    This shows why it's tough to do this by hand - the other post missed changing a few round brackets on the "Cells" call to square brackets and replaced "Or" with "||", which is not the exact intention of the VB code - the equivalent of "Or" is "|" - "OrElse" translates to "||".
    0