Click here to Skip to main content
15,917,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want to upload 15 images and their Name from textbox in asp.net,

Images and Name are may be less than 15 so I want to create fileUpload control and TextBox dynamically and store Image path and textbox value in sql server 2008.
Posted
Comments
JoCodes 19-Dec-13 1:35am    
What you tried so far?
Nelek 22-Dec-13 18:53pm    
Perfect, go ahead.

Since you didn't ask any question, it is difficult to give you a better answer.

I strongly recommend you to read:
How to ask a question[^] and What have you tried?[^]

You can use for loop to create controls in the back end.

Usually you can get the no of controls you want in dropdownlist and then with that number you can create controls in the backend dynamically.

I have attached a sample example .. You can check that out

.aspx page

XML
<body>
    <form id="form1" runat="server">
    <asp:Panel ID="Panel1" runat="server">
    </asp:Panel>
    <div>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    <asp:Button ID="Button1" runat="server"
        Text="Button" OnClick="Btn_Click" />

    </form>
</body>



c# code

protected void Page_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 5; i++)
            {
                Panel panel = new Panel();
                TextBox txt = new TextBox();
                txt.ID = "Textbx" + i;
                panel.Controls.Add(txt);
                Panel1.Controls.Add(panel);
            }
        }

        protected void Btn_Click(object sender, EventArgs e)
        {
            Label1.Text = "";
            for (int i = 0; i < 5; i++)
            {
                TextBox txt=(TextBox)Page.FindControl("Textbx"+i);
                Label1.Text =Label1.Text+ txt.Text + "<br />";
                
            }
        }


Over here since you need only the image path you dont have to upload it. You can get the filename.

I hope this is what your query is..
 
Share this answer
 
Creating controls dynamically in ASP.NET is hard because you have to create them before page load, or their viewstate will not be restored. If you know 15 is your maximum, adding 15 controls and only showing the ones you want to use, is a much simpler task.

Writing text to SQL Server is both trivial and widely documented. If you can't do that part, you should read some articles and ask a seperate SPECIFIC question about why you're stuck on something that is straightforward and easy to find information on.
 
Share this answer
 

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