我有这段代码,我想问一下如何将查询结果显示到名为“Textbox1”的文本框中
<%@ page language="C#" autoeventwireup="true" codeBehind="Default.aspx.cs" inherits="MainPage, App_Web_rlctbjj5" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
string connect = ConfigurationManager.ConnectionStrings["TDBSConnectionString"].ConnectionString;
string query = "SELECT news, news_date FROM [IBSI].[dbo].[ibsi.news]";
if (query != null)
{
using (SqlConnection conn = new SqlConnection(connect))
{
using (SqlCommand cmd = new SqlCommand(query, conn))
{
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
if (rdr.HasRows)
{
while (rdr.Read())
{
Response.Write("<p>");
Response.Write("<strong>" + rdr["news"].ToString() + "</strong><br />");
Response.Write(rdr["news_date"].ToString() + "</p>");
}
}
}
}
}
else
{
Response.Write("<p>No customer selected</p>");
}
Response.End();
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>iBSI SLA Manager</title>
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<meta name="keywords" content="iBSI SLA Manager" />
<meta name="description" content="SLA Manager" />
<meta name="author" content="iBSI" />
<meta name="copyright" content="Copyright 2010-2011 by Wenchester M. Visitacion" />
<meta name="company" content="iBSI SLA Manager" />
<%-- <link rel="shortcut icon" href="../styles/images/favicon.ico" />--%>
<link rel="icon" type="image/jpg" href="Styles/images/IBSI_LOGO.png" />
<link rel="Stylesheet" href="Styles/CoreStyle.css?version=1.0.1" type="text/css"
media="all" />
<link rel="Stylesheet" href="dojox/layout/resources/FloatingPane.css" type="text/css" />
<link rel="Stylesheet" href="dojox/layout/resources/ExpandoPane.css" type="text/css" />
<link rel="Stylesheet" href="dojox/widget/Toaster/Toaster.css" type="text/css" />
<link rel="Stylesheet" href="dojo/resources/dojo.css" type="text/css" />
<link rel="Stylesheet" href="dijit/themes/claro/claro.css" type="text/css" />
<link rel="Stylesheet" href="dojox/resources/Grid.css" type="text/css" />
<link rel="Stylesheet" href="dojox/resources/claroGrid.css" type="text/css" />
<link rel="Stylesheet" href="dojox/form/resources/CheckedMultiSelect.css" type="text/css" />
<link rel="Stylesheet" href="dojox/form/resources/FileInput.css" type="text/css" />
<link rel="Stylesheet" href="dojox/grid/enhanced/resources/claroEnhancedGrid.css"
type="text/css" />
<link rel="stylesheet" type="text/css" href="Scripts/style.css" media="all" />
<script type="text/javascript" src="Scripts/jquery.js"></script>
<script type="text/javascript" src="Scripts/jquery.cycle.all.min.js"></script>
<script type="text/javascript" src="Scripts/carosel.js"></script>
<script>
$(function() {
$(".newsticker-jcarousellite").jCarouselLite({
vertical: true,
hoverPause:true,
visible: 3,
auto:500,
speed:3000
});
});
</script>
<script type="text/javascript" src="dojo/dojo.js" djconfig="parseOnLoad: true "></script>
<script type="text/javascript">
dojo.require("dojo.CheckboxTree");
dojo.require("dojo.CheckboxForestStoreModel");
</script>
<script type="text/javascript" src="Scripts/CoreScript.min.js?version=1.0.1"></script>
<script type="text/javascript" src="Scripts/Dashboard.min.js?version=1.0.1"></script>
<script type="text/javascript" src="Scripts/Node.min.js?version=1.0.1"></script>
<script type="text/javascript" src="Scripts/Menu.min.js?version=1.0.1"></script>
<script type="text/javascript" src="Scripts/Role.min.js?version=1.0.1"></script>
<script type="text/javascript" src="Scripts/RoleMembers.min.js?version=1.0.1"></script>
<script type="text/javascript" src="Scripts/AccessRights.min.js?version=1.0.1"> </script>
<script type="text/javascript" src="Scripts/User.js?version=1.0.1"></script>
<script type="text/javascript" src="Scripts/Company.min.js?version=1.0.1"></script>
<script type="text/javascript" src="Scripts/Customer.min.js?version=1.0.1"></script>
<script type="text/javascript" src="Scripts/TransactionType.min.js?version=1.0.1"></script>
<script type="text/javascript" src="Scripts/Transaction.min.js?version=1.0.5"></script>
<script type="text/javascript" src="Scripts/WorkFlowIn.min.js?version=1.0.1"></script>
<script type="text/javascript" src="Scripts/WorkFlowOut.min.js?version=1.0.2"></script>
<script type="text/javascript" src="Scripts/DocumentControl.min.js?version=1.0.5"></script>
<script type="text/javascript" src="Scripts/Periodic.min.js?version=1.0.2"></script>
<script type="text/javascript" src="Scripts/PeriodicInstruction.min.js?version=1.0.2"></script>
<script type="text/javascript" src="Scripts/CustomerTransaction.min.js?version=1.0.2"></script>
<script type="text/javascript" src="Scripts/CustomerConcern.min.js?version=1.0.2"></script>
<script type="text/javascript" src="Scripts/TransactionInquiry.min.js?version=1.0.2"></script>
<script type="text/javascript" src="Scripts/CustomerConcernInquiry.min.js?version=1.0.2"></script>
<script type="text/javascript" src="Scripts/PeriodicInstructionInquiry.min.js?version=1.0.2"></script>
</head>
<body class="claro" style="background-color: #000000;">
<div dojotype="dojox.widget.Toaster" id="ToasterMessage" positiondirection="br-left"
duration="500" messagetopic="ToasterMessage">
</div>
<div id="bc" style="width: 100%; height: 100%; padding: 0px 5px 5px 5px;" dojotype="dijit.layout.BorderContainer">
<div id="header" dojotype="dijit.layout.ContentPane" region="top" style="background-color: Transparent;
height: 60px; border: 0px; overflow: hidden;">
<div id="divLoginInfo" class="LoginInfo">
<div>
<span id="spanUsername">Hi User!</span> <span id="spanChangePassword" class="LinkDrill">
[Change Password]</span> <span id="spanSignout" class="LinkDrill">[Signout]</span></div>
<div style="margin-top: 10px;">
<div style="text-align: right;">
<span id="spanDate"></span>
</div>
<div style="text-align: right;">
<span id="spanTime"></span>
</div>
</div>
</div>
<img src="Styles/images/sparkbanner.jpg" style="height: 100px; width: auto;" />
</div>
<div jsid="MainLeft" id="MainLeft" dojotype="dojox.layout.ExpandoPane" splitter="true"
duration="275" region="left" title="Menu" previewondblclick="true" maxwidth="230"
style="background-color: Transparent; width: 210px;" easein="dojo.fx.easing.backOut"
easeout="dojo.fx.easing.backInOut">
<div dojotype="dijit.layout.TabContainer" id="TabContainerMain" jsid="TabContainerMain"
region="center" attachparent="true" tabposition="bottom" tabstrip="true" style="background-color: Transparent;
border: 0px;">
<div id="ContentPaneMain_Login" jsid="ContentPaneMain_Login" dojotype="dijit.layout.ContentPane"
style="background-color: Transparent;">
<div style="padding-top: 50px; margin-left: 10px; background-color: Transparent;">
<div>
UserName:
<input jsid="TextBoxUserName" id="TextBoxUserName" dojotype="dijit.form.TextBox"
type="text" style="width: 90%;" selectonclick="true" />
</div>
<div>
Password:
<input jsid="TextBoxPassword" id="TextBoxPassword" dojotype="dijit.form.TextBox"
type="password" style="width: 90%;" selectonclick="true" />
</div>
<div>
<button jsid="ButtonLogin" id="ButtonLogin" dojotype="dijit.form.Button" style="float: right;
padding: 5px 15px 0px 0px;">
Login</button>
</div>
<br />
<br />
<span id="spanMessage"></span>
</div>
</div>
</div>
</div>
<div id="MainRight" jsid="MainRight" dojotype="dijit.layout.ContentPane" splitter="true"
region="center" style="background-color: transparent; padding: 0px; border: 0px;">
<div dojotype="dijit.layout.TabContainer" region="left" id="TCCenterPane" tabstrip="true"
style="margin-top: -4px; border: 0px;">
<div dojotype="dijit.layout.ContentPane" title="Home" selected="true" style="padding: 0px;
background-color: #000000;">
<form id="form1" runat="server">
<div style="position:absolute;z-index:200; left:52.5%;top:9%;">
<asp:TextBox ID="TextBox1" runat="server" Height="168px" TextMode="MultiLine"
Width="303px"></asp:TextBox>
<div class="news">
<div class="newsticker-jcarousellite" style="position:absolute;z-index:200; left:52.5%;top:9%;">
</div></div></div>
<div style="position:absolute;z-index:200; left:52.5%;top:52%;">
<asp:TextBox ID="TextBox2" runat="server" Height="168px" TextMode="MultiLine"
Width="303px"></asp:TextBox>
</div>
</form >
<div style="width: 100%; height: 90%; background: #000000 url(Styles/images/IBSI_LOGO1.png) no-repeat center;">
</div>
</div>
</div>
</div>
</div>
<div jsid="DialogAlertMessage" id="DialogAlertMessage" dojotype="dijit.Dialog" title="Alert Box"
style="padding: 0px 0px 0px 0px;">
<div style="width: 300px; min-height: 50px;">
<span id="spanAlertMessage">Empty Alert Message</span>
<br />
<div style="float: right;">
<button id="ButtonOKAlertMessage" jsid="ButtonOKAlertMessage" dojotype="dijit.form.Button">
OK</button></div>
</div>
</div>
<div jsid="DialogConfirmMessage" id="DialogConfirmMessage" dojotype="dijit.Dialog"
title="Confirmation" title="Alert Box" style="padding: 0px 0px 0px 0px;">
<div style="width: 300px">
<span id="spanConfirmMessage">Empty Alert Message</span>
<br />
<div style="float: right">
<button id="ButtonConfirmMessageYES" jsid="ButtonConfirmMessageYES" dojotype="dijit.form.Button">
YES</button>
<button id="ButtonConfirmMessageNO" jsid="ButtonConfirmMessageNO" dojotype="dijit.form.Button">
NO</button>
</div>
<br />
</div>
</div>
<div jsid="DialogReportPreview" id="DialogReportPreview" dojotype="dijit.Dialog"
aria-describedby="intro" title="Required" autofocus="true">
<iframe id="iframeReportPreview" onload="StandbyPreview.hide()" frameborder="0" style="width: 900px;
height: 500px;"></iframe>
</div>
<div jsid="StandbyPreview" id="StandbyPreview" dojotype="dojox.widget.Standby" color="#E4F4FC"
target="TabContainerMain" zindex="9000" slidefrom="bottom" image="Styles/Images/Progress/loadingSmall.gif">
</div>
<div jsid="DialogChangePassword" id="DialogChangePassword" dojotype="dijit.Dialog"
aria-describedby="intro" title="Change Password" autofocus="false">
<div style="height: 200px; width: 520px;">
<div style="width: 150px; padding: 15px 0px 10px 20px; height: 180px; float: left;">
<div style="height: 165px; width: 140px; border: 1px solid gray; padding: 3px 3px 3px 3px;">
To ensure system security, do not use familiar words for password initials, favorite
expressions and names of love ones or popular persons. We suggest to change passwords
regularly or once a month.</div>
</div>
<div style="width: 100px; padding: 50px 0px 10px 10px; float: left; font-family: 'Segoe UI';">
<div style="height: 18px; padding-top: 3px;">
User Name:</div>
<div style="height: 18px; padding-top: 3px;">
Old Password:</div>
<div style="height: 18px; padding-top: 3px;">
New Password:</div>
<div style="height: 18px; padding-top: 3px;">
Confirm Password:</div>
</div>
<div style="width: 200px; padding: 50px 0px 10px 10px; float: left;">
<div style="height: 18px; padding-top: 3px;">
<input jsid="TextBoxCurrentUserName" id="TextBoxCurrentUserName" dojotype="dijit.form.TextBox"
type="text" style="width: 100%;" selectonclick="true" readonly="true" /></div>
<div style="height: 18px; padding-top: 3px;">
<input jsid="TextBoxOldPassword" id="TextBoxOldPassword" dojotype="dijit.form.TextBox"
type="password" style="width: 100%;" selectonclick="true" /></div>
<div style="height: 18px; padding-top: 3px;">
<input jsid="TextBoxNewPassword" id="TextBoxNewPassword" dojotype="dijit.form.TextBox"
type="password" style="width: 100%;" selectonclick="true" /></div>
<div style="height: 18px; padding-top: 3px;">
<input jsid="TextBoxConfirmPassword" id="TextBoxConfirmPassword" dojotype="dijit.form.TextBox"
type="password" style="width: 100%;" selectonclick="true" /></div>
</div>
<div style="float: right; padding-right: 25px;">
<button jsid="ButtonChangePassword" id="ButtonChangePassword" dojotype="dijit.form.Button">
Proceed</button>
</div>
</div>
</div>
我用它来在屏幕上显示检索数据的值。
Response.Write("<p>");
Response.Write("<strong>" + rdr["news"].ToString() + "</strong><br />");
Response.Write(rdr["news_date"].ToString() + "</p>");
答案 0 :(得分:1)
通常你会写这样的东西:
TextBox1.Text = rdr["news"].ToString();
但是,您的查询可能会返回超过1行(并且超过1列)。 TextBox只能容纳1个值,所以如果你这样做,你只会看到最后一行的内容。
在你的情况下,最好使用一个可以显示多行值的控件,例如GridView,ListView,Repeater或者DataList
答案 1 :(得分:0)
它使用的是dojo框架。因此,请尝试在此处使用控件:http://dojotoolkit.org/。 对于dojo文本框,设置值为dijit.byId('TextBox1')。set('value','sampleValue'); 我从头开始创建该项目。但我想你是继续它的人。祝好运。 :)