public void createBoundCols()
{
DataTable dt = ds.Tables[0];
int countDt = 0;
foreach (DataColumn col in dt.Columns)
{
if (countDt < 12)
{
BoundField bfield = new BoundField();
bfield.DataField = col.ColumnName;
bfield.HeaderText = col.ColumnName;
GrdDynamic.Columns.Add(bfield);
countDt = countDt + 1;
}
}
CommandField cf = new CommandField();
cf.HeaderText = "print";
cf.ShowSelectButton = true;
cf.SelectText = "Print";
cf.Visible = true;
GrdDynamic.Columns.Add(cf);
}
// and on grid row command so that we can fire the event associated with the created bound column.
protected void GrdDynamic_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button clicked
// by the user from the Rows collection.
GridViewRow row = GrdDynamic.Rows[index];
int rowid = Convert.ToInt32(row.Cells[0].Text.ToString());
Response.Redirect("RecordDetails.aspx?rID=" + rowid);
}
}
No comments:
Post a Comment