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!

Can anybody convert this from VB.NE 1

Status
Not open for further replies.

lfc77

Programmer
Aug 12, 2003
218
GB
Can anybody convert this from VB.NET to C#?

If Int32.Parse(CatID) = _
Int32.Parse(dt.Rows(iLoop)("ID")) then
Return iLoop
End If

Thanks,

lfc77
 
If you could specify what dt is it would be easier, but the rest of the code should look like:
Code:
If Int32.Parse(CatID) = _
     Int32.Parse(dt.Rows(iLoop)("ID")) then
     Return iLoop
End If
 
if (System.Convert.ToInt32(CatID) == System.Convert.ToInt32(dt.Rows_stuff_here))
     return iLoop;

Regards,
John
 
i suspect dt is a DataTable. in which case 'dt.Rows(iLoop)("ID")' becomes 'dt.Rows[iLoop]["ID"]'.

'Int32.Parse' works in c# also, but 'System.Convert.ToInt32' is just as good. i tend to use 'int.Parse'. 3 down...

____________________________________________________
If you like a post, show you care by giving it a star.
 
My code now looks like this, but the error I get now is that 'not all code paths return a value'. Is there any way I can get around this? By the way, dt is a dataset.

public int GetSelIndex(string strCallType)
{
int intLoop;
//Loop through each row in the DataSet
DataTable dt = ddlDataSet.Tables["CallTypes"];

for (intLoop = 0; intLoop >= dt.Rows.Count-1; intLoop ++)
{
if (Convert.ToInt32(strCallType) == Convert.ToInt32((string)dt.Rows[intLoop]["CallType"]))
{
return intLoop;
}
}
}


Cheers,

Mike

 
public int GetSelIndex(string strCallType)
{
int intLoop;
//Loop through each row in the DataSet
DataTable dt = ddlDataSet.Tables"CallTypes";

for (intLoop = 0; intLoop >= dt.Rows.Count-1; intLoop ++)
{
if (Convert.ToInt32(strCallType) == Convert.ToInt32((string)dt.Rows[intLoop]"CallType"))
{
return intLoop;
}
}
return -1;
}


the problem comes if 'Convert.ToInt32(strCallType)' never equals 'Convert.ToInt32((string)dt.Rows[intLoop]"CallType")'. if such a thing occurs now, it'll return -1, remember to look out for this when calling the method.

____________________________________________________
If you like a post, show you care by giving it a star.
 
I'm now getting the error 'DataItem denotes a 'property' where a 'method' was expected again! My code is :

public int GetSelIndex(string strCallType)
{
int intLoop;
//Loop through each row in the DataSet
DataTable dt = ddlDataSet.Tables["CallTypes"];

for (intLoop = 0; intLoop >= dt.Rows.Count-1; intLoop ++)
{
if (Convert.ToInt32(strCallType) == Convert.ToInt32((string)dt.Rows[intLoop]["CallType"]))
{
return intLoop;
}
}
return -1;
}

And the related asp is :

<asp:TemplateColumn HeaderText=&quot;CallType&quot;>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, &quot;CallType&quot;) %>
</ItemTemplate>

<EditItemTemplate>
<asp:DropDownList runat=&quot;server&quot; id=&quot;lstCallTypes&quot;
DataValueField=&quot;CallType&quot;
DataTextField=&quot;CallType&quot;
DataSource='<%# GetCallTypes() %>'
SelectedIndex='<%# GetSelIndex(Container.DataItem(&quot;CallType&quot;)) %>'
/>
</EditItemTemplate>

</asp:TemplateColumn>


This is really driving me up the wall! What am I doing wrong here?


Thanks,

Mike

 
where is the error thrown? i assume it's on compile, but at what line? i'm going to assume &quot;SelectedIndex='<%# GetSelIndex(Container.DataItem(&quot;CallType&quot;)) %>' &quot;, tell me if it isn't.

does Container.DataItem(string) return a string?

is SelectedIndex a string? (the name suggests it isn't, but what's in a name?).

____________________________________________________
If you like a post, show you care by giving it a star.
 
The error is thrown on this line :

<asp:DropDownList runat=&quot;server&quot; id=&quot;lstCallTypes&quot;

The (Container.DataItem(&quot;CallType&quot;)) should be an int, but I've already tried passing it as an int and it didn't work, so I tried it the way my VB.NET example does it by passing it as a string for some reason.


Mike


 
i don't know enough about asp to know what's happening here, sorry. might want to try the asp forum.

on a sidenote, you might want to parse Container.DataItem(&quot;CallType&quot;) as a string if that is how you are using is. (there's probably a method called something like string.Parse).

best of luck

____________________________________________________
If you like a post, show you care by giving it a star.
 
I'm pretty certain the problem lies with the C# rather than the ASP. If I was going to pass it as an int rather than a string can you give me your idea of how my function should differ from how it is now?

Thanks for your help anyway, you deserve a star for effort!


Cheers,

Mike
 
public int GetSelIndex(int strCallType)
{
int intLoop;
//Loop through each row in the DataSet
DataTable dt = ddlDataSet.Tables&quot;CallTypes&quot;;

for (intLoop = 0; intLoop >= dt.Rows.Count-1; intLoop ++)
{
if (strCallType == Convert.ToInt32((string)dt.Rows[intLoop]&quot;CallType&quot;))
{
return intLoop;
}
}
return -1;
}

;)

____________________________________________________
If you like a post, show you care by giving it a star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top