You can create a list view to display the names and buttons.
Using a linq query you can name then according to the ID and display the user's name in text
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
AddControls();
}
protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
if (ViewState["controsladded"] == null)
AddControls();
}
private void AddControls()
{
int count = 0;
for(i = 0; i < LinqQuery(true).count; i ++)
{
TextBox dynamictextbox = new TextBox();
dynamictextbox.Text = LinqQuery(true)[i].name);
dynamictextbox.ID = string.Format("txtPerson{0}"LinqQuery(true)[i].ID);
Button dynamicbutton = new Button();
dynamicbutton.Click += new System.EventHandler(string.Format("dynamicbutton{0}_Click", LinqQuery(true)[i].ID);
dynamicbutton.Text = "Dynamic Button";
Panel1.Controls.Add(dynamictextbox);
Panel1.Controls.Add(new LiteralControl("<br>"));
Panel1.Controls.Add(new LiteralControl("<br>"));
Panel1.Controls.Add(dynamicbutton);
}
ViewState["controlsadded"] = true;
}
private void dynamicbutton_Click(Object sender, System.EventArgs e)
{
for(i = 0; i < LinqQuery(true).count; i ++)
{
TextBox tb = new TextBox();
tb = (TextBox) (Panel1.FindControl(string.Format("txtPerson{0}"LinqQuery(true)[i].ID)));
Label1.Text = tb.Text;
{
}
private void LinqQuery (bool active)
{
if (active)
var queryAllCustomers = from tbl in emp_details
select tbl
where tbl.active = 'yes';
return queryAllCustomers;
}
</br></br>
Now for the coding part I might suggest looking at
this[
+] and deciding upon how to alter the above code to get the correct results. Hope this helps :-)