我想在asp.net的文本框中上传15张图片及其名称, [英] I want to upload 15 images and their Name from textbox in asp.net,

查看:93
本文介绍了我想在asp.net的文本框中上传15张图片及其名称,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在asp.net上的文本框中上传15张图片及其名称,



图片和名称可能小于15,所以我想创建fileUpload动态控制和TextBox并在sql server 2008中存储图像路径和文本框值。

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.

推荐答案

您可以使用for循环在后端创建控件。



通常你可以在下拉列表中获得你想要的控制权,然后使用该数字你可以动态地在后端创建控件。



我附上了一个示例..你可以查看一下



.aspx页



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

<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






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..


在ASP.NET中动态创建控件很难,因为你必须在页面加载之前创建它们,否则它们的视图状态将不会被恢复。如果您知道15是最大值,则添加15个控件并仅显示您想要使用的控件,这是一个更简单的任务。



将文本写入SQL Server同时琐碎而广泛记载。如果你不能做到这一点,你应该阅读一些文章并询问一个单独的SPECIFIC问题,为什么你会被困在一个简单易懂的东西上。
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.


这篇关于我想在asp.net的文本框中上传15张图片及其名称,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆