asp.net中如何数据库每一行中的内容读取到gridview后,也是行显示,我在每一行后面添加了一个按钮

2024年11月22日 11:03
有4个网友回答
网友(1):

GridView 是可以自定义模板列的,标签,里面可以放置你所需要的所有HTML元素的。

网友(2):

用模版,或编辑资料行选择ButtonField按钮,或CommandFiled里面的几个功能按钮都可以

下面是ButtonField的例子

                                ForeColor="#333333" GridLines="None" onrowcommand="GV2_RowCommand" 
                                onrowdeleting="GV2_RowDeleting" 
                                onselectedindexchanged="GV2_SelectedIndexChanged" PageSize="5" 
                                Width="100%">
                                
                                
                                    
                                    
                                

                                
                                
                                                                    CssClass="Freezing" HorizontalAlign="Left" />
                                
                                
                                
                                
                                
                                
                                
                            
后台
 protected void GV2_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int id = Convert.ToInt32(e.CommandArgument);  //找到主键id
        string USERID = this.GV2.DataKeys[id].Value.ToString(); //找到主键值

        if (e.CommandName == "PASS")// 找到名称
        {

            string sql = "  insert into account_user_t select * from account_user_t_new where userid='" + USERID + "' ";
            MySqlHelper.ExecuteNonQuery(PublicFun.PublicFunction.GetDBconstr("ce_manage_db"), sql);

            string sqldelete = " delete from  account_user_t_new where userid='" + USERID + "' ";
            MySqlHelper.ExecuteNonQuery(PublicFun.PublicFunction.GetDBconstr("ce_manage_db"), sqldelete);
            PublicFun.PublicFunction.showMsg(this, "已经通过注册");


            //自己的逻辑
        }
        else if (e.CommandName == "delete")
        {
            string sql = "delete from account_user_t_new where userId='" + USERID + "' ";
            MySqlHelper.ExecuteNonQuery(PublicFun.PublicFunction.GetDBconstr("ce_manage_db"), sql);
            PublicFun.PublicFunction.showMsg(this, "已删除此注册用户:" + USERID + "  ");

        }
        BoundList2();
        Newapp = "";
    }

网友(3):

直接在gridview后边加一模板列,添加按钮就是了

网友(4):

运用模板列就可以了。