将动态文本框数据插入数据库 [英] Inserting dynamic textbox data to database

查看:93
本文介绍了将动态文本框数据插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai,
我不知道如何在单击按钮时将动态文本框数据插入数据库,而是要获取动态文本框,onclick提交按钮,我想将数据插入数据库.请帮助我的代码.

我的.aspx页面

hai,
i am not getting how to insert dynamic text boxes data to database on a button click am getting dynamic textboxes, onclick of submit button i want to insert data into database. help me with the code please.

my .aspx page

<legend>Organisation /Company Contacts</legend>
<asp:ScriptManager ID="scrptmgr1" runat="server" />
<asp:UpdatePanel ID="updatepnl1" runat="server" UpdateMode="Conditional">
<triggers>
 <asp:AsyncPostBackTrigger ControlID="btn1" EventName="Click" />
</triggers>
<contenttemplate>
<asp:Table ID="tbl1" runat="server" Height="48px" Width="330px">
 <asp:TableRow ID="tr1" runat="server">
 <asp:TableCell ID="r1_tc1" runat="server">
<asp:Label ID="regdet_llno_lbl" runat="server">Land Line Number:


<asp:TableCell ID="r1_tc2" runat="server" RowSpan="2">
<asp:TextBox ID="regdet_llno_txt" runat="server" />
 <asp:RegularExpressionValidator ID="validator1" runat="server" ControlToValidate="regdet_llno_txt" ErrorMessage="Only numbers are allowed" ValidationExpression="^\d+$">


<asp:TableCell ID="r1_tc3" runat="server">
<asp:Button ID="btn1" runat="server" Text="add" CausesValidation="false" OnClick="btn1_Click" />
 </contenttemplate>


我的.cs页面


my .cs page

protected void btn1_Click(object sender, EventArgs e)
{
    int a = 3;
    for (; a <= 5; a++)
    {
        TextBox lndline = new TextBox();
        lndline.ID = "lndline_txt" + a;
        r1_tc2.Controls.Add(lndline);
        Literal li1 = new Literal();
        li1.Text = "";
        r1_tc2.Controls.Add(li1);
    }
    int b = 1;
    if (b==1)
    {
        btn1.Enabled = false;
    }
}

推荐答案

" < asp:TableCell ID =" runat 服务器" < asp:Button ID =" runat 服务器" 文本 添加" CausesValidation false" OnClick =" / > < /contenttemplate >
"> <asp:TableCell ID="r1_tc3" runat="server"> <asp:Button ID="btn1" runat="server" Text="add" CausesValidation="false" OnClick="btn1_Click" /> </contenttemplate>


我的.cs页面


my .cs page

protected void btn1_Click(object sender, EventArgs e)
{
    int a = 3;
    for (; a <= 5; a++)
    {
        TextBox lndline = new TextBox();
        lndline.ID = "lndline_txt" + a;
        r1_tc2.Controls.Add(lndline);
        Literal li1 = new Literal();
        li1.Text = "";
        r1_tc2.Controls.Add(li1);
    }
    int b = 1;
    if (b==1)
    {
        btn1.Enabled = false;
    }
}


您需要在Page Load事件中重新生成此框.

将Box生成代码放在一个函数中.
在按钮单击和页面加载中都调用此函数.

然后在保存方法中,您将能够获取文本框的值
动态生成.
You need to re generate this boxes in Page Load event.

Put the Box generation code in a fucntion.
call this function on the button click and in page load both.

then in save method you will be able to get the values of the text boxes
dynamically generated.


这篇关于将动态文本框数据插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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