我在這方面很新穎。我有用vb.net編寫的腳本,但我想用C#轉換,但它不能用作vb.net代碼。所以請幫助。VB.net到asp.net中的C#轉換
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="2"
ForeColor="#333333" GridLines="None" AllowPaging="True">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkdownload" runat="server" Text="Download" CommandName="Download"
CommandArgument='<%#Eval("FullName") +";" + Eval("Name") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="File Name" />
<asp:BoundField DataField="Length" HeaderText="Size (Bytes)" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
。
Private Sub BindGrid()
Dim DataDirectory As String = "~/Uploads"
Dim files() As FileInfo = New DirectoryInfo(Server.MapPath(DataDirectory)).GetFiles
GridView1.DataSource = files
GridView1.DataBind()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BindGrid()
End If
End Sub
Private Sub Downloadfile(ByVal fileName As String, ByVal FullFilePath As String)
Response.AddHeader("Content-Disposition", "attachment; filename=" & fileName)
Response.TransmitFile(FullFilePath)
Response.End()
End Sub
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
If e.CommandName = "Download" Then
Dim fileInfo() As String = e.CommandArgument.ToString().Split(";")
Dim FileName As String = fileInfo(1)
Dim FullPath As String = fileInfo(0)
Downloadfile(FileName, FullPath)
End If
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
BindGrid()
End Sub
哪部分代碼沒有像VB那樣執行?具體是什麼問題? – 2010-09-09 16:08:30
我們通常喜歡看到你先把更多的工作放到裏面去。嘗試並詢問引起問題的特定行或片段,或者至少先通過在線轉換器運行它。我會很有幫助地說,aspx標記應該能夠保持不變。 – 2010-09-09 16:10:01
以及我在我的問題嘗試在asp.net我的問題下載問題我給了我轉換的代碼,但它沒有奏效,這就是爲什麼我要求它。由於它非常緊急,我無法通過它進行研究。 – sayket 2010-09-09 16:21:41