VB to C# help

C

Cdudej

Hello
Any help appreciated.
I need to convert this:

Protected Sub grdMaster_RowDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
Handles grdMaster.RowDataBound
Dim objListItem As DataControlRowState
objListItem = e.Row.RowState
Dim intMAsterID1 As Integer
If e.Row.RowType = DataControlRowType.DataRow Then
Dim grd As GridView
If objListItem = 5 Then
grd = CType(e.Row.FindControl("grdChildGridEdit"),
GridView)
MasterTableID = Convert.ToInt32(CType(e.Row.DataItem, _
DataRowView).Row.ItemArray(0).ToString())
intMAsterID1 = MasterTableID
If grd IsNot Nothing Then
grd.DataSourceID = ""
grd.DataSource = ChildDataSource
ChildDataSource.SelectParameters(_
"MasterTableID").DefaultValue = intMAsterID1
ChildDataSource.Select()
grd.DataBind()

To C#.
DataRowState objListItem = new DataRowState();
int intMAsterID1;
if (e.Row.RowType = DataControlRowType.DataRow)
{
GridView grd = new GridView();
if (objListItem = 5)
{
grd = (GridView)
(e.Row.FindControl("grdChildGridEdit"));
//Cant get this line. I havent used vb before.
//intMAsterID1 =
int.Parse(e.Row.DataItem).Row.ItemArray(0).ToString())
if (grd != null)
{
grd.DataSourceID = "";
grd.DataSource = ChildDataSource;
}
}
}
 
A

Alberto Poblacion

Cdudej said:
[...]
if (objListItem = 5)

This should use ==.
//Cant get this line. I havent used vb before.
//intMAsterID1 =
int.Parse(e.Row.DataItem).Row.ItemArray(0).ToString())

Should be ItemArray[0] (in C#, use square brackets for the indexer,
instead of parenthesis). Also note that you are missing an opening
parenthesis.
BTW, int.Parse is not always equivalent to Convert.Int32. If you want to
preserve the original semantics, use this:

MasterTableID =
Convert.ToInt32(((DataRowView)e.Row.DataItem).Row.ItemArray[0].ToString());
 
G

Göran Andersson

Cdudej said:
Hello
Any help appreciated.
I need to convert this:

Protected Sub grdMaster_RowDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
Handles grdMaster.RowDataBound
Dim objListItem As DataControlRowState
objListItem = e.Row.RowState
Dim intMAsterID1 As Integer
If e.Row.RowType = DataControlRowType.DataRow Then
Dim grd As GridView
If objListItem = 5 Then
grd = CType(e.Row.FindControl("grdChildGridEdit"),
GridView)
MasterTableID = Convert.ToInt32(CType(e.Row.DataItem, _
DataRowView).Row.ItemArray(0).ToString())
intMAsterID1 = MasterTableID
If grd IsNot Nothing Then
grd.DataSourceID = ""
grd.DataSource = ChildDataSource
ChildDataSource.SelectParameters(_
"MasterTableID").DefaultValue = intMAsterID1
ChildDataSource.Select()
grd.DataBind()

To C#.
DataRowState objListItem = new DataRowState();

Don't create instances that you won't use.

DataControlRowState objListItem;

You missed a line:

objListItem = e.Row.RowState;
int intMAsterID1;
if (e.Row.RowType = DataControlRowType.DataRow)

The operator == is used for comparison:

if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView grd = new GridView();

GridView grd;
if (objListItem = 5)

if (objListItem == 5)
{
grd = (GridView)
(e.Row.FindControl("grdChildGridEdit"));
//Cant get this line. I havent used vb before.
//intMAsterID1 =
int.Parse(e.Row.DataItem).Row.ItemArray(0).ToString())

The equivalent is this (but will eventually use Parse anyway):

intMAsterID1 =
Convert.ToInt32(((DataRowView)e.Row.DataItem).Row.ItemArray(0).ToString())

However, you should try to convert the value directly instead of
converting to a string and then parse the string.
if (grd != null)
{
grd.DataSourceID = "";
grd.DataSource = ChildDataSource;

Missing:

ChildDataSource.SelectParameters("MasterTableID").DefaultValue =
intMAsterID1;
ChildDataSource.Select();
grd.DataBind();
 
D

David Anton

DataControlRowState objListItem;
objListItem = e.Row.RowState;
int intMAsterID1 = 0;
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView grd = null;
if (objListItem == 5)
{
grd = (GridView)(e.Row.FindControl("grdChildGridEdit"));
MasterTableID =
Convert.ToInt32(((DataRowView)e.Row.DataItem).Row.ItemArray[0].ToString());
intMAsterID1 = MasterTableID;
if (grd != null)
{
grd.DataSourceID = "";
grd.DataSource = ChildDataSource;
ChildDataSource.SelectParameters("MasterTableID").DefaultValue =
intMAsterID1;
ChildDataSource.Select();
grd.DataBind();
}
}
}
 
K

Kenneth Cochran

Hello
Any help appreciated.
I need to convert this:

Protected Sub grdMaster_RowDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
Handles grdMaster.RowDataBound
Dim objListItem As DataControlRowState
objListItem = e.Row.RowState
Dim intMAsterID1 As Integer
If e.Row.RowType = DataControlRowType.DataRow Then
Dim grd As GridView
If objListItem = 5 Then
grd = CType(e.Row.FindControl("grdChildGridEdit"),
GridView)
MasterTableID = Convert.ToInt32(CType(e.Row.DataItem, _
DataRowView).Row.ItemArray(0).ToString())
intMAsterID1 = MasterTableID
If grd IsNot Nothing Then
grd.DataSourceID = ""
grd.DataSource = ChildDataSource
ChildDataSource.SelectParameters(_
"MasterTableID").DefaultValue = intMAsterID1
ChildDataSource.Select()
grd.DataBind()

To C#.
DataRowState objListItem = new DataRowState();
int intMAsterID1;
if (e.Row.RowType = DataControlRowType.DataRow)
{
GridView grd = new GridView();
if (objListItem = 5)
{
grd = (GridView)
(e.Row.FindControl("grdChildGridEdit"));
//Cant get this line. I havent used vb before.
//intMAsterID1 =
int.Parse(e.Row.DataItem).Row.ItemArray(0).ToString())
if (grd != null)
{
grd.DataSourceID = "";
grd.DataSource = ChildDataSource;
}
}
}

The lazy way...
Drop it into an assembly.
Download .NET Reflector.
In Reflector go to View > Options
Set it to disassemble to C#
Find grdMaster_RowDataBound(...
Click Tools > Disassemble
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top