Click here to Skip to main content
15,910,872 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why data is not showing in Form View after selecting in GridView?

I want to display details in form view after selection of Gridview.

The Grid View and Data Source is given below.
ASP.NET
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                        AutoGenerateColumns="False" CellPadding="3" DataKeyNames="qid" 
                        DataSourceID="SqlDataSource5" GridLines="Vertical" 
                        onselectedindexchanged="GridView1_SelectedIndexChanged" 
                        style="margin-left: 23px" Width="582px" BackColor="White" 
                        BorderColor="#999999" BorderStyle="None" BorderWidth="1px" 
                        AllowSorting="True">
                        <AlternatingRowStyle BackColor="#DCDCDC" />
                        <Columns>
                            <asp:BoundField DataField="qname" HeaderText="qname" SortExpression="qname" />
                            <asp:CommandField ShowSelectButton="True" />
                        </Columns>
                        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                        <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                        <SortedAscendingCellStyle BackColor="#F1F1F1" />
                        <SortedAscendingHeaderStyle BackColor="#0000A9" />
                        <SortedDescendingCellStyle BackColor="#CAC9C9" />
                        <SortedDescendingHeaderStyle BackColor="#000065" />
                    </asp:GridView>
                    <asp:SqlDataSource ID="SqlDataSource5" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:tuitionConnectionString %>" 
                        SelectCommand="SELECT * FROM [question] WHERE (([sid] = @sid) AND ([aid] = @aid) AND ([cid] = @cid))">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="DropDownList2" Name="sid" 
                                PropertyName="SelectedValue" Type="String" />
                            <asp:ControlParameter ControlID="DropDownList3" Name="aid" 
                                PropertyName="SelectedValue" Type="String" />
                            <asp:ControlParameter ControlID="DropDownList4" Name="cid" 
                                PropertyName="SelectedValue" Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>

The FormView is given below.
ASP.NET
<asp:SqlDataSource ID="SqlDataSource6" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:tuitionConnectionString %>" 
                        
                        SelectCommand="SELECT * FROM [answer] WHERE ([qid] = @qid)" 
                        onselecting="SqlDataSource6_Selecting">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="GridView1" Name="qid" 
                                PropertyName="SelectedValue" Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                    <asp:FormView ID="FormView1" runat="server" 
                        BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" 
                        CellPadding="4" DataSourceID="SqlDataSource6" 
                        GridLines="Both" onpageindexchanging="FormView1_PageIndexChanging" 
                        DataKeyNames="qid">
                        <EditItemTemplate>
                            ansid:
                            <asp:Label ID="ansidLabel1" runat="server" Text='<%# Eval("ansid") %>' />
                            <br />
                            ansdesc:
                            <asp:TextBox ID="ansdescTextBox" runat="server" Text='<%# Bind("ansdesc") %>' />
                            <br />
                            sid:
                            <asp:TextBox ID="sidTextBox" runat="server" Text='<%# Bind("sid") %>' />
                            <br />
                            aid:
                            <asp:TextBox ID="aidTextBox" runat="server" Text='<%# Bind("aid") %>' />
                            <br />
                            cid:
                            <asp:TextBox ID="cidTextBox" runat="server" Text='<%# Bind("cid") %>' />
                            <br />
                            qid:
                            <asp:TextBox ID="qidTextBox" runat="server" Text='<%# Bind("qid") %>' />
                            <br />
                            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                                CommandName="Update" Text="Update" />
                             <asp:LinkButton ID="UpdateCancelButton" runat="server" 
                                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                        </EditItemTemplate>
                        <EditRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
                        <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
                        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
                        <InsertItemTemplate>
                            ansid:
                            <asp:TextBox ID="ansidTextBox" runat="server" Text='<%# Bind("ansid") %>' />
                            <br />
                            ansdesc:
                            <asp:TextBox ID="ansdescTextBox" runat="server" Text='<%# Bind("ansdesc") %>' />
                            <br />
                            sid:
                            <asp:TextBox ID="sidTextBox" runat="server" Text='<%# Bind("sid") %>' />
                            <br />
                            aid:
                            <asp:TextBox ID="aidTextBox" runat="server" Text='<%# Bind("aid") %>' />
                            <br />
                            cid:
                            <asp:TextBox ID="cidTextBox" runat="server" Text='<%# Bind("cid") %>' />
                            <br />
                            qid:
                            <asp:TextBox ID="qidTextBox" runat="server" Text='<%# Bind("qid") %>' />
                            <br />
                            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                                CommandName="Insert" Text="Insert" />
                             <asp:LinkButton ID="InsertCancelButton" runat="server" 
                                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <br />

                            ansdesc:
                            <asp:Label ID="ansdescLabel" runat="server" Text='<%# Bind("ansdesc") %>' />
                            <br />
                            <br />

                        </ItemTemplate>
                        <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
                        <RowStyle BackColor="White" ForeColor="#330099" />
                    </asp:FormView>
Posted
Updated 22-Dec-11 23:15pm
v2

You have not shared full information. Have a look here for sample project:
GridView-FormView (Master/Detail) Control[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900