Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Dec 25, 2014, 8:53 PM EST
Hi akash singh,
Use likes this in button click
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < ListBox2.GetSelectedIndices().Count();i++ )
{
if ((TextBox)Panle1.FindControl("txt"+ListBox2.SelectedIndex) != null)
{
TextBox txt = (TextBox)Panle1.FindControl("txt" + ListBox2.SelectedIndex);
Response.Write("TextBox ID = " + txt.ID + "
");
Response.Write("TextBox Text = " + txt.Text + "
");
}
else
Response.Write("Nothing is there");
}
And create a method
void AddControl()
{
if (ListBox2.SelectedIndex != -1)
{
Table tbl = new Table();
tbl.ID = "Tabl";
tbl.EnableViewState = true;
tbl.ViewStateMode = ViewStateMode.Enabled;
// tbl.Attributes.Add("runat", "server");
for (int i = 0; i < ListBox2.Items.Count; i++)
{
//TableRow tr = new TableRow();
if (ListBox2.Items[i].Selected)
{
//++ind;
TableRow tr = new TableRow();
tr.EnableViewState = true;
tr.ViewStateMode = ViewStateMode.Enabled;
// tr.Attributes.Add("runat", "server");
TableCell col = new TableCell();
col.EnableViewState = true;
col.ViewStateMode = ViewStateMode.Enabled;
// col.Attributes.Add("runat", "server");
col.Width = 100;
Label Lbl = new Label();
Lbl.Text = ListBox2.Items[i].Text;
Lbl.ID = "lbl" + i.ToString();
Lbl.ForeColor = System.Drawing.Color.Red;
col.Controls.Add(Lbl);
// arr[ind] = Lbl.Text;
TableCell col1 = new TableCell();
TextBox txt = new TextBox();
txt.ID = "txt" + i.ToString();
txt.EnableViewState = true;
txt.ViewStateMode = ViewStateMode.Enabled;
// txt.ID = ListBox2.Items[i].Text;
txt.Width = 150;
txt.Height = 20;
col1.Controls.Add(txt);
tr.Cells.Add(col);
tr.Cells.Add(col1);
//Lbl1.Text = "txt" + i.ToString();
// txt.TextChanged += new EventHandler(adddff);
// LabCHK.Text += tr.Cells[2];
// tbl.Rows.Add(tr);
tbl.Rows.Add(tr);
}
}
Panle1.Controls.Add(tbl);
}
}
and call it in page lode in place of ListBox Selected Index change
protected void Page_Load(object sender, EventArgs e)
{
AddControl();
}
akash singh119 reputationPosted Dec 25, 2014, 9:20 PM EST
akash singh119 reputationPosted Dec 25, 2014, 9:20 PM EST
akash singh119 reputationPosted Dec 26, 2014, 12:47 AM EST
akash singh119 reputationPosted Dec 26, 2014, 12:47 AM EST
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Dec 26, 2014, 2:46 AM EST
lbl.Text+= txt.ID
akash singh119 reputationPosted Dec 26, 2014, 7:42 PM EST
akash singh119 reputationPosted Dec 26, 2014, 7:43 PM EST