文本框不会填充 [英] Textbox will not populate
本文介绍了文本框不会填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含Label和两个文本框的Web表单。其中一个文本框可以输入名称并按Enter键,Label将填充数据库中的数据,但文本框不会。我试图让文本框填充Label填充的相同数据。我怎样才能做到这一点?我做错了什么?
< html xmlns = http://www.w3.org/1999/xhtml >
< head < span class =code-attribute> id = Head1 runat = 服务器 >
< title > < /标题 >
< style type = text / css >
# form1
{
text-align : 正确;
}
。 style1
{
宽度 : 98%;
}
。 style3
{
width : 1096px;
text-align : left;
}
。 style5
{
width : 585px;
height : 137px;
}
。 style6
{
width : 100%;
}
。 style7
{
width : 68px;
}
。 style8
{
font-weight : < span class =code-keyword> bold;
}
< / style >
< / head >
< body background = Images / bkg-blu.jpg >
< 表格 id = form1 runat = server >
< div style = font-size:x-large; font-weight:700; text-align:center >
< table class = style1 >
< tr >
< td 类 = style3 > ;
< table class = style1 >
< tr >
< td style = text-align:justify >
< img class = 青青草地跨度> src = Images / buildout_header.jpg / > < / td >
< / tr >
< / table >
< / td < span class =code-keyword>>
< / tr >
< / table >
< / div >
< p >
< / p > ;
< table class = style6 >
< tr >
< td class = style7 style = text-align:left >
< asp:Label ID = Label1 runat = server CssClass = style8 文字 = INSTID > < / asp:标签 >
< / td < span class =code-keyword>>
< td style = text-align:left >
< asp:标签 ID = Label2 runat = server CssClass = < span class =code-keyword> style8 文本 = 机构 > < / asp:标签 >
< / td >
< td 样式 = text-ali gn:left >
< / td >
< / tr >
< tr >
< < span class =code-leadattribute> td class = style7 style = text-align:left >
< asp:标签 ID = lblINST_ID runat = server 样式 = font-weight:700 > < / asp:标签 >
< / td < span class =code-keyword>>
< td style = text-align:left >
< span class =code-keyword>< asp:TextBox ID = TextBoxLongName runat = server
< span class =code-attribute> ontextchanged = TextBoxLongName_TextChanged 宽度 = 415px > < / asp:TextBox >
< / td >
< td 样式 = text-align:left >
< asp:TextBox ID = TextBoxINST_ID runat = server > < ; / asp:TextBox >
< / td >
< / tr < span class =code-keyword>>
< / table >
< br / >
< p >
< / p >
< / form >
< / body >
< / html >
使用系统;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Data;
使用 System.Drawing;
使用 System.Text;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Data.SqlClient;
使用 System.Configuration;
使用 System.Drawing.Printing;
使用 System.IO;
使用 CrystalDecisions.CrystalReports.Engine;
使用 CrystalDecisions.Shared;
命名空间 SACSCOCLogin1._1
{
public partial class BranchOffsiteCamp:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgs e)
{
}
protected void TextBoxLongName_TextChanged( object sender,EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings [ HotConnectionString]。ConnectionString);
con.Open();
SqlCommand scmd = new SqlCommand( 从Table23中选择INST_ID,LongName,其中LongName =' + TextBoxLongName.Text + ',con);
SqlDataReader dr = scmd.ExecuteReader();
if (dr.Read())
{
lblINST_ID.Text = dr [< span class =code-string> INST_ID]。ToString();
TextBoxINST_ID.Text = dr [ INST_ID]。ToString();
}
dr.Close();
con.Close();
}
}
}
解决方案
当我按原样运行代码时,标签都没有只要文本在TextBoxLongName中更改,文本框就会更新。
但是如果我把AutoPostBack =True
作为TextBoxLongName的属性,那么两者都可以工作。
I have a web form that has a Label and two textboxes. One of the textboxes you can enter a name and press enter and the Label will populate with the data from the database but the textbox will not. I am trying to get the textbox to populate with the same data that the Label populates. How can I do that? What did I do wrong?
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
#form1
{
text-align: right;
}
.style1
{
width: 98%;
}
.style3
{
width: 1096px;
text-align: left;
}
.style5
{
width: 585px;
height: 137px;
}
.style6
{
width: 100%;
}
.style7
{
width: 68px;
}
.style8
{
font-weight: bold;
}
</style>
</head>
<body background="Images/bkg-blu.jpg">
<form id="form1" runat="server">
<div style="font-size: x-large; font-weight: 700; text-align: center">
<table class="style1">
<tr>
<td class="style3">
<table class="style1">
<tr>
<td style="text-align: justify">
<img class="style5" src="Images/buildout_header.jpg" /></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<p>
</p>
<table class="style6">
<tr>
<td class="style7" style="text-align: left">
<asp:Label ID="Label1" runat="server" CssClass="style8" Text="INSTID"></asp:Label>
</td>
<td style="text-align: left">
<asp:Label ID="Label2" runat="server" CssClass="style8" Text="INSTITUTION"></asp:Label>
</td>
<td style="text-align: left">
</td>
</tr>
<tr>
<td class="style7" style="text-align: left">
<asp:Label ID="lblINST_ID" runat="server" style="font-weight: 700"></asp:Label>
</td>
<td style="text-align: left">
<asp:TextBox ID="TextBoxLongName" runat="server"
ontextchanged="TextBoxLongName_TextChanged" Width="415px"></asp:TextBox>
</td>
<td style="text-align: left">
<asp:TextBox ID="TextBoxINST_ID" runat="server"></asp:TextBox>
</td>
</tr>
</table>
<br />
<p>
</p>
</form>
</body>
</html>
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing.Printing;
using System.IO;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace SACSCOCLogin1._1
{
public partial class BranchOffsiteCamp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TextBoxLongName_TextChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con.Open();
SqlCommand scmd = new SqlCommand("Select INST_ID, LongName from Table23 where LongName = '" + TextBoxLongName.Text + "'", con);
SqlDataReader dr = scmd.ExecuteReader();
if (dr.Read())
{
lblINST_ID.Text = dr["INST_ID"].ToString();
TextBoxINST_ID.Text = dr["INST_ID"].ToString();
}
dr.Close();
con.Close();
}
}
}
解决方案
When I run you code as is then neither the label nor the textbox are updated as soon as the text changes in TextBoxLongName.
However if I putAutoPostBack="True"
as an attribute of TextBoxLongName then both work.
这篇关于文本框不会填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文