GridView使用技巧之:如何在RowCommand里获取内容

Code

      对于非模板列的内容的获取方法:
Code

获取最后一列非模板列的行索引,单击最后一列按钮列的处理函数如下:
        protected void GV_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //该句是关键,获取行索引
            int index = Convert.ToInt32(e.CommandArgument);
            switch (e.CommandName)
            {
                case "RowUpdate":
                    string sql = "Update ep_table Set Pj_name = '" + ((TextBox)(GV.Rows[index].FindControl("txtProname"))).Text.Trim()
                        + "',Dbname = '" + ((TextBox)(GV.Rows[index].FindControl("txtDbname"))).Text.Trim()
                        + "',StartTime ='" + ((WebCalendar)(GV.Rows[index].FindControl("StartTime"))).Text.Trim()
                        + "',EndTime ='" + ((WebCalendar)(GV.Rows[index].FindControl("EndTime"))).Text.Trim()
                        + "',BackUpTime = '" + ((WebCalendar)(GV.Rows[index].FindControl("BackUpTime"))).Text.Trim()
                        + "',Flag = '" + ((DropDownList)(GV.Rows[index].FindControl("Status"))).SelectedValue + "' Where Id ='" + GV.Rows[index].Cells[0].Text.Trim() + "'";
                    DB.ExecuteSQL(sql);
                    sql = "Update MultiProject Set Description ='" + ((TextBox)(GV.Rows[index].FindControl("txtProname"))).Text.Trim() + "' Where Dbname = '" + ((TextBox)(GV.Rows[index].FindControl("txtDbname"))).Text.Trim() + "'";
                    SqlConnection con = DB.CreateConnectionToElite();
                    DB.ExecuteSQL(sql, con);
                    Function.RemoveGVRows(GV);
                    ShowGridView();
                    Response.Write("<Script language='JavaScript'>alert('更新成功!')</Script>");
                    break;
            }
        }

posted on 2009-07-21 22:11  jef  阅读(787)  评论(0编辑  收藏  举报

导航