后台设置GridView列
protected void BindGVJFView()
{
//初始化GridView
int num = this.GVJF.Columns.Count;
for (int i = 0; i < num; i++)
{
this.GVJF.Columns.RemoveAt(0);
}
//将部分数据转为超链接
DataTable dtGV = StoreSNDAL.GetJF(this.txtKeywords.Text, GetPKStore(), this.ddlYear.SelectedValue).Copy();
//处理DataTable中的数据
//遍历行
for (int i = 0; i < dtGV.Rows.Count; i++)
{
string aPKStoreUser = dtGV.Rows[i][0].ToString().Trim();
string a1 = "<a href='javascript:void(0);' onclick=" + '"' + "window.open('StoreMonthSN.aspx?PK_StoreUser=" + aPKStoreUser + "&intMonth=0','StoreMonthSN','height=800, width=1000, top=30, left=500, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no')" + '"' + ">" + dtGV.Rows[i]["StoreUserName"] + "</a>";
dtGV.Rows[i]["StoreUserName"] = a1;
//遍历列
for (int j = 5; j < dtGV.Columns.Count; j++)
{
string mon = GetMonth(dtGV.Columns[j].ColumnName.ToString());//获取月份
string p = dtGV.Rows[i][j].ToString().Trim();
string a2 = "<a href='javascript:void(0);' onclick=" + '"' + "window.open('StoreMonthSN.aspx?PK_StoreUser=" + aPKStoreUser + "&intMonth=" + mon + "','StoreMonthSN','height=800, width=1000, top=30, left=500, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no')" + '"' + ">" + p + "</a>";
dtGV.Rows[i][j] = a2;
}
}
//添加列
BindJFColumn("店员姓名", "StoreUserName", 0);
BindJFColumn("手机号", "UserPhone", 1);
BindJFColumn("是否在职", "UserState", 2);
BindJFColumn("员工类型", "UserType", 3);
for (int i = 5; i < dtGV.Columns.Count; i++)
{
BindJFColumn(dtGV.Columns[i].ColumnName.ToString(), dtGV.Columns[i].ColumnName.ToString(), i - 1);
}
this.GVJF.DataSource = dtGV;
this.GVJF.DataBind();
}
/// <summary>
/// 绑定GridView的列
/// </summary>
/// <param name="HeaderText">列名</param>
/// <param name="DataField">列值</param>
/// <param name="num">索引位置</param>
protected void BindJFColumn(string HeaderText, string DataField, int num)
{
BoundField column = new BoundField();
column.HeaderText = HeaderText;
column.DataField = DataField;
column.HtmlEncode = false;//将超链接转为Html标签
GVJF.Columns.Insert(num, column);
}
凡事预则立,不预则废。

浙公网安备 33010602011771号