Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Convert this VB code to C#

Convert this VB code to C#

Scheduled Pinned Locked Moved C#
csharpdesignhelpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    grewin
    wrote on last edited by
    #1

    HI all, Can someone please help me to convert this VB code to C#. Thanks! Private Sub DataGrid1_ItemDataBound (ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles DataGrid1.ItemDataBound Dim img As System.Web.UI.WebControls.Image If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then img = CType(e.Item.Cells(1).Controls(1), System.Web.UI.WebControls.Image) img.ImageUrl = "webform2.aspx?id=" & e.Item.Cells(0).Text End If End Sub EWIN

    C T D 3 Replies Last reply
    0
    • G grewin

      HI all, Can someone please help me to convert this VB code to C#. Thanks! Private Sub DataGrid1_ItemDataBound (ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles DataGrid1.ItemDataBound Dim img As System.Web.UI.WebControls.Image If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then img = CType(e.Item.Cells(1).Controls(1), System.Web.UI.WebControls.Image) img.ImageUrl = "webform2.aspx?id=" & e.Item.Cells(0).Text End If End Sub EWIN

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      There are conversion tools on the web that are free. It's also a good exercise to learn to do this. The big trick is, there is no C# syntax for 'handles', you need to assign the handler on page load or in the aspx.

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      1 Reply Last reply
      0
      • G grewin

        HI all, Can someone please help me to convert this VB code to C#. Thanks! Private Sub DataGrid1_ItemDataBound (ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles DataGrid1.ItemDataBound Dim img As System.Web.UI.WebControls.Image If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then img = CType(e.Item.Cells(1).Controls(1), System.Web.UI.WebControls.Image) img.ImageUrl = "webform2.aspx?id=" & e.Item.Cells(0).Text End If End Sub EWIN

        T Offline
        T Offline
        Travis D Mathison
        wrote on last edited by
        #3

        Translation of most VB.NET->C# (and other way around) is pretty simple but with a few things that are specific to one language and not the other. One thing that you could do to learn how one thing is written in language X vs. language Y is look at the direct translation from MSIL. You can download .NET Reflector from -> http://www.aisto.com/roeder/dotnet/[^] and load in an assembly with the above method in it (must be compilable at this point) and .NET Reflector will allow you to toggle between VB.NET and C#. .NET Reflector merely looks at the IL and translates to the language of choice from that (in most cases you can simply recompile from it as it does a fairly good job at it). Hope this helps a little, Cheers, -t

        1 Reply Last reply
        0
        • G grewin

          HI all, Can someone please help me to convert this VB code to C#. Thanks! Private Sub DataGrid1_ItemDataBound (ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles DataGrid1.ItemDataBound Dim img As System.Web.UI.WebControls.Image If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then img = CType(e.Item.Cells(1).Controls(1), System.Web.UI.WebControls.Image) img.ImageUrl = "webform2.aspx?id=" & e.Item.Cells(0).Text End If End Sub EWIN

          D Offline
          D Offline
          Dave Doknjas
          wrote on last edited by
          #4

          //TODO: INSTANT C# TODO TASK: Insert the following converted event handler wireups at the end of the 'InitializeComponent' method for forms, 'Page_Init' for web pages, or into a constructor for other classes: DataGrid1.ItemDataBound += DataGrid1_ItemDataBound; private void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e) { System.Web.UI.WebControls.Image img = null; if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { img = (System.Web.UI.WebControls.Image)(e.Item.Cells[1].Controls[1]); img.ImageUrl = "webform2.aspx?id=" + e.Item.Cells[0].Text; } }

          David Anton http://www.tangiblesoftwaresolutions.com C++ to C# Converter C++ to VB Converter C++ to Java Converter VB to Java Converter Java to VB & C# Converter Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: convert VB, C#, or Java to C++/CLI

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups