0

我对此很陌生,所以我不明白这里有什么问题。

我在 gridview 的列中创建了带有事件的按钮,以通过传递 gridview 行项参数重定向到另一个 Web 表单。我收到这个错误 Cannot perform '=' operation on System.Int32 and System.String.

protected void gvAccommodations_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Open")
    {
        int Id = Convert.ToInt32(e.CommandArgument);
        Response.Redirect("~/Rooms.aspx?Id=" + Id);
    }
}


<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id">
</asp:BoundField>          
<asp:TemplateField>
    <ItemTemplate>
        <asp:Button ID="btnOdaberi" runat="server" Text="Odaberi" 
                       CommandName="Open" CommandArgument='<%# Bind("Id") %>'/>
        </ItemTemplate>
</asp:TemplateField>
4

2 回答 2

0

您不能将整数连接到字符串 - 您必须先使用 ToString 将其转换为字符串。

所以使用这一行:

Response.Redirect("~/Rooms.aspx?Id=" + Id.ToString());
于 2013-11-14T13:58:52.953 回答
0
protected void gvAccommodations_RowCommand(object sender, GridViewCommandEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Values["ID"].ToString();
if (e.CommandName == "Open")
{
    int Id = Convert.ToInt32(e.CommandArgument);
    Response.Redirect("~/Rooms.aspx?Id=" id);
}
}
于 2013-11-14T16:25:51.570 回答