public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Create dummy data
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("Name");
dt.Columns.Add(dc);
DataRow dr = dt.NewRow();
dr["Name"] = "Ivan";
//Uncomment the following line to have data in the grid :)
//dt.Rows.Add(dr);
//Bind the gridview
GridView1.DataSource = dt;
GridView1.DataBind();
}
//Recurses through the controls to show the naming of each individual control that is currently in the gridview
RecurseControls(GridView1.Controls[0].Controls);
Label1.Text += GridView1.Controls[0].Controls[0].GetType().Name + "<br />";
}
void RecurseControls(ControlCollection ctls)
{
foreach (Control ctl in ctls)
{
if (!ctl.HasControls())
Label1.Text += ctl.ClientID + " " + ctl.GetType().Name + "<br />";
else
RecurseControls(ctl.Controls);
}
}
protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "EmptyInsert")
{
//handle insert here
TextBox tbEmptyInsert = GridView1.Controls[0].Controls[0].FindControl("tbEmptyInsert") as TextBox;
56 Label1.Text = string.Format("You would have inserted the name : <b>{0}</b> from the emptydatatemplate",tbEmptyInsert.Text);
}
if (e.CommandName == "Insert")
{
//handle insert here
TextBox tbInsert = GridView1.FooterRow.FindControl("tbInsert") as TextBox;
Label1.Text = string.Format("You would have inserted the name : <b>{0}</b> from the footerrow", tbInsert.Text);
}
}
}