简体   繁体   English

使用数据库中的数据填充文本框

[英]Fill a textbox with data from database

I have a couple of textboxes on my page and want to fill them with data from the database. 我的页面上有几个文本框,想要用数据库中的数据填充它们。 I do the query and get (in my case) a Film object back wich i use to fill textboxes but it won't work. 我做查询并得到(在我的情况下)一个电影对象,我用它来填充文本框,但它不起作用。 Here is my code: 这是我的代码:

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;
}

There is a Film object in film but for some reason the textboxes don't display the text. 电影中有一个电影对象但由于某种原因文本框不显示文本。

Code (that is relevant) for the entire page: 整个页面的代码(相关):

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;
    }

The .aspx page .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>

I've tried putting breakpoint pretty much everywhere and textboxes have a value for text but on the page it remains empty? 我已经尝试过几乎无处不在的断点,文本框有文本值,但在页面上它仍然是空的?

检查您的updatetemplate是否包含要填充的文本框是个不错的主意。

Why don't you use a Recordset? 你为什么不使用Recordset? It is very easy to use and I think is good for your situation: Here more info 它非常易于使用,我认为对您的情况有好处: 更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM