C# Can';“由于错误而无法重定向”;无法执行'=';对System.Int32和System.String的操作。”;

C# Can';“由于错误而无法重定向”;无法执行'=';对System.Int32和System.String的操作。”;,c#,asp.net,redirect,gridview,C#,Asp.net,Redirect,Gridview,我对这个很陌生,所以我不明白这里出了什么问题 我在gridview with事件列中创建了一个按钮,用于重定向到另一个web表单,并传递gridview行项目参数。我得到这个错误 无法对System.Int32和System.String执行“=”操作。 protected void gvAccommodations_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Open")

我对这个很陌生,所以我不明白这里出了什么问题

我在gridview with事件列中创建了一个按钮,用于重定向到另一个web表单,并传递gridview行项目参数。我得到这个错误
无法对System.Int32和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>
protectedvoid gvconditions\u row命令(对象发送方,GridViewCommandEventArgs e)
{
如果(如CommandName==“打开”)
{
int Id=Convert.ToInt32(e.CommandArgument);
Response.Redirect(“~/Rooms.aspx?Id=“+Id”);
}
}

不能将整数合并到字符串中-必须先使用ToString将其转换为字符串

所以用这句话:

Response.Redirect("~/Rooms.aspx?Id=" + Id.ToString());

... <代码>Id.ToString()。事实上,错误消息清楚地说明了问题所在。错误在哪里?在呈现GridView时您是否得到错误?当页面加载时?当我单击按钮转到新的web表单时,我会收到错误。请您提供stacktrace或错误实际发生的代码行。实际上
。编译器将推断ToString()
,因为您将其添加到字符串中,所以不必这样做。我认为这不是错误。
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);
}
}