Can anyone convert the follwong VB to C# the online converters work but the application throws an error. I will post the code infront to make sure that the correct fields are bound.
Thanks
The code behind is:
Public Function GetDropDownValues(ByVal questionNo As String) As System.Data.DataView
Dim view As System.Data.DataView = CType(SqlDataSource2.Select(New DataSourceSelectArguments()), System.Data.DataView)
view.RowFilter = "QuestionNo=" + questionNo + ""
Return view
End Function
shabbsali81
Member
138 Points
134 Posts
convert vb to C#
Apr 03, 2012 11:31 AM|LINK
Hi
Can anyone convert the follwong VB to C# the online converters work but the application throws an error. I will post the code infront to make sure that the correct fields are bound.
Thanks
The code behind is:
Public Function GetDropDownValues(ByVal questionNo As String) As System.Data.DataView
Dim view As System.Data.DataView = CType(SqlDataSource2.Select(New DataSourceSelectArguments()), System.Data.DataView)
view.RowFilter = "QuestionNo=" + questionNo + ""
Return view
End Function
End Class
the code infront is:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="QuestionNo" DataSourceID="SqlDataSource1" Width="936px"
Height="193px" CellPadding="4" ForeColor="#333333" GridLines="None">
<RowStyle BackColor="#E3EAEB" />
<Columns>
<asp:BoundField DataField="DocRef" HeaderText="DocRef"
SortExpression="DocRef" />
<asp:TemplateField HeaderText="QuestionNo" SortExpression="QuestionNo">
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"
Text='<%# Bind("QuestionNo") %>' Height="21px" MaxLength="6"
ReadOnly="True" Width="85px"
AutoPostBack="True"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="QuestionText" HeaderText="Question Text"
SortExpression="QuestionText" />
<asp:TemplateField HeaderText="Response" SortExpression="QuestionNo">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("QuestionNo") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server" Height="32px" Width="290px"
DataSource='<%# GetDropDownValues(String.format("{0}",Eval("QuestionNo"))) %>'
DataTextField="ResponseText"
DataValueField="ResponseText" AutoPostBack="True"
style="margin-bottom: 0px"
>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Comment">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Height="58px" TextMode="MultiLine"
Width="246px" AutoPostBack="True"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Action" />
</Columns>
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<EmptyDataTemplate>
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="LinqDataSource1" DataTextField="ResponseText"
DataValueField="ResponseText">
</asp:DropDownList>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="Respone_ListDataContext"
Select="new (ResponseText)" TableName="Responses">
</asp:LinqDataSource>
</EmptyDataTemplate>
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</td>
<td class="style12">
</td>
<td class="style12">
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style18">
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:LdConnectionString %>"
SelectCommand="SELECT Responses.QuestionNo, Responses.ResponseText, Responses.DocRef FROM Responses INNER JOIN Questions ON Responses.QuestionNo = Questions.QuestionNo AND Responses.DocRef = Questions.DocRef WHERE (Responses.DocRef = N'si')">
</asp:SqlDataSource>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style13">
</td>
<td class="style20">
</td>
<td class="style16">
</td>
<td class="style16">
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style18">
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:LdConnectionString %>"
SelectCommand="SELECT Responses.Comment FROM Questions INNER JOIN Responses ON Questions.QuestionNo = Responses.QuestionNo AND Questions.DocRef = Responses.DocRef">
</asp:SqlDataSource>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style18">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style18">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:LdConnectionString %>"
SelectCommand="SELECT DocRef, QuestionNo, QuestionText FROM Questions WHERE (DocRef = N'si')">
</asp:SqlDataSource>
</td>
<td>
me_ritz
Star
9337 Points
1447 Posts
Re: convert vb to C#
Apr 03, 2012 11:45 AM|LINK
http://www.developerfusion.com/tools/convert/vb-to-csharp/
Thanks
shabbsali81
Member
138 Points
134 Posts
Re: convert vb to C#
Apr 03, 2012 12:06 PM|LINK
Thanks for your reply, that gives this
public System.Data.DataView GetDropDownValues(string questionNo)
{
System.Data.DataView view = (System.Data.DataView)SqlDataSource2.Select(new DataSourceSelectArguments());
view.RowFilter = "QuestionNo=" + questionNo + "";
return view;
}
and this trows out errors, ive tried it before
kirupa.v
Contributor
2070 Points
531 Posts
Re: convert vb to C#
Apr 03, 2012 12:15 PM|LINK
I doesn't get any error
public System.Data.DataView GetDropDownValues(string questionNo) { System.Data.DataView view = (System.Data.DataView)SqlDataSource2.Select(new DataSourceSelectArguments()); view.RowFilter = "QuestionNo=" + questionNo + ""; return view; }
While pasting in that convertion tool
don't put the
End Class
Because u did not specify the initialisation of that class.
For any clarifications, pls reply..
shabbsali81
Member
138 Points
134 Posts
Re: convert vb to C#
Apr 03, 2012 12:20 PM|LINK
appologies i ment that when i put that in my code behind page it shows errors.
kirupa.v
Contributor
2070 Points
531 Posts
Re: convert vb to C#
Apr 03, 2012 12:22 PM|LINK
Hi,
Can u specify what the error u get..
shabbsali81
Member
138 Points
134 Posts
Re: convert vb to C#
Apr 03, 2012 12:50 PM|LINK
invalid token '='in class, struct, or interface member declaration
me_ritz
Star
9337 Points
1447 Posts
Re: convert vb to C#
Apr 04, 2012 04:05 AM|LINK
Try changing to:
view.RowFilter = "QuestionNo = '" + questionNo + "'"; //Single quotes around
Thanks
kirupa.v
Contributor
2070 Points
531 Posts
Re: convert vb to C#
Apr 04, 2012 04:34 AM|LINK
Try with this
public System.Data.DataView GetDropDownValues(string questionNo) { System.Data.DataView view = (System.Data.DataView)SqlDataSource2.Select(new DataSourceSelectArguments()); view.RowFilter = "QuestionNo='" + questionNo + "'"; return view; }