C# 用数据库中的数据填充文本框
我的页面上有几个文本框,希望用数据库中的数据填充它们。我做了这个查询,得到了(在我的例子中)一个胶片对象,我用它来填充文本框,但它不起作用。 这是我的密码:C# 用数据库中的数据填充文本框,c#,asp.net,textbox,C#,Asp.net,Textbox,我的页面上有几个文本框,希望用数据库中的数据填充它们。我做了这个查询,得到了(在我的例子中)一个胶片对象,我用它来填充文本框,但它不起作用。 这是我的密码: private void FilmInfo(int gekozenFilm) { BLFilm blFilm = new BLFilm(); Film film = blFilm.GetFilmById(gekozenFilm); TextBoxFilm.Text = film.Naam; TextBoxRe
private void FilmInfo(int gekozenFilm)
{
BLFilm blFilm = new BLFilm();
Film film = blFilm.GetFilmById(gekozenFilm);
TextBoxFilm.Text = film.Naam;
TextBoxRelease.Text = film.Releasedatum.ToString();
TextBoxTrailer.Text = film.Filmpje;
TextBoxAfbeelding.Text = film.Afbeelding;
}
胶片中有胶片对象,但由于某些原因,文本框不显示文本
整个页面的代码(相关):
protected void ListBoxMovies_SelectedIndexChanged(object sender, EventArgs e)
{
int gekozenFilm;
gekozenFilm = Convert.ToInt32(ListBoxMovies.SelectedItem.Value);
FilmInfo(gekozenFilm);
}
private void FilmInfo(int gekozenFilm)
{
BLFilm blFilm = new BLFilm();
Film film = blFilm.GetFilmById(gekozenFilm);
TextBoxFilm.Text = film.Naam;
TextBoxRelease.Text = film.Releasedatum.ToString();
TextBoxTrailer.Text = film.Filmpje;
TextBoxAfbeelding.Text = film.Afbeelding;
}
.aspx页面
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<section id="context">
<article id="left">
<h2>Movie CRUD</h2>
<div class="seperator">
<!-- seperator -->
<asp:Label ID="LabelNaam" runat="server" Text="Naam"></asp:Label>
<asp:TextBox ID="TextBoxFilm" runat="server" Width="250px"></asp:TextBox>
<br />
<asp:Label ID="LabelRelease" runat="server" Text="Releasedatum"></asp:Label>
<asp:TextBox ID="TextBoxRelease" runat="server" Width="185px"></asp:TextBox>
<br />
<asp:Label ID="LabelTrailer" runat="server" Text="Trailer"></asp:Label>
<asp:TextBox ID="TextBoxTrailer" runat="server" Width="241px"></asp:TextBox>
<br />
<asp:Label ID="Label1" runat="server" Text="Afbeelding"></asp:Label>
<asp:TextBox ID="TextBoxAfbeelding" runat="server" Width="209px"></asp:TextBox>
</div>
</article>
<article id="right">
<h2>Movies</h2>
<asp:ListBox ID="ListBoxMovies" runat="server" Height="141px" Width="315px" OnSelectedIndexChanged="ListBoxMovies_SelectedIndexChanged" ViewStateMode="Inherit" AutoPostBack="True"></asp:ListBox>
</article>
</section>
</form>
电影积垢
影视
我试着把断点放在几乎所有的地方,文本框有一个文本值,但在页面上它仍然是空的?为什么不使用记录集? 它非常容易使用,我认为这对您的情况很好:
最好检查updatetemplate是否包含要填充的文本框。这是唯一一个数据绑定它们的地方吗?您从何处调用此方法?能否显示
文本框的aspx
?您是否尝试过调试以查看胶片对象中是否确实存在一些文本?为什么要使用文本框?您可以在此处使用标签来显示数据。另外,Textbox.Text是一个NOT get操作。我已经尝试过调试,并且电影对象中有文本。如果您正在使用webform,请尝试插入:listbox.AutoPostBack=true;