Convert this VB code to C#
-
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
-
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
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 )
-
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
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
-
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
//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