Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic file input 1

Status
Not open for further replies.

sroberts82

Programmer
Oct 11, 2005
36
US
Hi,
I have a page which may have to upload any number of files, call the number x. The way I am doing it is I have an asp:table on the page and I cycle through a for loop (0 to x), each time adding a row and cell which contains an asp:htmlinputfile control. Each time I give it an id of file1, file2, file3 etc. My question is, how do I refer to these controls on the server side. I know what x is, but what is the synatx for returning each of the files, or am I going about this the wrong way? Thank you in advance,
Stephen
 
Hi Jim,
I used the following

//Datareader contains the database output
while (dataReader.Read())
{

fileNumber++;

String fileExt = (String)dataReader.GetSqlString(0);

String fileDesc = (String)dataReader.GetSqlString(2);

TableRow row = new TableRow();
TableCell cell = new TableCell();
TableCell cell2 = new TableCell();

Label textLabel = new Label();
textLabel.Text = fileDesc+" ("+fileExt+")";

cell.Attributes["width"] = "300";
HtmlInputFile inputFile = new HtmlInputFile();
String style = "font-size:8pt;border:1px solid #666666;width:200px;";

//**********************************
//This is where i specify the variable name ID

inputFile.ID = "file"+fileNumber;
inputFile.Attributes["style"] = style;

cell.Controls.Add(textLabel);
cell2.Controls.Add(inputFile);
row.Controls.Add(cell);
row.Controls.Add(cell2);
contentTable.Controls.Add(row);

}
 
You won't be able to refence the contorls by the ID you specify because they are generated dynamically. I am not sure what you are tying to do, but you can try to get the rowID of the row clicked and find the control:
(Sorry this is VB code, but you can convert it easily to C#)
Code:
''After you get the row clicked
Dim MyInputFile As New HtmlInputFile
MyInputFile = Me.FindControl("<name of control you created>")

Wish I could be more help..
Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top