Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Finding a dynamically created control in a web part

  Asked By: Jay    Date: May 02    Category: Sharepoint    Views: 1767

I am creating dropdownlists in a webpart dynamically using the following code:
DropDownList ddl = new DropDownList();
ddCount = ddCount + 1;
ddl.ID = "DropDownListID" + (ddCount).ToString();
ddl.DataValueField = finallocation;
_myFileCount.Text = fileCount.ToString();
for (int j=1;j<=fileCount;j++)
{
ddl.Items.Add(j.ToString());
}
this.Controls.Add(ddl);
I am trying to find these dropdownlists at a later time when a click a button
in the web part
using the following code:
for(int i = 1; i<=n; i++)
{
string DropDownListName = "DropDownListID" + (i).ToString();

DropDownList ddl = this.FindControl(DropDownListName) as DropDownList;
this.Controls.Add(new LiteralControl(ddl.SelectedValue));

int indexValue;
indexValue = Convert.ToInt32(ddla.SelectedValue);
strFiles[arrCount] = ddla.DataValueField;
arrCount = arrCount + 1;
}
But i am not able to find the dropdowslists

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Finding a dynamically created control in a web part Or get search suggestion and latest updates.




Tagged: