2018正版葡京赌侠诗输入数字动态创建行(二)

Insus.NET有很久以前,有救助网友形容了一个多少例子《输入数字动态创建行》http://www.cnblogs.com/insus/archive/2011/12/01/2270455.html 不过只是实现了前有,没有到手与仓储入数据库功能都无落实。

日前几龙,连接受几只网友的求,需将她做成一个一体化的事例。实现之前,先对原来程序修改2处地方:
2018正版葡京赌侠诗 1

将TextBox
的ID由TextBox1转移吧TextBoxNum。如果无移,它见面潜移默化动态产的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

 

发表评论

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