日期:2014-05-17 浏览次数:20468 次
public void GridViewDataBind(GridView gridview, DataTable table,string ID)
{
if (table.Rows.Count == 0)
{
table = table.Clone();
table.Rows.Add(table.NewRow());
gridview.DataSource = table;
gridview.DataBind();
int columnCount = table.Columns.Count;
gridview.Rows[0].Cells.Clear();
gridview.Rows[0].Cells.Add(new TableCell());
gridview.Rows[0].Cells[0].ColumnSpan = columnCount;
gridview.Rows[0].Cells[0].Text = "No relevant records";
gridview.Rows[0].Cells[0].Style.Add("text-align", "center");
}
else
{
DataColumn[] keys = new DataColumn[1];
keys[0] = table.Columns[ID];
table.PrimaryKey = keys;
gridview.DataSource = table;
gridview.DataBind();
}
gridview.SelectedIndex = -1;
}
if (e.Row.RowType == DataControlRowType.Header)
{
// 标题的处理
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
// 行的处理
}