如何从数据库绑定文本框中的数据. [英] how to bind data in text box from database.

查看:117
本文介绍了如何从数据库绑定文本框中的数据.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在在这个应用程序中以Jr.developer的身份从事一个MLM软件项目的工作,现在有一个管理员在那里我正在编辑该Admin的Web表单.....现在假设是否要编辑admin的数据例如地址移动电话,没有电子邮件ID电话号码........………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………….该文本框上的时间提示表示我只是想从数据库中绑定该名称..im与3层应用程序密切配合,因此应该有DAL文件BLL文件和MY项目....所以应该是

I m working on One MLM Software project as Jr.developer now in this application one administrator is there now i have working with editing the web form for that Admin..... now suppose if i want to edit data of admin like address mobile no email ID Phone NO........and one text box is there for admon name that will never change so whenever admin want to update his/her data that name should be bind on that textbox each and every time cliclk on that text box means simply i want to bind that name from database.......i m strongly working with 3 Tier application so there should be DAL file BLL FIle and MY project....so what should be the coding for that???

推荐答案

您的DAL将包含一种根据需要的id返回文本的方法,并且您将执行myTextBox.Text = DAL .GetText(id);
Your DAL would contain a method to return the text based on what ids are needed and you''d do myTextBox.Text = DAL.GetText(id);


您的问题不是很具体.虽然,据我所知,您需要编辑一个页面,在该页面中,您将编辑所有详细信息地址,移动电话,电子邮件等,而无需输入名称.

我不清楚您是说在每次点击中将数据绑定到名称是什么意思.
但是我想是您希望名称显示在文本框中,但是用户无法更改编辑文本框.

如果这是您想要的东西,我的朋友您想得太深了.

只需将数据填充到pageload事件中的所有文本框,下拉列表等中.
填充代码后,只需禁用名称文本框控件.

这是代码

aspx页面
Your question is not very specic. Though, what I have understood, you need to edit a page where you will edit all the details address, mobile, email etc but never the name.

I am not clear what you mean to say binding data to name in every click.
But what I guess is you want the name to be shown in the text box but, user cannot change edit the textbox.

If this is the thing you want, my friend you have thought too far.

Simply populate the data into all textbox, dropdown etc in pageload event.
After the populate code, just disable name textbox control.

Here is the code

aspx page
<div>
    <asp:label id="Label1" runat="server" text="Admin Name" xmlns:asp="#unknown"></asp:label>
    <asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox>
    <br />
    <asp:label id="Label2" runat="server" text="Email" xmlns:asp="#unknown"></asp:label>
    <asp:textbox id="TextBox2" runat="server" xmlns:asp="#unknown"></asp:textbox>
    <br />
    <br />
    <asp:button id="Button1" runat="server" onclick="Button1_Click" text="Edit" xmlns:asp="#unknown" />
</div>



后面的代码



code behind

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        //populate from database
        DataTable dtblClient = doPopulate();
        foreach (DataRow dr in dtblClient.Rows)
        {
            TextBox1.Text = dr["name"].ToString();
            TextBox2.Text = dr["email"].ToString();
        }

        //make the name textbox disable
        TextBox1.Enabled = false;
        dtblClient.Dispose();
    }
}
private DataTable doPopulate()
{
    //call databse to get the data as reader or datatable
    //here in the e.g, I create a custom datatable
    DataTable dtbl = new DataTable();
    dtbl.Columns.Add(new DataColumn("id", Type.GetType("System.Int32")));
    dtbl.Columns.Add(new DataColumn("name", Type.GetType("System.String")));
    dtbl.Columns.Add(new DataColumn("email", Type.GetType("System.String")));

    dtbl.Rows.Add(new object[]{1, "Sandip", "sandip@test.com"});

    return dtbl;
}



希望这会有所帮助.
欢呼



Hope this helps.
cheers


这篇关于如何从数据库绑定文本框中的数据.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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