Insus.NET有很久从前,有帮网络好友写过三个小例子《输入数字动态创设行http://www.cnblogs.com/insus/archive/2011/12/01/2270455.html 但是只是完毕了眼下一部分,未有博得与储存入数据库功效均未有兑现。

目明日,连接受多少个网上朋友的渴求,需把它做成三个壹体化的例证。完成此前,先对原程序修改贰处地方:
2018正版葡京赌侠诗 1

把TextBox的ID由TextBox一改为Text博克斯Num。假设不改,它会影响动态产的TextBox。

其它一个:
2018正版葡京赌侠诗 2

把原先click的事件代码,写成三个私人住房方法,然后分别在page_load和click事件中利用。

下一场您须要在数据库创设表,创设自定义连串,创制存款和储蓄进程:
2018正版葡京赌侠诗 3

 上边SQL语句可从上边拷贝:

2018正版葡京赌侠诗 42018正版葡京赌侠诗 5

CREATE TABLE [dbo].[TData]
(
    [TData_nbr] INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
    [ImgSource] NVARCHAR(30) NULL,
    [Title] NVARCHAR(50) NULL,
    [Description] NVARCHAR(100) NULL,
    [Album] NVARCHAR(20) NULL
)
GO

CREATE TYPE [dbo].[udt_TData] AS TABLE(
    [ImgSource] NVARCHAR(30) NULL,
    [Title] NVARCHAR(50) NULL,
    [Description] NVARCHAR(100) NULL,
    [Album] NVARCHAR(20) NULL
)
GO


CREATE PROCEDURE [dbo].[usp_TData_Insert]
(
    @TData [dbo].[udt_TData] READONLY
)
AS
INSERT INTO [dbo].[TData] ([ImgSource],[Title],[Description],[Album]) SELECT [ImgSource],[Title],[Description],[Album]
FROM @TData
GO

View Code

接下去,你能够在先后中,创设叁个门类:
2018正版葡京赌侠诗 6

今天你能够写“上传图片”铵钮的风浪了:
2018正版葡京赌侠诗 7

地点截图可复制代码:

2018正版葡京赌侠诗 82018正版葡京赌侠诗 9

DataTable td = new DataTable();

        td.Columns.Add("ImgSource", typeof(string));
        td.Columns.Add("Title", typeof(string));
        td.Columns.Add("Description", typeof(string));
        td.Columns.Add("Album", typeof(string));

        int rowIndex = 0;
        for (int idx = 0; idx < TableUploadlayout.Rows.Count; idx++)  // (TableRow tr in TableUploadlayout.Rows)
        {
            if (idx != rowIndex) //略过表格头行。
            {
                string imgSource = string.Empty;
                string title = string.Empty;
                string desc = string.Empty;
                string album = string.Empty;

                foreach (TableCell tc in TableUploadlayout.Rows[idx].Cells)
                {
                    foreach (Control ctl in tc.Controls)
                    {
                        if (ctl is FileUpload)
                        {
                            FileUpload fud = (FileUpload)ctl;
                            string uploadfile = fud.PostedFile.FileName;
                            //处理图片存储...
                            imgSource = uploadfile.Substring(uploadfile.LastIndexOf(@"\") + 1);
                        }

                        if (ctl is TextBox)
                        {
                            TextBox tb = (TextBox)ctl;
                            int id = Convert.ToInt32(tb.ID.Substring(7));

                            if (id % 2 == 1)  //第一个文本框
                                title = tb.Text;

                            if (id % 2 == 0) //第二个文本框
                                desc = tb.Text;
                        }

                        if (ctl is DropDownList)
                        {
                            DropDownList ddl = (DropDownList)ctl;
                            album = ddl.SelectedValue;
                        }
                    }
                }

                td.Rows.Add(imgSource, title, desc, album);
            }
        }

        TData tData = new TData();
        tData.TD = td;
        tData.AddRecord();

View Code

终极做一个动画演示:

 2018正版葡京赌侠诗 10

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图