输入数字动态创制行(二)

Insus.NET有很久从前,有帮网民写过1个小例子《输入数字动态创制行http://www.cnblogs.com/insus/archive/2011/12/01/2270455.html 然则只是实现了前边①部分,未有获得与存款和储蓄入数据库作用均未有落到实处。

目前几天,连接受多少个网民的要求,需把它做成三个全体的事例。完毕从前,先对原程序修改二处地点:
图片 1

把TextBox的ID由TextBox一改为TextBoxNum。借使不改,它会潜移默化动态产的TextBox。

除此以外二个:
图片 2

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

然后你要求在数据库创设表,创制自定义种类,创造存储进度:
图片 3

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

图片 4图片 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

接下去,你能够在先后中,创立3个门类:
图片 6

后天你能够写“上传图片”铵钮的轩然大波了:
图片 7

下边截图可复制代码:

图片 8图片 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

终极做三个动画片演示:

 图片 10

 

相关文章