Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type this from VB.NET to C# 1

Status
Not open for further replies.

aspvbnetnerd

Programmer
May 16, 2006
278
SE
I would like to type this to C#. I am new to C# but know VB.NET

Code:
Protected Sub GridProjects_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridProjects.RowUpdating

Dim empid As String
empid = CType(GridProjects.Rows(e.RowIndex).Cells(4).Text, String)
Dim FieldName1 As New System.Web.UI.WebControls.TextBox
Dim FieldName2 As New System.Web.UI.WebControls.TextBox
FieldName1 = CType(Me.GridProjects.Rows(e.RowIndex).Cells(5).Controls(0), TextBox)
FieldName2 = CType(Me.GridProjects.Rows(e.RowIndex).Cells(6).Controls(0), TextBox)
Dim sFName As String = FieldName1.Text
Dim dFName As String = FieldName2.Text

End Sub

I have tried but I type it in C#, but with no success.
Code:
int IntProjectID;
IntProjectID = int.Parse(GridProjects.Rows[e.RowIndex].Cells[4].Text);

System.Web.UI.WebControls.TextBox FieldName1 = new System.Web.UI.WebControls.TextBox();
System.Web.UI.WebControls.TextBox FieldName2 = new System.Web.UI.WebControls.TextBox();

FieldName1 = (System.Web.UI.WebControls.TextBox) e.Item.Cells[0].Controls[0];
FieldName2 = (this.GridProjects.Rows[e.RowIndex].Cells[6].Controls[0]);

Any help is appriciated

/George
 
What do you mean with no success? Do you get errors? Is there anything in particular that doesn't work as expected?

You may also want to look at

-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
ca8msm, thanks for the response.

Nice, site. That goes to my favorites :)
Now it complains about the rows.

Code:
string empid;
empid = ((string)(GridProjects.Rows[e.RowIndex].Cells[4].Text));
System.Web.UI.WebControls.TextBox FieldName1 = new System.Web.UI.WebControls.TextBox();
System.Web.UI.WebControls.TextBox FieldName2 = new System.Web.UI.WebControls.TextBox();
FieldName1 = ((TextBox)(this.GridProjects.[COLOR=red]Rows[/color](e.RowIndex).Cells[5].Controls[0]));
FieldName2 = ((TextBox)(this.GridProjects.[COLOR=red]Rows[/color](e.RowIndex).Cells[6].Controls[0]));
string sFName = FieldName1.Text;
string dFName = FieldName2.Text;

'System.Web.UI.WebControls.GridView.Rows' is a 'property' but is used like a 'method'

There is nothing wrong with my vb.net code

/George
 
Code:
FieldName1 = ((TextBox)(this.GridProjects.Rows[COLOR=blue][e.RowIndex][/color].Cells[5].Controls[0]));
FieldName2 = ((TextBox)(this.GridProjects.Rows[COLOR=blue][e.RowIndex][/color].Cells[6].Controls[0]));

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
the converter will do this almost always, carolsag, and many others.

kinda sorta -
in c# if an item has an index, it uses [ ]
hard to explain, but use [ ] almost always when the parameter is going to expect an index

this.GridProjects.Rows[e.RowIndex].Cells[5].Controls[0]

its hard for all the converters to pick up on that.

you will see DataGrid.Columns(0) as well, but it needs to be DataGrid.Colums[0]

hope i didnt confuse you more!
 
Works like a charm. :) Many thanks.
When do you know when to use [ and to use ( in C#.

Trying to learn C#

/George
 
indexers use brackets.
method signatures use parantheses.
google c# syntax for more information. I also recommend the CLR via C# book.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
you'll get a hang of it really quick, the hardest part is converting old code, but IMO, you'll develop better habits because c# is so strict. (looks like we posted at same time, did u see above?)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top