Lost link between GridView and DetailsView

V

VB Programmer

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>
 
E

Eliyahu Goldin

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 said:
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>
 
V

VB Programmer

I appreciate your help!

Eliyahu Goldin said:
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 said:
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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,057
Messages
2,570,443
Members
47,115
Latest member
DorothyLus

Latest Threads

Top