gridview到formview - formview没有显示任何数据

时间:2011-02-01 19:45:39

标签: asp.net gridview filtering formview

我有一个gridview,如果你选择一行,它会将你带到一个表格视图,在那里你可以查看该条目的详细信息并编辑数据。当我只有一个过滤器参数时,这有用,但我添加了另一个,现在formview显示为空白。这是我的代码:

<asp:AccessDataSource ID="courseinfo" runat="server" DataFile="~/App_Data/courseinfo.mdb" SelectCommand="SELECT [prefix], [course_number], [title], [date_submitted] FROM [tableCourse]">
</asp:AccessDataSource>

<asp:AccessDataSource ID="courseinfo2" runat="server" DataFile="~/App_Data/courseinfo.mdb" FilterExpression="prefix='{0}' AND course_number='{1}'" SelectCommand="SELECT * FROM [tableCourse]">
 <FilterParameters>
  <asp:ControlParameter Name="prefix" ControlID="GridView1" PropertyName="SelectedValue" />
  <asp:ControlParameter Name="course_number" ControlID="GridView1" PropertyName="SelectedValue" />
 </FilterParameters>
</asp:AccessDataSource>

<asp:GridView ID="GridView1" runat="server" DataSourceID="courseinfo" DataKeyNames="prefix,course_number"
                    OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AutoGenerateColumns="False"
                    CellPadding="8" ForeColor="#333333" GridLines="vertical" BorderWidth="1" BorderColor="#dddddd"
                    AllowPaging="true" AllowSorting="true" AutoGenerateSelectButton="true">
                    <RowStyle BackColor="#eeeeee" />
                    <Columns>
                        <asp:BoundField DataField="prefix" HeaderText="prefix" SortExpression="prefix" />
                        <asp:BoundField DataField="course_number" HeaderText="number" SortExpression="course_number" />
                        <asp:BoundField DataField="title" HeaderText="title" SortExpression="title" />
                        <asp:BoundField DataField="date_submitted" HeaderText="date submitted" SortExpression="date_submitted" />
                    </Columns>
                    <FooterStyle BackColor="black" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="black" ForeColor="White" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#c0c0e0" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#000000" Font-Bold="True" ForeColor="#eeeeee" />
                    <EditRowStyle BackColor="#2461BF" />
                    <AlternatingRowStyle BackColor="White" />
                </asp:GridView>

<asp:FormView ID="FormView1" runat="server" DefaultMode="Edit" DataSourceID="courseinfo2"
                DataKeyNames="prefix,course_number" Width="100%">

当然formview是完整的,但它包含很多代码,所以我没有在这里包含,尽管如果有人想看到它,我可以发布它。

1 个答案:

答案 0 :(得分:0)

您可以按照以下原因更改控制参数,因为您有多个数据名称,您无法选择值作为两者的属性。但这应该有效:

    <asp:ControlParameter Name="prefix" ControlID="GridView1" PropertyName="SelectedDataKey.Values[prefix]" Type="String"  />
    <asp:ControlParameter Name="course_number" ControlID="GridView1" PropertyName="SelectedDataKey.Values[course_number]" Type="Int32" />