コード例 #1
0
    protected void gvData_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string commandName = e.CommandName;
        int    id          = e.CommandArgument.ToArrowInt();

        TMS.Slider bll = new TMS.Slider();
        if (e.CommandName == "UpdateData")
        {
            GridViewRow drv     = ((GridViewRow)(((LinkButton)(e.CommandSource)).Parent.Parent));
            string      picName = (gvData.Rows[drv.RowIndex].FindControl("tbName") as TextBox).Text;
            int         sort    = (gvData.Rows[drv.RowIndex].FindControl("tbSort") as TextBox).Text.ToArrowInt();
            var         model   = bll.Select(id);
            if (model != null)
            {
                model.Name      = picName;
                model.SortOrder = sort;
                bll.Update(model);
            }
        }
        else if (e.CommandName == "DelData")
        {
            //删除
            new TMS.Slider().Delete(id);
        }

        BindData();
        MessageBox.Show("操作成功!");
    }
コード例 #2
0
    protected void btnUpdateAll_Click(object sender, EventArgs e)
    {
        TMS.Slider bll = new TMS.Slider();
        foreach (GridViewRow row in gvData.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                int    id    = (row.FindControl("hfID") as HiddenField).Value.Trim().ToArrowInt();
                string name  = (row.FindControl("tbName") as TextBox).Text.Trim();
                int    order = (row.FindControl("tbSort") as TextBox).Text.Trim().ToArrowInt();
                var    model = bll.Select(id);
                if (model != null)
                {
                    model.Name      = name;
                    model.SortOrder = order;
                    bll.Update(model);
                }
            }
        }

        BindData();
        MessageBox.Show("更新成功!");
    }