Lost link between GridView and DetailsView

Discussion in 'ASP .Net' started by VB Programmer, Oct 8, 2007.

  1. For some reason, when I select the record in my GridView the DetailsView
    doesn't show up anymore. What "links" the 2?

    The DetailsView is based on an SQLDataSource with a WHERE clause using the
    value from the GridView.

    Any ideas?

    Here's the definitions...

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
    AllowSorting="True"
    AutoGenerateColumns="False" CellPadding="4"
    DataSourceID="SqlDataSource1" ForeColor="#333333"
    GridLines="None" DataKeyNames="ProgramId">
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
    />
    <Columns>
    <asp:CommandField ShowSelectButton="True" />
    <asp:BoundField DataField="ProgramName" HeaderText="Program"
    SortExpression="ProgramName">
    <ItemStyle Width="200px" />
    </asp:BoundField>
    <asp:BoundField DataField="ProgramId" HeaderText="ProgramId"
    InsertVisible="False"
    ReadOnly="True" SortExpression="ProgramId" Visible="False"
    />
    <asp:TemplateField>
    <ItemTemplate>
    <asp:LinkButton runat="server" ID="btnDelete"
    CommandName="Delete" OnClientClick="return confirm('Are you sure you want to
    PERMANENTLY DELETE this record and ALL associated records?');"
    Text="Delete"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <EditRowStyle BackColor="#999999" />
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
    ForeColor="#333333" />
    <PagerStyle BackColor="#284775" ForeColor="White"
    HorizontalAlign="Center" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
    />
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>

    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
    CellPadding="4"
    DataKeyNames="ProgramId" DataSourceID="sdsProgramDetails"
    ForeColor="#333333" GridLines="None"
    Height="50px" Width="465px">
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
    />
    <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
    <EditRowStyle BackColor="#999999" />
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <PagerStyle BackColor="#284775" ForeColor="White"
    HorizontalAlign="Center" />
    <Fields>
    <asp:BoundField DataField="ProgramName" HeaderText="Program
    Name" SortExpression="ProgramName" />
    <asp:CheckBoxField DataField="ActiveProgram" HeaderText="Active"
    SortExpression="ActiveProgram" />
    <asp:BoundField DataField="ProgramId" HeaderText="ProgramId"
    InsertVisible="False"
    ReadOnly="True" SortExpression="ProgramId" Visible="False"
    />
    <asp:TemplateField HeaderText="Program Type"
    SortExpression="ProgramTypeId">
    <EditItemTemplate>
    <asp:DropDownList ID="DropDownList1" runat="server"
    DataSourceID="sdsProgTypes" DataTextField="ProgramType"
    DataValueField="ProgramTypeId" SelectedValue='<%#
    Bind("ProgramTypeId") %>' Width="269px">
    </asp:DropDownList>
    </EditItemTemplate>
    <InsertItemTemplate>
    <asp:DropDownList ID="DropDownList1" runat="server"
    DataSourceID="sdsProgTypes" DataTextField="ProgramType"
    DataValueField="ProgramTypeId" SelectedValue='<%#
    Bind("ProgramTypeId") %>' Width="269px">
    </asp:DropDownList>
    </InsertItemTemplate>
    <ItemTemplate>
    <asp:Label ID="Label2" runat="server" Text='<%#
    Bind("ProgramType") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="MaxClients" HeaderText="Max Clients"
    SortExpression="MaxClients" />
    <asp:TemplateField HeaderText="Start Date"
    SortExpression="StartDate">
    <EditItemTemplate>
    <asp:Calendar ID="Calendar1" runat="server"
    BackColor="White" BorderColor="White"
    BorderWidth="1px" Font-Names="Verdana"
    Font-Size="9pt" ForeColor="Black" Height="170px"
    NextPrevFormat="FullMonth" SelectedDate='<%#
    Bind("StartDate") %>' Width="274px">
    <SelectedDayStyle BackColor="#333399"
    ForeColor="White" />
    <TodayDayStyle BackColor="#CCCCCC" />
    <OtherMonthDayStyle ForeColor="#999999" />
    <NextPrevStyle Font-Bold="True" Font-Size="8pt"
    ForeColor="#333333" VerticalAlign="Bottom" />
    <DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
    <TitleStyle BackColor="White" BorderColor="Black"
    BorderWidth="4px" Font-Bold="True"
    Font-Size="12pt" ForeColor="#333399" />
    </asp:Calendar>
    </EditItemTemplate>
    <InsertItemTemplate>
    <asp:Calendar ID="Calendar1" runat="server"
    BackColor="White" BorderColor="White"
    BorderWidth="1px" Font-Names="Verdana"
    Font-Size="9pt" ForeColor="Black" Height="170px"
    NextPrevFormat="FullMonth" SelectedDate='<%#
    Bind("StartDate") %>' Width="274px">
    <SelectedDayStyle BackColor="#333399"
    ForeColor="White" />
    <TodayDayStyle BackColor="#CCCCCC" />
    <OtherMonthDayStyle ForeColor="#999999" />
    <NextPrevStyle Font-Bold="True" Font-Size="8pt"
    ForeColor="#333333" VerticalAlign="Bottom" />
    <DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
    <TitleStyle BackColor="White" BorderColor="Black"
    BorderWidth="4px" Font-Bold="True"
    Font-Size="12pt" ForeColor="#333399" />
    </asp:Calendar>
    </InsertItemTemplate>
    <ItemTemplate>
    <asp:Label ID="Label3" runat="server" Text='<%#
    Bind("StartDate", "{0:d}") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="DefaultMgmtFee" HeaderText="Default
    Mgmt Fee" SortExpression="DefaultMgmtFee" />
    <asp:TemplateField HeaderText="Fee Type"
    SortExpression="MgmtFeeType">
    <EditItemTemplate>
    <asp:DropDownList ID="DropDownList2" runat="server"
    SelectedValue='<%# Bind("MgmtFeeType") %>'>
    <asp:ListItem>%</asp:ListItem>
    <asp:ListItem>$</asp:ListItem>
    </asp:DropDownList>
    </EditItemTemplate>
    <InsertItemTemplate>
    <asp:DropDownList ID="DropDownList2" runat="server"
    SelectedValue='<%# Bind("MgmtFeeType") %>'>
    <asp:ListItem>%</asp:ListItem>
    <asp:ListItem>$</asp:ListItem>
    </asp:DropDownList>
    </InsertItemTemplate>
    <ItemTemplate>
    <asp:Label ID="Label1" runat="server" Text='<%#
    Bind("MgmtFeeType") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="ReoccuranceNumber"
    HeaderText="Reoccur #" SortExpression="ReoccuranceNumber" />
    <asp:TemplateField HeaderText="Reoccur Interval"
    SortExpression="Reoccurance">
    <EditItemTemplate>
    <asp:DropDownList ID="DropDownList3" runat="server"
    DataSourceID="sdsReoccur" DataTextField="Reoccurance"
    DataValueField="ReoccuranceId" SelectedValue='<%#
    Bind("ReoccuranceId") %>'>
    </asp:DropDownList>
    </EditItemTemplate>
    <InsertItemTemplate>
    <asp:DropDownList ID="DropDownList3" runat="server"
    DataSourceID="sdsReoccur" DataTextField="Reoccurance"
    DataValueField="ReoccuranceId" SelectedValue='<%#
    Bind("ReoccuranceId") %>'>
    </asp:DropDownList>
    </InsertItemTemplate>
    <ItemTemplate>
    <asp:Label ID="Label4" runat="server" Text='<%#
    Bind("Reoccurance") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="Comments" HeaderText="Comments"
    SortExpression="Comments" >
    <ItemStyle Width="300px" />
    </asp:BoundField>
    <asp:CommandField ShowEditButton="True" ShowInsertButton="True"
    />
    </Fields>
    <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
    />
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:DetailsView>


    <asp:SqlDataSource ID="sdsProgramDetails" runat="server"
    ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>"
    DeleteCommand="DELETE FROM [Programs] WHERE
    [ProgramId] = @ProgramId" InsertCommand="INSERT INTO [Programs]
    ([ProgramTypeId], [ProgramName], [ActiveProgram], [MaxClients], [StartDate],
    [DefaultMgmtFee], [MgmtFeeType], [Comments]) VALUES (@ProgramTypeId,
    @ProgramName, @ActiveProgram, @MaxClients, @StartDate, @DefaultMgmtFee,
    @MgmtFeeType, @Comments)"
    SelectCommand="SELECT Programs.ProgramId,
    Programs.ProgramTypeId, Programs.ProgramName, Programs.ActiveProgram,
    Programs.MaxClients, Programs.StartDate, Programs.DefaultMgmtFee,
    Programs.MgmtFeeType, Programs.Comments, ProgramTypes.ProgramType,
    Programs.ReoccuranceNumber, Programs.ReoccuranceId, Reoccurance.Reoccurance
    FROM Programs INNER JOIN ProgramTypes ON Programs.ProgramTypeId =
    ProgramTypes.ProgramTypeId INNER JOIN Reoccurance ON Programs.ReoccuranceId
    = Reoccurance.ReoccuranceId WHERE (Programs.ProgramId = @ProgramId)"
    UpdateCommand="UPDATE [Programs] SET [ProgramTypeId] = @ProgramTypeId,
    [ProgramName] = @ProgramName, [ActiveProgram] = @ActiveProgram, [MaxClients]
    = @MaxClients, [StartDate] = @StartDate, [DefaultMgmtFee] = @DefaultMgmtFee,
    [MgmtFeeType] = @MgmtFeeType, [Comments] = @Comments WHERE [ProgramId] =
    @ProgramId">
    <DeleteParameters>
    <asp:parameter Name="ProgramId" Type="Int32"
    />
    </DeleteParameters>
    <UpdateParameters>
    <asp:parameter Name="ProgramTypeId"
    Type="Int32" />
    <asp:parameter Name="ProgramName"
    Type="String" />
    <asp:parameter Name="ActiveProgram"
    Type="Boolean" />
    <asp:parameter Name="MaxClients"
    Type="Int32" />
    <asp:parameter Name="StartDate"
    Type="DateTime" />
    <asp:parameter Name="DefaultMgmtFee"
    Type="Decimal" />
    <asp:parameter Name="MgmtFeeType"
    Type="String" />
    <asp:parameter Name="Comments" Type="String"
    />
    <asp:parameter Name="ProgramId" Type="Int32"
    />
    </UpdateParameters>
    <SelectParameters>
    <asp:ControlParameter ControlID="GridView1"
    Name="ProgramId" PropertyName="SelectedValue"
    Type="Int32" />
    </SelectParameters>
    <InsertParameters>
    <asp:parameter Name="ProgramTypeId"
    Type="Int32" />
    <asp:parameter Name="ProgramName"
    Type="String" />
    <asp:parameter Name="ActiveProgram"
    Type="Boolean" />
    <asp:parameter Name="MaxClients"
    Type="Int32" />
    <asp:parameter Name="StartDate"
    Type="DateTime" />
    <asp:parameter Name="DefaultMgmtFee"
    Type="Decimal" />
    <asp:parameter Name="MgmtFeeType"
    Type="String" />
    <asp:parameter Name="Comments" Type="String"
    />
    </InsertParameters>
    </asp:SqlDataSource>
     
    VB Programmer, Oct 8, 2007
    #1
    1. Advertising

  2. Your datasources are linked correctly. You need to handle the gridview's
    SelectedIndexChanged event like this:

    protected void GridView1_OnSelectedIndexChanged(Object sender, EventArgs e)

    {

    this.sdsProgramDetails.Select(System.Web.UI.DataSourceSelectArguments.Empty);

    this.DetailsView1.DataBind();

    }


    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "VB Programmer" <> wrote in message
    news:%...
    > For some reason, when I select the record in my GridView the DetailsView
    > doesn't show up anymore. What "links" the 2?
    >
    > The DetailsView is based on an SQLDataSource with a WHERE clause using the
    > value from the GridView.
    >
    > Any ideas?
    >
    > Here's the definitions...
    >
    > <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
    > AllowSorting="True"
    > AutoGenerateColumns="False" CellPadding="4"
    > DataSourceID="SqlDataSource1" ForeColor="#333333"
    > GridLines="None" DataKeyNames="ProgramId">
    > <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
    > />
    > <Columns>
    > <asp:CommandField ShowSelectButton="True" />
    > <asp:BoundField DataField="ProgramName" HeaderText="Program"
    > SortExpression="ProgramName">
    > <ItemStyle Width="200px" />
    > </asp:BoundField>
    > <asp:BoundField DataField="ProgramId" HeaderText="ProgramId"
    > InsertVisible="False"
    > ReadOnly="True" SortExpression="ProgramId" Visible="False"
    > />
    > <asp:TemplateField>
    > <ItemTemplate>
    > <asp:LinkButton runat="server" ID="btnDelete"
    > CommandName="Delete" OnClientClick="return confirm('Are you sure you want
    > to PERMANENTLY DELETE this record and ALL associated records?');"
    > Text="Delete"></asp:LinkButton>
    > </ItemTemplate>
    > </asp:TemplateField>
    > </Columns>
    > <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    > <EditRowStyle BackColor="#999999" />
    > <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
    > ForeColor="#333333" />
    > <PagerStyle BackColor="#284775" ForeColor="White"
    > HorizontalAlign="Center" />
    > <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
    > />
    > <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    > </asp:GridView>
    >
    > <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
    > CellPadding="4"
    > DataKeyNames="ProgramId" DataSourceID="sdsProgramDetails"
    > ForeColor="#333333" GridLines="None"
    > Height="50px" Width="465px">
    > <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
    > />
    > <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
    > <EditRowStyle BackColor="#999999" />
    > <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    > <PagerStyle BackColor="#284775" ForeColor="White"
    > HorizontalAlign="Center" />
    > <Fields>
    > <asp:BoundField DataField="ProgramName" HeaderText="Program
    > Name" SortExpression="ProgramName" />
    > <asp:CheckBoxField DataField="ActiveProgram"
    > HeaderText="Active" SortExpression="ActiveProgram" />
    > <asp:BoundField DataField="ProgramId" HeaderText="ProgramId"
    > InsertVisible="False"
    > ReadOnly="True" SortExpression="ProgramId" Visible="False"
    > />
    > <asp:TemplateField HeaderText="Program Type"
    > SortExpression="ProgramTypeId">
    > <EditItemTemplate>
    > <asp:DropDownList ID="DropDownList1" runat="server"
    > DataSourceID="sdsProgTypes" DataTextField="ProgramType"
    > DataValueField="ProgramTypeId" SelectedValue='<%#
    > Bind("ProgramTypeId") %>' Width="269px">
    > </asp:DropDownList>
    > </EditItemTemplate>
    > <InsertItemTemplate>
    > <asp:DropDownList ID="DropDownList1" runat="server"
    > DataSourceID="sdsProgTypes" DataTextField="ProgramType"
    > DataValueField="ProgramTypeId" SelectedValue='<%#
    > Bind("ProgramTypeId") %>' Width="269px">
    > </asp:DropDownList>
    > </InsertItemTemplate>
    > <ItemTemplate>
    > <asp:Label ID="Label2" runat="server" Text='<%#
    > Bind("ProgramType") %>'></asp:Label>
    > </ItemTemplate>
    > </asp:TemplateField>
    > <asp:BoundField DataField="MaxClients" HeaderText="Max Clients"
    > SortExpression="MaxClients" />
    > <asp:TemplateField HeaderText="Start Date"
    > SortExpression="StartDate">
    > <EditItemTemplate>
    > <asp:Calendar ID="Calendar1" runat="server"
    > BackColor="White" BorderColor="White"
    > BorderWidth="1px" Font-Names="Verdana"
    > Font-Size="9pt" ForeColor="Black" Height="170px"
    > NextPrevFormat="FullMonth" SelectedDate='<%#
    > Bind("StartDate") %>' Width="274px">
    > <SelectedDayStyle BackColor="#333399"
    > ForeColor="White" />
    > <TodayDayStyle BackColor="#CCCCCC" />
    > <OtherMonthDayStyle ForeColor="#999999" />
    > <NextPrevStyle Font-Bold="True" Font-Size="8pt"
    > ForeColor="#333333" VerticalAlign="Bottom" />
    > <DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
    > <TitleStyle BackColor="White" BorderColor="Black"
    > BorderWidth="4px" Font-Bold="True"
    > Font-Size="12pt" ForeColor="#333399" />
    > </asp:Calendar>
    > </EditItemTemplate>
    > <InsertItemTemplate>
    > <asp:Calendar ID="Calendar1" runat="server"
    > BackColor="White" BorderColor="White"
    > BorderWidth="1px" Font-Names="Verdana"
    > Font-Size="9pt" ForeColor="Black" Height="170px"
    > NextPrevFormat="FullMonth" SelectedDate='<%#
    > Bind("StartDate") %>' Width="274px">
    > <SelectedDayStyle BackColor="#333399"
    > ForeColor="White" />
    > <TodayDayStyle BackColor="#CCCCCC" />
    > <OtherMonthDayStyle ForeColor="#999999" />
    > <NextPrevStyle Font-Bold="True" Font-Size="8pt"
    > ForeColor="#333333" VerticalAlign="Bottom" />
    > <DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
    > <TitleStyle BackColor="White" BorderColor="Black"
    > BorderWidth="4px" Font-Bold="True"
    > Font-Size="12pt" ForeColor="#333399" />
    > </asp:Calendar>
    > </InsertItemTemplate>
    > <ItemTemplate>
    > <asp:Label ID="Label3" runat="server" Text='<%#
    > Bind("StartDate", "{0:d}") %>'></asp:Label>
    > </ItemTemplate>
    > </asp:TemplateField>
    > <asp:BoundField DataField="DefaultMgmtFee" HeaderText="Default
    > Mgmt Fee" SortExpression="DefaultMgmtFee" />
    > <asp:TemplateField HeaderText="Fee Type"
    > SortExpression="MgmtFeeType">
    > <EditItemTemplate>
    > <asp:DropDownList ID="DropDownList2" runat="server"
    > SelectedValue='<%# Bind("MgmtFeeType") %>'>
    > <asp:ListItem>%</asp:ListItem>
    > <asp:ListItem>$</asp:ListItem>
    > </asp:DropDownList>
    > </EditItemTemplate>
    > <InsertItemTemplate>
    > <asp:DropDownList ID="DropDownList2" runat="server"
    > SelectedValue='<%# Bind("MgmtFeeType") %>'>
    > <asp:ListItem>%</asp:ListItem>
    > <asp:ListItem>$</asp:ListItem>
    > </asp:DropDownList>
    > </InsertItemTemplate>
    > <ItemTemplate>
    > <asp:Label ID="Label1" runat="server" Text='<%#
    > Bind("MgmtFeeType") %>'></asp:Label>
    > </ItemTemplate>
    > </asp:TemplateField>
    > <asp:BoundField DataField="ReoccuranceNumber"
    > HeaderText="Reoccur #" SortExpression="ReoccuranceNumber" />
    > <asp:TemplateField HeaderText="Reoccur Interval"
    > SortExpression="Reoccurance">
    > <EditItemTemplate>
    > <asp:DropDownList ID="DropDownList3" runat="server"
    > DataSourceID="sdsReoccur" DataTextField="Reoccurance"
    > DataValueField="ReoccuranceId" SelectedValue='<%#
    > Bind("ReoccuranceId") %>'>
    > </asp:DropDownList>
    > </EditItemTemplate>
    > <InsertItemTemplate>
    > <asp:DropDownList ID="DropDownList3" runat="server"
    > DataSourceID="sdsReoccur" DataTextField="Reoccurance"
    > DataValueField="ReoccuranceId" SelectedValue='<%#
    > Bind("ReoccuranceId") %>'>
    > </asp:DropDownList>
    > </InsertItemTemplate>
    > <ItemTemplate>
    > <asp:Label ID="Label4" runat="server" Text='<%#
    > Bind("Reoccurance") %>'></asp:Label>
    > </ItemTemplate>
    > </asp:TemplateField>
    > <asp:BoundField DataField="Comments" HeaderText="Comments"
    > SortExpression="Comments" >
    > <ItemStyle Width="300px" />
    > </asp:BoundField>
    > <asp:CommandField ShowEditButton="True" ShowInsertButton="True"
    > />
    > </Fields>
    > <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
    > <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
    > />
    > <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    > </asp:DetailsView>
    >
    >
    > <asp:SqlDataSource ID="sdsProgramDetails" runat="server"
    > ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>"
    > DeleteCommand="DELETE FROM [Programs] WHERE
    > [ProgramId] = @ProgramId" InsertCommand="INSERT INTO [Programs]
    > ([ProgramTypeId], [ProgramName], [ActiveProgram], [MaxClients],
    > [StartDate], [DefaultMgmtFee], [MgmtFeeType], [Comments]) VALUES
    > (@ProgramTypeId, @ProgramName, @ActiveProgram, @MaxClients, @StartDate,
    > @DefaultMgmtFee, @MgmtFeeType, @Comments)"
    > SelectCommand="SELECT Programs.ProgramId,
    > Programs.ProgramTypeId, Programs.ProgramName, Programs.ActiveProgram,
    > Programs.MaxClients, Programs.StartDate, Programs.DefaultMgmtFee,
    > Programs.MgmtFeeType, Programs.Comments, ProgramTypes.ProgramType,
    > Programs.ReoccuranceNumber, Programs.ReoccuranceId,
    > Reoccurance.Reoccurance FROM Programs INNER JOIN ProgramTypes ON
    > Programs.ProgramTypeId = ProgramTypes.ProgramTypeId INNER JOIN Reoccurance
    > ON Programs.ReoccuranceId = Reoccurance.ReoccuranceId WHERE
    > (Programs.ProgramId = @ProgramId)" UpdateCommand="UPDATE [Programs] SET
    > [ProgramTypeId] = @ProgramTypeId, [ProgramName] = @ProgramName,
    > [ActiveProgram] = @ActiveProgram, [MaxClients] = @MaxClients, [StartDate]
    > = @StartDate, [DefaultMgmtFee] = @DefaultMgmtFee, [MgmtFeeType] =
    > @MgmtFeeType, [Comments] = @Comments WHERE [ProgramId] = @ProgramId">
    > <DeleteParameters>
    > <asp:parameter Name="ProgramId"
    > Type="Int32" />
    > </DeleteParameters>
    > <UpdateParameters>
    > <asp:parameter Name="ProgramTypeId"
    > Type="Int32" />
    > <asp:parameter Name="ProgramName"
    > Type="String" />
    > <asp:parameter Name="ActiveProgram"
    > Type="Boolean" />
    > <asp:parameter Name="MaxClients"
    > Type="Int32" />
    > <asp:parameter Name="StartDate"
    > Type="DateTime" />
    > <asp:parameter Name="DefaultMgmtFee"
    > Type="Decimal" />
    > <asp:parameter Name="MgmtFeeType"
    > Type="String" />
    > <asp:parameter Name="Comments"
    > Type="String" />
    > <asp:parameter Name="ProgramId"
    > Type="Int32" />
    > </UpdateParameters>
    > <SelectParameters>
    > <asp:ControlParameter ControlID="GridView1"
    > Name="ProgramId" PropertyName="SelectedValue"
    > Type="Int32" />
    > </SelectParameters>
    > <InsertParameters>
    > <asp:parameter Name="ProgramTypeId"
    > Type="Int32" />
    > <asp:parameter Name="ProgramName"
    > Type="String" />
    > <asp:parameter Name="ActiveProgram"
    > Type="Boolean" />
    > <asp:parameter Name="MaxClients"
    > Type="Int32" />
    > <asp:parameter Name="StartDate"
    > Type="DateTime" />
    > <asp:parameter Name="DefaultMgmtFee"
    > Type="Decimal" />
    > <asp:parameter Name="MgmtFeeType"
    > Type="String" />
    > <asp:parameter Name="Comments"
    > Type="String" />
    > </InsertParameters>
    > </asp:SqlDataSource>
    >
     
    Eliyahu Goldin, Oct 9, 2007
    #2
    1. Advertising

  3. I appreciate your help!

    "Eliyahu Goldin" <> wrote in
    message news:%...
    > Your datasources are linked correctly. You need to handle the gridview's
    > SelectedIndexChanged event like this:
    >
    > protected void GridView1_OnSelectedIndexChanged(Object sender, EventArgs
    > e)
    >
    > {
    >
    > this.sdsProgramDetails.Select(System.Web.UI.DataSourceSelectArguments.Empty);
    >
    > this.DetailsView1.DataBind();
    >
    > }
    >
    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    > http://usableasp.net
    >
    >
    > "VB Programmer" <> wrote in message
    > news:%...
    >> For some reason, when I select the record in my GridView the DetailsView
    >> doesn't show up anymore. What "links" the 2?
    >>
    >> The DetailsView is based on an SQLDataSource with a WHERE clause using
    >> the value from the GridView.
    >>
    >> Any ideas?
    >>
    >> Here's the definitions...
    >>
    >> <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
    >> AllowSorting="True"
    >> AutoGenerateColumns="False" CellPadding="4"
    >> DataSourceID="SqlDataSource1" ForeColor="#333333"
    >> GridLines="None" DataKeyNames="ProgramId">
    >> <FooterStyle BackColor="#5D7B9D" Font-Bold="True"
    >> ForeColor="White" />
    >> <Columns>
    >> <asp:CommandField ShowSelectButton="True" />
    >> <asp:BoundField DataField="ProgramName" HeaderText="Program"
    >> SortExpression="ProgramName">
    >> <ItemStyle Width="200px" />
    >> </asp:BoundField>
    >> <asp:BoundField DataField="ProgramId" HeaderText="ProgramId"
    >> InsertVisible="False"
    >> ReadOnly="True" SortExpression="ProgramId" Visible="False"
    >> />
    >> <asp:TemplateField>
    >> <ItemTemplate>
    >> <asp:LinkButton runat="server" ID="btnDelete"
    >> CommandName="Delete" OnClientClick="return confirm('Are you sure you want
    >> to PERMANENTLY DELETE this record and ALL associated records?');"
    >> Text="Delete"></asp:LinkButton>
    >> </ItemTemplate>
    >> </asp:TemplateField>
    >> </Columns>
    >> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    >> <EditRowStyle BackColor="#999999" />
    >> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
    >> ForeColor="#333333" />
    >> <PagerStyle BackColor="#284775" ForeColor="White"
    >> HorizontalAlign="Center" />
    >> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
    >> ForeColor="White" />
    >> <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    >> </asp:GridView>
    >>
    >> <asp:DetailsView ID="DetailsView1" runat="server"
    >> AutoGenerateRows="False" CellPadding="4"
    >> DataKeyNames="ProgramId" DataSourceID="sdsProgramDetails"
    >> ForeColor="#333333" GridLines="None"
    >> Height="50px" Width="465px">
    >> <FooterStyle BackColor="#5D7B9D" Font-Bold="True"
    >> ForeColor="White" />
    >> <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
    >> <EditRowStyle BackColor="#999999" />
    >> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    >> <PagerStyle BackColor="#284775" ForeColor="White"
    >> HorizontalAlign="Center" />
    >> <Fields>
    >> <asp:BoundField DataField="ProgramName" HeaderText="Program
    >> Name" SortExpression="ProgramName" />
    >> <asp:CheckBoxField DataField="ActiveProgram"
    >> HeaderText="Active" SortExpression="ActiveProgram" />
    >> <asp:BoundField DataField="ProgramId" HeaderText="ProgramId"
    >> InsertVisible="False"
    >> ReadOnly="True" SortExpression="ProgramId" Visible="False"
    >> />
    >> <asp:TemplateField HeaderText="Program Type"
    >> SortExpression="ProgramTypeId">
    >> <EditItemTemplate>
    >> <asp:DropDownList ID="DropDownList1" runat="server"
    >> DataSourceID="sdsProgTypes" DataTextField="ProgramType"
    >> DataValueField="ProgramTypeId" SelectedValue='<%#
    >> Bind("ProgramTypeId") %>' Width="269px">
    >> </asp:DropDownList>
    >> </EditItemTemplate>
    >> <InsertItemTemplate>
    >> <asp:DropDownList ID="DropDownList1" runat="server"
    >> DataSourceID="sdsProgTypes" DataTextField="ProgramType"
    >> DataValueField="ProgramTypeId" SelectedValue='<%#
    >> Bind("ProgramTypeId") %>' Width="269px">
    >> </asp:DropDownList>
    >> </InsertItemTemplate>
    >> <ItemTemplate>
    >> <asp:Label ID="Label2" runat="server" Text='<%#
    >> Bind("ProgramType") %>'></asp:Label>
    >> </ItemTemplate>
    >> </asp:TemplateField>
    >> <asp:BoundField DataField="MaxClients" HeaderText="Max
    >> Clients" SortExpression="MaxClients" />
    >> <asp:TemplateField HeaderText="Start Date"
    >> SortExpression="StartDate">
    >> <EditItemTemplate>
    >> <asp:Calendar ID="Calendar1" runat="server"
    >> BackColor="White" BorderColor="White"
    >> BorderWidth="1px" Font-Names="Verdana"
    >> Font-Size="9pt" ForeColor="Black" Height="170px"
    >> NextPrevFormat="FullMonth" SelectedDate='<%#
    >> Bind("StartDate") %>' Width="274px">
    >> <SelectedDayStyle BackColor="#333399"
    >> ForeColor="White" />
    >> <TodayDayStyle BackColor="#CCCCCC" />
    >> <OtherMonthDayStyle ForeColor="#999999" />
    >> <NextPrevStyle Font-Bold="True" Font-Size="8pt"
    >> ForeColor="#333333" VerticalAlign="Bottom" />
    >> <DayHeaderStyle Font-Bold="True" Font-Size="8pt"
    >> />
    >> <TitleStyle BackColor="White" BorderColor="Black"
    >> BorderWidth="4px" Font-Bold="True"
    >> Font-Size="12pt" ForeColor="#333399" />
    >> </asp:Calendar>
    >> </EditItemTemplate>
    >> <InsertItemTemplate>
    >> <asp:Calendar ID="Calendar1" runat="server"
    >> BackColor="White" BorderColor="White"
    >> BorderWidth="1px" Font-Names="Verdana"
    >> Font-Size="9pt" ForeColor="Black" Height="170px"
    >> NextPrevFormat="FullMonth" SelectedDate='<%#
    >> Bind("StartDate") %>' Width="274px">
    >> <SelectedDayStyle BackColor="#333399"
    >> ForeColor="White" />
    >> <TodayDayStyle BackColor="#CCCCCC" />
    >> <OtherMonthDayStyle ForeColor="#999999" />
    >> <NextPrevStyle Font-Bold="True" Font-Size="8pt"
    >> ForeColor="#333333" VerticalAlign="Bottom" />
    >> <DayHeaderStyle Font-Bold="True" Font-Size="8pt"
    >> />
    >> <TitleStyle BackColor="White" BorderColor="Black"
    >> BorderWidth="4px" Font-Bold="True"
    >> Font-Size="12pt" ForeColor="#333399" />
    >> </asp:Calendar>
    >> </InsertItemTemplate>
    >> <ItemTemplate>
    >> <asp:Label ID="Label3" runat="server" Text='<%#
    >> Bind("StartDate", "{0:d}") %>'></asp:Label>
    >> </ItemTemplate>
    >> </asp:TemplateField>
    >> <asp:BoundField DataField="DefaultMgmtFee" HeaderText="Default
    >> Mgmt Fee" SortExpression="DefaultMgmtFee" />
    >> <asp:TemplateField HeaderText="Fee Type"
    >> SortExpression="MgmtFeeType">
    >> <EditItemTemplate>
    >> <asp:DropDownList ID="DropDownList2" runat="server"
    >> SelectedValue='<%# Bind("MgmtFeeType") %>'>
    >> <asp:ListItem>%</asp:ListItem>
    >> <asp:ListItem>$</asp:ListItem>
    >> </asp:DropDownList>
    >> </EditItemTemplate>
    >> <InsertItemTemplate>
    >> <asp:DropDownList ID="DropDownList2" runat="server"
    >> SelectedValue='<%# Bind("MgmtFeeType") %>'>
    >> <asp:ListItem>%</asp:ListItem>
    >> <asp:ListItem>$</asp:ListItem>
    >> </asp:DropDownList>
    >> </InsertItemTemplate>
    >> <ItemTemplate>
    >> <asp:Label ID="Label1" runat="server" Text='<%#
    >> Bind("MgmtFeeType") %>'></asp:Label>
    >> </ItemTemplate>
    >> </asp:TemplateField>
    >> <asp:BoundField DataField="ReoccuranceNumber"
    >> HeaderText="Reoccur #" SortExpression="ReoccuranceNumber" />
    >> <asp:TemplateField HeaderText="Reoccur Interval"
    >> SortExpression="Reoccurance">
    >> <EditItemTemplate>
    >> <asp:DropDownList ID="DropDownList3" runat="server"
    >> DataSourceID="sdsReoccur" DataTextField="Reoccurance"
    >> DataValueField="ReoccuranceId" SelectedValue='<%#
    >> Bind("ReoccuranceId") %>'>
    >> </asp:DropDownList>
    >> </EditItemTemplate>
    >> <InsertItemTemplate>
    >> <asp:DropDownList ID="DropDownList3" runat="server"
    >> DataSourceID="sdsReoccur" DataTextField="Reoccurance"
    >> DataValueField="ReoccuranceId" SelectedValue='<%#
    >> Bind("ReoccuranceId") %>'>
    >> </asp:DropDownList>
    >> </InsertItemTemplate>
    >> <ItemTemplate>
    >> <asp:Label ID="Label4" runat="server" Text='<%#
    >> Bind("Reoccurance") %>'></asp:Label>
    >> </ItemTemplate>
    >> </asp:TemplateField>
    >> <asp:BoundField DataField="Comments" HeaderText="Comments"
    >> SortExpression="Comments" >
    >> <ItemStyle Width="300px" />
    >> </asp:BoundField>
    >> <asp:CommandField ShowEditButton="True"
    >> ShowInsertButton="True" />
    >> </Fields>
    >> <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
    >> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
    >> ForeColor="White" />
    >> <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    >> </asp:DetailsView>
    >>
    >>
    >> <asp:SqlDataSource ID="sdsProgramDetails" runat="server"
    >> ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>"
    >> DeleteCommand="DELETE FROM [Programs] WHERE
    >> [ProgramId] = @ProgramId" InsertCommand="INSERT INTO [Programs]
    >> ([ProgramTypeId], [ProgramName], [ActiveProgram], [MaxClients],
    >> [StartDate], [DefaultMgmtFee], [MgmtFeeType], [Comments]) VALUES
    >> (@ProgramTypeId, @ProgramName, @ActiveProgram, @MaxClients, @StartDate,
    >> @DefaultMgmtFee, @MgmtFeeType, @Comments)"
    >> SelectCommand="SELECT Programs.ProgramId,
    >> Programs.ProgramTypeId, Programs.ProgramName, Programs.ActiveProgram,
    >> Programs.MaxClients, Programs.StartDate, Programs.DefaultMgmtFee,
    >> Programs.MgmtFeeType, Programs.Comments, ProgramTypes.ProgramType,
    >> Programs.ReoccuranceNumber, Programs.ReoccuranceId,
    >> Reoccurance.Reoccurance FROM Programs INNER JOIN ProgramTypes ON
    >> Programs.ProgramTypeId = ProgramTypes.ProgramTypeId INNER JOIN
    >> Reoccurance ON Programs.ReoccuranceId = Reoccurance.ReoccuranceId WHERE
    >> (Programs.ProgramId = @ProgramId)" UpdateCommand="UPDATE [Programs] SET
    >> [ProgramTypeId] = @ProgramTypeId, [ProgramName] = @ProgramName,
    >> [ActiveProgram] = @ActiveProgram, [MaxClients] = @MaxClients, [StartDate]
    >> = @StartDate, [DefaultMgmtFee] = @DefaultMgmtFee, [MgmtFeeType] =
    >> @MgmtFeeType, [Comments] = @Comments WHERE [ProgramId] = @ProgramId">
    >> <DeleteParameters>
    >> <asp:parameter Name="ProgramId"
    >> Type="Int32" />
    >> </DeleteParameters>
    >> <UpdateParameters>
    >> <asp:parameter Name="ProgramTypeId"
    >> Type="Int32" />
    >> <asp:parameter Name="ProgramName"
    >> Type="String" />
    >> <asp:parameter Name="ActiveProgram"
    >> Type="Boolean" />
    >> <asp:parameter Name="MaxClients"
    >> Type="Int32" />
    >> <asp:parameter Name="StartDate"
    >> Type="DateTime" />
    >> <asp:parameter Name="DefaultMgmtFee"
    >> Type="Decimal" />
    >> <asp:parameter Name="MgmtFeeType"
    >> Type="String" />
    >> <asp:parameter Name="Comments"
    >> Type="String" />
    >> <asp:parameter Name="ProgramId"
    >> Type="Int32" />
    >> </UpdateParameters>
    >> <SelectParameters>
    >> <asp:ControlParameter
    >> ControlID="GridView1" Name="ProgramId" PropertyName="SelectedValue"
    >> Type="Int32" />
    >> </SelectParameters>
    >> <InsertParameters>
    >> <asp:parameter Name="ProgramTypeId"
    >> Type="Int32" />
    >> <asp:parameter Name="ProgramName"
    >> Type="String" />
    >> <asp:parameter Name="ActiveProgram"
    >> Type="Boolean" />
    >> <asp:parameter Name="MaxClients"
    >> Type="Int32" />
    >> <asp:parameter Name="StartDate"
    >> Type="DateTime" />
    >> <asp:parameter Name="DefaultMgmtFee"
    >> Type="Decimal" />
    >> <asp:parameter Name="MgmtFeeType"
    >> Type="String" />
    >> <asp:parameter Name="Comments"
    >> Type="String" />
    >> </InsertParameters>
    >> </asp:SqlDataSource>
    >>

    >
    >
     
    VB Programmer, Oct 9, 2007
    #3
    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. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    960
    Kevin Spencer
    May 17, 2005
  2. wardemon
    Replies:
    0
    Views:
    492
    wardemon
    Dec 26, 2006
  3. Feege
    Replies:
    0
    Views:
    503
    Feege
    Dec 20, 2005
  4. mt
    Replies:
    2
    Views:
    1,446
  5. bruno

    How-to link 2 Detailsview

    bruno, Jul 18, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    317
    bruno
    Jul 23, 2006
Loading...

Share This Page