本人以前是学C#的,近来要用VB.NET,不知是不是C#比VB.NET强大还是自己不懂得转变,下面这一小段代码我尝试了好多次,想把它转成VB.NET,但都不成功,讲大家帮个忙!谢谢大家!
private void Button1_Click(object sender, System.EventArgs e)
{
string sql;
sql="";
foreach(DataGridItem item in this.DataGrid1.Items)
{
if(((CheckBox)item.FindControl ("chk")).Checked ==true)
{
sql+="id="+item.Cells[0].Text;
}
}}
最主要是if(((CheckBox)item.FindControl ("chk")).Checked ==true)这句不知道怎样转换!

解决方案 »

  1.   

    if ctype(item.FindControl ("chk")),CheckBox).Checked ==true then     sql+="id="+item.Cells(0).Text
    end if
      

  2.   

    C#比VB.net功能强大这个问题毋庸置疑
    我对VB都不怎么了解
    怕给你写出来万一不成丢人
    帮你顶吧
      

  3.   

    二楼的楼主,我照你的意思去做了,但是电脑提示在if ctype(item.FindControl ("chk")),CheckBox).Checked ==true then 这句的("chk")),CheckBox的","那里有错。
      

  4.   

    大概是
    For Each item In Me.DataGrid1.Items
                If CType((item.FindControl("chk")), CheckBox).Checked = True Then
                    strsql += "id=" + item.Cells(0).Text
                End If
    Next
      

  5.   

    好像在一般情况下VB.net 和 C#的功能都差不多吧!  语法有些不同
      

  6.   

    For Each item as DataGridItem In Me.DataGrid1.Items
                If CType((item.FindControl("chk")), CheckBox).Checked = True Then
                    strsql += "id="&item.Cells(0).Text
                End If
     Next
      

  7.   

    唉,问题真多,在同样的程序strsql += "id=" + item.Cells(0).Text 在C#里
    if(((CheckBox)item.FindControl ("chk")).Checked ==true)
    {
    sql+="id="+item.Cells[0].Text;
    }
    可以执行得了,而在VB.NET中
    If CType((item.FindControl("chk")), CheckBox).Checked = True Then
             sql+= "id=" + item.Cells(0).Text
    End If就执行不了,真怪!!!
      

  8.   

    c#只是编译时速度快一点,编译后的代码执行速度基本上没区别了
    C#能做的,vb.net也都能做