srod srod

srod srod

  • NA
  • 14
  • 8.4k

Gridview Selected Value to Populate DetailsView

Feb 13 2012 7:32 PM
I have a Gridview control within a <asp:Content> control.  I have another <asp:Content> control with a DetailView inside the <asp:Content>

The Gridview populates an SQL query using an SQL Datasource, and I have the "Enable Selection" option checked in the smart tag of the Gridview.  I also have the DataKeyNames listed.

The DetailsView has another SQL Datasource that will display results needed when the Gridview Selected Option is clicked.  I have Select Parameters listed in the DetailView SQL Datasource that links to the Gridview when selected.

Problem is when I select the value in the Gridview, my page reloads however the DetailsView does not populate.  My code is listed below for the aspx page, and the code behind.  Any help would be greatly appreciated.

ASPX PAGE

<asp:Content ID="cpQuickView" ContentPlaceHolderID="cphQuickView" Runat="Server"><div style="text-align: left;">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <body>
  <div>
  <asp:GridView ID="GridView2" runat="server" AllowPaging="True"
  AutoGenerateColumns="False" BackColor="White"
  DataSourceID="SqlDataSource2" EnableModelValidation="True"
  Font-Size="Medium" ForeColor="Black" BorderColor="White" GridLines="None"
  style="text-align: center" Width="645px" DataKeyNames="FirstName,LastName"
  AutoGenerateSelectButton="True">
  <Columns>
  <asp:BoundField DataField="FirstName" HeaderText="FirstName"
  SortExpression="FirstName" />
  <asp:BoundField DataField="LastName" HeaderText="LastName"
  SortExpression="LastName" />
  <asp:BoundField DataField="IsEnrolled" HeaderText="IsEnrolled"
  SortExpression="IsEnrolled" />
  <asp:CheckBoxField DataField="IsApproved" HeaderText="IsApproved"
  SortExpression="IsApproved" />
  <asp:CheckBoxField DataField="IsLockedOut" HeaderText="IsLockedOut"
  SortExpression="IsLockedOut" />
  </Columns> 
  <FooterStyle BackColor="#333333" />
  <PagerSettings Mode="NextPreviousFirstLast" />
  </asp:GridView>
  <br />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:MySite_ConnectionString %>" SelectCommand="SELECT FranchiseAgent.FirstName, FranchiseAgent.LastName, FranchiseAgent.IsEnrolled, aspnet_Membership.IsApproved, aspnet_Membership.IsLockedOut FROM aspnet_Membership CROSS JOIN FranchiseAgent"
UpdateCommand="UPDATE aspnet_Membership SET IsApproved = @IsApproved, IsLockedOut = @IsLockedOut FROM aspnet_Membership INNER JOIN FranchiseAgent ON aspnet_Membership.UserId = FranchiseAgent.MembershipId WHERE (@MembershipId = aspnet_Membership.UserId)">
  <UpdateParameters>
  <asp:Parameter Name="IsApproved" />
  <asp:Parameter Name="IsLockedOut" />
  <asp:Parameter Name="MembershipId" />
  </UpdateParameters>
</asp:SqlDataSource>
  <br /> 
  </div>
</body>
</html>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphMainContent" Runat="Server">
  <asp:SqlDataSource ID="SqlDataSource1" runat="server"
  ConnectionString="<%$ ConnectionStrings:CreditScoreTechs_BetaConnectionString %>" 
 
  SelectCommand="SELECT FranchiseAgent.FirstName, FranchiseAgent.LastName, FranchiseAgent.IsEnrolled, aspnet_Membership.IsApproved, aspnet_Membership.IsLockedOut FROM FranchiseAgent CROSS JOIN aspnet_Membership
  WHERE FranchiseAgent.FirstName = @FirstName OR FranchiseAgent.LastName = @LastName"
  onselecting="SqlDataSource1_Selecting">
  <SelectParameters>
  <asp:ControlParameter ControlID="cphQuickView$GridView2"
  Name="FirstName"
  PropertyName="SelectedValue" />
  <asp:ControlParameter ControlID="cphQuickView$GridView2" Name="LastName"
  PropertyName="SelectedValue" />
  </SelectParameters>
  </asp:SqlDataSource>
  <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
  DataSourceID="SqlDataSource1" EnableModelValidation="True" Height="50px"
  Width="125px">
  </asp:DetailsView>
  </asp:Content>


CODE BEHIND:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MySite: System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
  Gridview2.Databind();
  }
   
 
}