控件以填充数据并执行回发 [英] control to fill the data and perform postback

查看:56
本文介绍了控件以填充数据并执行回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


是否有任何控件可以填充数据库中的数据并执行回发操作.
我想从数据库中填充一个字段,然后选择应在文本框中显示所选字段.


Is there any control to fill the data from database and perform postback operation.
I want to fill a field from my database and after selecting that the selected field should be displayed in the textbox.

推荐答案



您可以使用基本的asp.net控件中的任何数据控件

您可以在工具箱中看到数据控件的列表,例如..datalist,reapeter,gridview ...


并编写代码以在selectedindexchanged事件中显示数据


http://msdn.microsoft.com/en-us/library/cc295567.aspx

在上面的链接中,您可以查看有关数据控件的详细信息

Hi,

you can use any data control from basic asp.net controls

you can see list of data controls in toolbox like..datalist,reapeter,gridview...


And write code to display data in selectedindexchanged event


http://msdn.microsoft.com/en-us/library/cc295567.aspx

In the above link you can see details about data controls

<form id="form1" runat="server">
<div>
<br />
    <asp:TextBox ID="TextBox1" runat="server"><br />
    <asp:DataList ID="DataList1" runat="server" onitemcommand="DataList1_ItemCommand" Width ="60%"
       >
     <HeaderTemplate >
       <table width="100%" align="center">
         <tr>
           <td>List of Items</td>
         </tr>

     </HeaderTemplate>
     <itemtemplate>
          <tr>
           <td>
               <asp:LinkButton ID="LinkButton1" runat="server" CommandName ="show" CommandArgument ="3"> <asp:Label ID="Label1" runat="server" Text=' <%#Container.DataItem %>'>

           </td>
         </tr>
     </itemtemplate>
     <footertemplate>
         </footertemplate></table>



</div>
</form>



文件后面的代码包含以下代码



And code behind file contains following code

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

   
            List<string> str = new List<string>();
            str.Add("frstitem");
            str.Add("secnditem");
            str.Add("ghgfh");
            str.Add("frstitem");
            str.Add("secnditem");
            str.Add("ghgfh");
            str.Add("frstitem");
            str.Add("secnditem");
            str.Add("ghgfh");

            DataList1.DataSource = str;
            DataList1.DataBind();
         

        }
    }

    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "show")
        {
            Label lbl = (Label)e.Item.FindControl("Label1");
            TextBox1.Text = lbl.Text;
        }
    }
</string></string>



在上面的示例中,我们可以按照较旧的方法将数据库设置为数据列表


最好的



In the above example we can set database to datalist as per older method


All the Best


这篇关于控件以填充数据并执行回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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