0
以下是渲染柵格項(單元格)失敗嘗試的腳本。 想法是處理輸入值並將其返回給單元格渲染。渲染GridView項目文本
ASP
<asp:GridView ID="GridView_stations" runat="server" AutoGenerateColumns="False"
DataSourceID="mailreport" AllowSorting="True" Width="100%" AllowPaging="True">
<Columns>
<asp:BoundField DataField="id" HeaderText="ID" SortExpression="id" >
<HeaderStyle HorizontalAlign="Center" Width="70px" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="name" ItemStyle-CssClass="padding-left" HeaderText="Name" SortExpression="name" >
<HeaderStyle CssClass="padding-left" HorizontalAlign="Left" />
<ItemStyle CssClass="padding-left"></ItemStyle>
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button runat="server" Text='<%#renderthis(Eval("id"))%>' CommandArgument='<%#Eval("id")%>' OnClick="DoRedirect" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="description" ItemStyle-CssClass="padding-left" HeaderText="Description"
SortExpression="description" >
<HeaderStyle CssClass="padding-left" HorizontalAlign="Left" />
<ItemStyle CssClass="padding-left"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="name" HeaderText="Last report"
SortExpression="name" >
<HeaderStyle HorizontalAlign="Center" Width="120px" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="name" HeaderText="Status" SortExpression="name" >
<HeaderStyle HorizontalAlign="Center" Width="100px" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
</asp:GridView>
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MailReport
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected string renderthis(string sender)
{
string str = sender.ToString()+"-str";
return str;
}
protected void DoRedirect(object sender, EventArgs e)
{
Button theButton = sender as Button;
Response.Redirect("Newpage.aspx?ID=" + theButton.CommandArgument);
}
}
}
錯誤:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1502: The best overloaded method match for 'MailReport.WebForm1.renderthis(string)' has some invalid arguments
Source Error:
Line 25: <asp:Button runat="server" **
Text='<%#renderthis(Eval("id"))%>'** CommandArgument='<%#Eval("id")%>' OnClick="DoRedirect" />
請你能幫助我理解這個錯誤以及如何繼續。