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

时间:2012-11-29 10:26:05

标签: c# asp.net textbox

我的页面上有几个文本框,想要用数据库中的数据填充它们。我做查询并得到(在我的情况下)一个电影对象,我用它来填充文本框,但它不起作用。 这是我的代码:

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>

我尝试过几乎无处不在的断点,文本框有文本值,但在页面上它仍然是空的?

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

为什么不使用Recordset? 它非常易于使用,我认为对您的情况有益: Here more info

相关问题