GridView-FormView (Master/Detail) Control not working...

Discussion in 'ASP .Net' started by yixiang, Jan 28, 2008.

  1. yixiang

    yixiang Guest

    Hi All,

    I am a newbie to .NET programming and have been figuring out this
    (master/detail) control.

    However, it is not working...can someone please help me out???

    <asp:GridView ID="GridView1" runat="server" DataKeyNames="ServiceID,
    VersionNum" CellPadding="4" DataSourceID="SqlDataSource1"
    ForeColor="#333333" GridLines="None"
    Height="81px" Width="16px">
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True"
    ForeColor="White" />
    <Columns>
    <asp:CommandField ShowSelectButton="True" />
    <asp:BoundField DataField="VersionNum"
    HeaderText="VersionNum" ReadOnly="True" SortExpression="VersionNum" />
    <asp:BoundField DataField="ServiceID"
    HeaderText="ServiceID" ReadOnly="True" SortExpression="ServiceID" />
    <asp:BoundField DataField="VersionDesc"
    HeaderText="VersionDesc" SortExpression="VersionDesc" />
    </Columns>
    </asp:GridView>
    </div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
    ProviderName="<%$ ConnectionStrings:ConnectionString2.
    ProviderName %>" SelectCommand="SELECT [ServiceID], [VersionNum],
    [VersionDesc] FROM [w_ServiceVersion]">
    </asp:SqlDataSource>
    </td>
    </tr>
    <tr>
    <td style="width: 737px; height: 21px">
    <asp:FormView ID="FormView1" runat="server"
    DataKeyNames="ServiceID,VersionNum" DataSourceID="SqlDataSource2"
    Width="555px">
    <EditItemTemplate>
    ...........
    </EditItemTemplate>
    <InsertItemTemplate>
    .............

    </InsertItemTemplate>
    <ItemTemplate>
    ............
    </ItemTemplate>
    </asp:FormView>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server"
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    ProviderName="<%$ ConnectionStrings:ConnectionString.
    ProviderName %>" SelectCommand="SELECT ServiceID, VersionNum, VersionDesc
    FROM dbo.w_ServiceVersion WHERE (ServiceID = ServiceID AND VersionNum =
    VersionNum)">
    <SelectParameters>
    <asp:ControlParameter ControlID="GridView1"
    Name="ServiceID" PropertyName="SelectedValue" />
    <asp:ControlParameter ControlID="GridView1"
    Name="VersionNum" PropertyName="SelectedValue" />
    </SelectParameters>
    </asp:SqlDataSource>

    url:http://ureader.com/gp/1417-1.aspx
     
    yixiang, Jan 28, 2008
    #1
    1. Advertising

  2. Howdy,

    Seems you use composite data key on columns ServiceID and VersionNum, but
    you two control parameters both point to the first value which in this case
    is ServiceID (you can check what's passed to the query by handling
    SqlDataSource2.Selecting event and checking e.Command.Parameters[0].Value,
    e.Command.Parameters[1].Value). They point to the same value because of you
    used GridView1.SelectedValue property which is a shortcut for
    GridView1.SelectedDataKey.Values[0], what you need is to change the code to:

    <asp:SqlDataSource ID="SqlDataSource2" runat="server"
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
    SelectCommand="SELECT ServiceID, VersionNum, VersionDesc FROM
    dbo.w_ServiceVersion WHERE (ServiceID = ServiceID AND VersionNum =
    VersionNum)">
    <SelectParameters>
    <asp:ControlParameter ControlID="GridView1" Name="ServiceID"
    PropertyName="SelectedDataKey[0]" />
    <asp:ControlParameter ControlID="GridView1" Name="VersionNum"
    PropertyName="SelectedDataKey[1]" />
    </SelectParameters>
    </asp:SqlDataSource>

    Hope this helps
    --
    Milosz


    "yixiang" wrote:

    > Hi All,
    >
    > I am a newbie to .NET programming and have been figuring out this
    > (master/detail) control.
    >
    > However, it is not working...can someone please help me out???
    >
    > <asp:GridView ID="GridView1" runat="server" DataKeyNames="ServiceID,
    > VersionNum" CellPadding="4" DataSourceID="SqlDataSource1"
    > ForeColor="#333333" GridLines="None"
    > Height="81px" Width="16px">
    > <FooterStyle BackColor="#5D7B9D" Font-Bold="True"
    > ForeColor="White" />
    > <Columns>
    > <asp:CommandField ShowSelectButton="True" />
    > <asp:BoundField DataField="VersionNum"
    > HeaderText="VersionNum" ReadOnly="True" SortExpression="VersionNum" />
    > <asp:BoundField DataField="ServiceID"
    > HeaderText="ServiceID" ReadOnly="True" SortExpression="ServiceID" />
    > <asp:BoundField DataField="VersionDesc"
    > HeaderText="VersionDesc" SortExpression="VersionDesc" />
    > </Columns>
    > </asp:GridView>
    > </div>
    > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    > ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
    > ProviderName="<%$ ConnectionStrings:ConnectionString2.
    > ProviderName %>" SelectCommand="SELECT [ServiceID], [VersionNum],
    > [VersionDesc] FROM [w_ServiceVersion]">
    > </asp:SqlDataSource>
    > </td>
    > </tr>
    > <tr>
    > <td style="width: 737px; height: 21px">
    > <asp:FormView ID="FormView1" runat="server"
    > DataKeyNames="ServiceID,VersionNum" DataSourceID="SqlDataSource2"
    > Width="555px">
    > <EditItemTemplate>
    > ...........
    > </EditItemTemplate>
    > <InsertItemTemplate>
    > .............
    >
    > </InsertItemTemplate>
    > <ItemTemplate>
    > ............
    > </ItemTemplate>
    > </asp:FormView>
    > <asp:SqlDataSource ID="SqlDataSource2" runat="server"
    > ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    > ProviderName="<%$ ConnectionStrings:ConnectionString.
    > ProviderName %>" SelectCommand="SELECT ServiceID, VersionNum, VersionDesc
    > FROM dbo.w_ServiceVersion WHERE (ServiceID = ServiceID AND VersionNum =
    > VersionNum)">
    > <SelectParameters>
    > <asp:ControlParameter ControlID="GridView1"
    > Name="ServiceID" PropertyName="SelectedValue" />
    > <asp:ControlParameter ControlID="GridView1"
    > Name="VersionNum" PropertyName="SelectedValue" />
    > </SelectParameters>
    > </asp:SqlDataSource>
    >
    > url:http://ureader.com/gp/1417-1.aspx
    >
     
    Milosz Skalecki [MCAD], Jan 29, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. asmj
    Replies:
    0
    Views:
    523
  2. Aamir Ghanchi
    Replies:
    2
    Views:
    5,848
    Aamir Ghanchi
    Jan 18, 2008
  3. Henri Fournier

    FormView/ListView master/detail problem

    Henri Fournier, Mar 6, 2009, in forum: ASP .Net
    Replies:
    0
    Views:
    1,831
    Henri Fournier
    Mar 6, 2009
  4. Arun Kumar Menon

    Master Detail detail

    Arun Kumar Menon, Aug 6, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    218
    Arun Kumar Menon
    Aug 6, 2003
  5. Frederik Borg

    ASp.net data binding: Master-detail-detail

    Frederik Borg, Jun 9, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    380
    Frederik Borg
    Jun 9, 2006
Loading...

Share This Page