gridview 后台增加列

BoundField field1 = null;

field1 = new BoundField();  //实例化

field1.HeaderText = "序号";
field1.HeaderStyle.Width = new Unit(40, UnitType.Pixel);
field1.ItemStyle.CssClass = "GridViewClo";

GridView1.Columns.Add(field1); //增加列

 

//把模板列谢伟一般列 BoundField 导入事件

//还是行上面一样先搭一个BoundField 

然后在GridView1_RowDataBound事件中加列的事件

for (int i = 0; i < GridView1.Columns.Count; i++)
{
DataControlField dcf = GridView1.Columns[i];

if (dcf.HeaderText.IndexOf("班主任评语") == 0)
{
string sqlpingyu = "select Commentpingyu from base_comment where Stu_code= '" + e.Row.Cells[1].Text + "'";
string Commentpingyu = DataBase.Exec(sqlpingyu);

string xueqi = "select termxueqi from base_comment where Stu_code= '" + e.Row.Cells[1].Text + "'";
string termxueqi = DataBase.Exec(xueqi);
if (termxueqi == "")
{

//学期
string xueqimax = "select top 1 Key_number from Base_DbKey where Key_parentnumber='000028' order by key_name desc ";
termxueqi = DataBase.Exec(xueqimax); 
}

e.Row.Cells[i].Text = "<input type=\"button\" id=\"btndead\" title=\"编辑\" class=\"btndead\" style=\" width:17px; height:15px;background:url(../../Images/blue/2014/pin.png);\" onclick=\"guestedit(this,'" + i + "','" + e.Row.Cells[1].Text + "','" + termxueqi + "','" + Commentpingyu + "')\" />";

}

}

 

在看看前台的事件:

function guestedit(obj, numbers, code,termxueqi, Commentpingyu) {
// var sel = document.getElementById('ddl_xq');
// var ddlcode = sel.options[sel.selectedIndex].value;
Window_Open(obj, 1, '../student/studentcommentAdd.aspx?numbers=' + numbers + '&code=' + code + '&DDL=' + termxueqi + '&Commentpingyu=' + Commentpingyu, 600, 400);
}

 

posted @ 2016-01-18 16:32  来自潘大大  阅读(1224)  评论(0编辑  收藏  举报