簡體   English   中英

使用數據庫中的數據填充文本框

[英]Fill a textbox with data from database

我的頁面上有幾個文本框,想要用數據庫中的數據填充它們。 我做查詢並得到(在我的情況下)一個電影對象,我用它來填充文本框,但它不起作用。 這是我的代碼:

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是否包含要填充的文本框是個不錯的主意。

你為什么不使用Recordset? 它非常易於使用,我認為對您的情況有好處: 更多信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM