Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Good Morning.

Friends, I would like some help to create a textbox with property ID dynamic.
I need the control ID has the name rescue from database. Something like this:
XML
<asp:TextBox ID='<%# Eval("ST_DESCRICAO") %>'  runat="server" Width="100%">
</asp:TextBox>

and in codebehind:
myDataList.FindControl("nameoftext");
Is it possible? My control is on a DataList.

Thanks.
Posted
Updated 12-Sep-13 22:11pm
v3
Comments
Sergey Alexandrovich Kryukov 11-Sep-13 10:56am    
Absolutely everything in ASP.NET is created dynamically, on HTTP request. You can always generate any HTML output, say, conditionally...
—SA
Ildebrando Araújo 11-Sep-13 11:01am    
How I could do this?
Could you send me a example using DataList, please?
Sergey Alexandrovich Kryukov 11-Sep-13 11:26am    
Send?! send what?

[DataContract(Namespace = myNamespace)]
class MyList {
internal List { get { return list; } }
[DataMember]
System.Collection.Generic.List<MyListItem> = new System.Collection.Generic.List<MyListItem>()
//...
}

[DataContract(Namespace = myNamespace)]
class MyListItem { /* ... */ }


And so on...

—SA
Sunasara Imdadhusen 13-Sep-13 4:11am    
Please add your answer in solution box
Sergey Alexandrovich Kryukov 13-Sep-13 12:07pm    
Done.
—SA

You can always add it dynamically like this
C#
TextBox tb=new TextBox();
tb.ID = //get ID from database;

Hope this helps
 
Share this answer
 
C#
TextBox textbox2 = new TextBox();
textbox2.ID = "textbox2";
textbox2.Style["Position"] = "Absolute";
textbox2.Style["Top"] = "40px";
textbox2.Style["Left"] = "110px";
 
Share this answer
 
It can be something like
C#
[DataContract(Namespace = myNamespace)]
class MyList {
    internal List { get { return list; } }
    [DataMember] System.Collection.Generic.List<MyListItem> = new System.Collection.Generic.List<mylistitem>();
    //...
}

//...

[DataContract(Namespace = myNamespace)]
class MyListItem { /* ... */ }

And so on...

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900