如何指定FormView控件显示的默认数据? [英] How to specify the default data a FormView control displays?

查看:99
本文介绍了如何指定FormView控件显示的默认数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,该页面使用主/详细信息"排列来显示GridView中的一系列链接以及FormView控件中每个链接的详细信息.

多个页面使用这种安排来显示同一张表中的不同数据行-3年级页面仅显示3年级相关的表行.如果用户单击GridView中的特定链接,则该页面回发,并在FormView控件中显示该记录的详细信息.

我的问题是用户首次从该页面导航到该用户之前,该用户已从GridView选择任何记录:FormView控件默认情况下在首次加载页面时默认在源表中显示第一行,即使不是来自与该页面关联的行组.

在用户从gridview中选择任何记录之前,如何强制FormView控件在Pageload上显示特定记录?这是代码隐藏中的一个简单的PageLoad事件吗?

例如,"4年级"页面应显示"4年级"行中的条目,而不是第一个表行(即"1年级").

非常感谢您的任何建议!

这是FormView当前数据源的样子:

I have a page that uses a Master/Detail arrangement to display a series of links in a GridView and details from each link in a FormView control.

Several pages use this arrangement to display different data rows from the same table - the grade 3 page displays only the grade 3-related table rows. If a user clicks a particular link in the GridView, the page posts back with the details for that record displayed in the FormView control.

My problem is when the page is first navigated to by a user, before the user has selected any records from the GridView: the FormView control defaults to displaying the first row in the source table when the page is first loaded, even if this is not from the group of rows associated with that page.

How can I force the FormView control to display a particular record upon Pageload, before the user has chosen any record from the gridview? Is this a simple PageLoad event in codebehind?

For example, the grade 4 page should display an entry from the grade 4 rows, rather than the 1st table row (which is grade 1).

Thanks very much for any advice!

Here is what the FormView''s current datasource looks like:

<asp:SqlDataSource ID="srcProductDetailsTeacher" runat="server"

    ConnectionString="<%$ ConnectionStrings:siteConnectionString %>"

    SelectCommand="SELECT [ProductName], [ProductSKU], [ProductID], [ProductType], [ImageFile], [Grade], [ISBN], [Description], [Price] FROM [Products] WHERE ([ProductID] = @ProductID)">
    <SelectParameters>
        <asp:ControlParameter

            ControlID="grdTeacherList"

            Name="ProductID"

            PropertyName="SelectedValue"

            Type="Int32"

            DefaultValue="12"/>
    </SelectParameters>
</asp:SqlDataSource>

推荐答案

ConnectionStrings:siteConnectionString %> " SelectCommand =" 从[产品]的[SELECT]中选择[产品名称],[产品SKU],[产品ID],[产品类型],[图像文件],[等级],[ISBN],[描述],[价格]([产品ID] = @ProductID) " < SelectParameters > < asp:ControlParameter =" grdTeacherList" =" 产品ID" =" SelectedValue" =" Int32" =" 12" > < /SelectParameters > < /asp:SqlDataSource >
ConnectionStrings:siteConnectionString %>" SelectCommand="SELECT [ProductName], [ProductSKU], [ProductID], [ProductType], [ImageFile], [Grade], [ISBN], [Description], [Price] FROM [Products] WHERE ([ProductID] = @ProductID)"> <SelectParameters> <asp:ControlParameter ControlID="grdTeacherList" Name="ProductID" PropertyName="SelectedValue" Type="Int32" DefaultValue="12"/> </SelectParameters> </asp:SqlDataSource>


好,知道了:我已经将"DefaultValue"设置为行ID,而没有意识到.

正如艾米丽·丽特拉(Emily Litella)所说,没关系" ...

Ok, got it: I had set my "DefaultValue" to a row ID already without realising it.

As Emily Litella says, "Nevermind"...

<pre lang="xml"><SelectParameters>
    <asp:ControlParameter
        ControlID="grdStudentList"
        Name="ProductID"
        PropertyName="SelectedValue"
        Type="Int32"
        DefaultValue="8"/>
</SelectParameters>






这篇关于如何指定FormView控件显示的默认数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆