在GridView的模板列(ItemTemplate)中添加三个Button,跳转到同一个页面,但传递不同的多个参数,其中有一个参数是当前行的值,怎样传递呀?
我在Button里有个PostBackUrl属性设置:aaa.aspx?id={0}&name=tian,怎样把当前行的编号传进去,好像可以设置什么命令参数的,不知道行不行?

解决方案 »

  1.   

    让我来告诉你吧。
    <asp:TemplateField HeaderText="操 作">
                                    <ItemTemplate>
                                        <asp:Button ID="btnEdit" runat="server" CommandArgument=' <%#   Eval( "InfoId ")   %> '
                                            CommandName="Edit" Text=" 编 辑 " />
                                        <asp:Button ID="btnDel" runat="server" CommandArgument=' <%#   Eval( "InfoId ")   %> '
                                            CommandName="Delete" Text=" 删 除 "  OnClientClick="return confirm('确认要删除此行信息吗?')"/>
                                        <asp:Button ID="btnTop" runat="server" CommandName="Top" Text=" 置 顶 "  CommandArgument=' <%#   Eval( "InfoId ")   %> '/>
                                        <asp:Button ID="btnHot" runat="server" CommandName="Hot" Text="设为热点" CommandArgument=' <%#   Eval( "InfoId ")   %> ' />
                                        <asp:Button ID="btnNoHot" runat="server" CommandName="NoHot" Text="取消热点"  CommandArgument=' <%#   Eval( "InfoId ")   %> '/>
                                    </ItemTemplate>
                                </asp:TemplateField> protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {        if (e.CommandName == "Edit")
            {     
                int id = Convert.ToInt32(e.CommandArgument.ToString());
                Response.Redirect("editInfo.aspx?InfoId=" + id);
            }
            if (e.CommandName == "Delete")
            {
                int id = Convert.ToInt32(e.CommandArgument.ToString());
                Response.Redirect("deleteInfo.aspx?InfoId=" + id);
            }
            if (e.CommandName == "Hot")
            {
                int id = Convert.ToInt32(e.CommandArgument.ToString());
                Response.Redirect("setHot.aspx?InfoId=" + id);
            }
            if (e.CommandName == "NoHot")
            {
                int id = Convert.ToInt32(e.CommandArgument.ToString());
                Response.Redirect("setNoHot.aspx?InfoId=" + id);
            }
            if (e.CommandName == "Top")
            {
                int id = Convert.ToInt32(e.CommandArgument.ToString());
                Response.Redirect("setTop.aspx?InfoId=" + id);
            }
        }好了。给分吧。别小气哦