- Add a GridView to your aspx page.
- Populate with data using any datasource control (ObjectDataSource, SQLDataSource, etc.)
Then, your ccode may looks like:
< asp:GridView ID="departmentGridView" Runat="server" DataSourceID="DepartmentObjectDataSource" DataKeyNames="DeptID" AutoGenerateColumns="False" cellpadding="5" OnSelectedIndexChanged="departmentGridView_SelectedIndexChanged" >
.......
.......
.......
</asp:GridView>
protected void departmentGridView_SelectedIndexChanged(object sender, EventArgs e)
{
if (departmentGridView.SelectedRow != null)
{
Table table = new Table();
if (table != null)
addNewRow(table, departmentGridView.SelectedIndex)
}
}
private void addNewRow(Table table, int SelectedIndex)
{
GridViewRow GridRow = new GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal);
Row.Cells.Add(generateColumns());
table.Rows.AddAt(SelectedIndex+ 2, GridRow);
}
private TableCell generateColumns()
{
TableCell Cell1= new TableCell();
Cell1.ColumnSpan = departmentGridView.Columns.Count;
Cell1.style["width"] = "100%";
/* Here you can create any control and add that control to this Cell */
Button btn = new Button();
btn.Text = "Click Me";
Cell1.Controls.Add(btn);
return Cell1;
}
1 comment:
Great man, Thanks I'm looking for this for a long time.
Post a Comment