gridview to formview - formview not showing any data

1.9k views Asked by At

I have a gridview where, if you select a row, it takes you to a formview where you can view details from that entry and edit the data. This worked when I had only one filter parameter, but I added another, and now the formview is showing up blank. Here's my code:

<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%">

Of course the formview is complete but it contains a lot of code so I didn't include that here, although if anyone wants to see it, I can post it.

1

There are 1 answers

0
Bat_Programmer On

You can change your control parameters as follows reason being since you have multiple datakeynames, you cant have selected value as property of both. This should work however:

    <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" />