GridView to DetailsView

Last post 05-16-2008 1:33 AM by migs8teen. 28 replies.

Sort Posts:

  • GridView to DetailsView

    05-13-2008, 4:57 AM
    • Member
      5 point Member
    • migs8teen
    • Member since 05-09-2008, 1:14 AM
    • Posts 37

    good day to everyone,

    i just want to ask question on how can i view my records from gridview to detailsView

    just like this i have a gridview control and displaying 3 records

    i have a primary key 58,59,62

    the problem is how can i view #59 in details view?? ican view 58 bu if i click the second record 58 will be viewed again..

    i have my sample program attached pls do bare me..

    pls fix my code..

    tnx in advance

     

     

    EDIT2.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="EDIT2.aspx.cs" Inherits="EDIT2" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

    <title>Migzipotpot-Records</title>

    </head>

    <body>

    <form id="form1" runat="server">

    <div>

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White"

    BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="ID"

    DataSourceID="AccessDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"

    Style="z-index: 100; left: 112px; position: absolute; top: 88px" OnSelectedIndexChanging="GridView1_SelectedIndexChanging">

    <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />

    <RowStyle BackColor="White" ForeColor="#003399" />

    <Columns>

    <asp:CommandField ShowSelectButton="True" />

    <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"

    SortExpression="ID" />

    <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />

    <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />

    <asp:BoundField DataField="MiddleName" HeaderText="MiddleName" SortExpression="MiddleName" />

    <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address"

    Visible="False" />

    <asp:BoundField DataField="TelNo" HeaderText="TelNo" SortExpression="TelNo" Visible="False" />

    <asp:BoundField DataField="CelNo" HeaderText="CelNo" SortExpression="CelNo" Visible="False" />

    <asp:BoundField DataField="EmailAdd" HeaderText="EmailAdd" SortExpression="EmailAdd"

    Visible="False" />

    <asp:BoundField DataField="Nationality" HeaderText="Nationality" SortExpression="Nationality"

    Visible="False" />

    <asp:BoundField DataField="Marital Status" HeaderText="Marital Status" SortExpression="Marital Status"

    Visible="False" />

    <asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" Visible="False" />

    <asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" Visible="False" />

    <asp:BoundField DataField="BirthDate" HeaderText="BirthDate" SortExpression="BirthDate"

    Visible="False" />

    <asp:BoundField DataField="BirthPlace" HeaderText="BirthPlace" SortExpression="BirthPlace"

    Visible="False" />

    </Columns>

    <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />

    <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />

    <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />

    </asp:GridView>

    <input id="Button1" style="z-index: 101; left: 0px; position: absolute; top: 0px"

    type="button" value="button" />

     

    </div>

    <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/db1.mdb"

    DeleteCommand="DELETE FROM [tblUser] WHERE [ID] = ?" InsertCommand="INSERT INTO [tblUser] ([ID], [LastName], [FirstName], [MiddleName], [Address], [TelNo], [CelNo], [EmailAdd], [Nationality], [Marital Status], [Gender], [Age], [BirthDate], [BirthPlace]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

    SelectCommand="SELECT * FROM [tblUser]" UpdateCommand="UPDATE [tblUser] SET [LastName] = ?, [FirstName] = ?, [MiddleName] = ?, [Address] = ?, [TelNo] = ?, [CelNo] = ?, [EmailAdd] = ?, [Nationality] = ?, [Marital Status] = ?, [Gender] = ?, [Age] = ?, [BirthDate] = ?, [BirthPlace] = ? WHERE [ID] = ?">

    <DeleteParameters>

    <asp:Parameter Name="ID" Type="Int32" />

    </DeleteParameters>

    <UpdateParameters>

    <asp:Parameter Name="LastName" Type="String" />

    <asp:Parameter Name="FirstName" Type="String" />

    <asp:Parameter Name="MiddleName" Type="String" />

    <asp:Parameter Name="Address" Type="String" />

    <asp:Parameter Name="TelNo" Type="String" />

    <asp:Parameter Name="CelNo" Type="String" />

    <asp:Parameter Name="EmailAdd" Type="String" />

    <asp:Parameter Name="Nationality" Type="String" />

    <asp:Parameter Name="Marital_Status" Type="String" />

    <asp:Parameter Name="Gender" Type="String" />

    <asp:Parameter Name="Age" Type="Int32" />

    <asp:Parameter Name="BirthDate" Type="String" />

    <asp:Parameter Name="BirthPlace" Type="String" />

    <asp:Parameter Name="ID" Type="Int32" />

    </UpdateParameters>

    <InsertParameters>

    <asp:Parameter Name="ID" Type="Int32" />

    <asp:Parameter Name="LastName" Type="String" />

    <asp:Parameter Name="FirstName" Type="String" />

    <asp:Parameter Name="MiddleName" Type="String" />

    <asp:Parameter Name="Address" Type="String" />

    <asp:Parameter Name="TelNo" Type="String" />

    <asp:Parameter Name="CelNo" Type="String" />

    <asp:Parameter Name="EmailAdd" Type="String" />

    <asp:Parameter Name="Nationality" Type="String" />

    <asp:Parameter Name="Marital_Status" Type="String" />

    <asp:Parameter Name="Gender" Type="String" />

    <asp:Parameter Name="Age" Type="Int32" />

    <asp:Parameter Name="BirthDate" Type="String" />

    <asp:Parameter Name="BirthPlace" Type="String" />

    </InsertParameters>

    </asp:AccessDataSource>

    </form>

    </body>

    </html>

     

    EDIT2.aspx.cs

    using System;

    using System.Data;

    using System.Configuration;

    using System.Collections;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using System.Web.UI.HtmlControls;

    using System.Data.OleDb;

    public partial class EDIT2 : System.Web.UI.Page

    {

    string stcron = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\Database\\db1.mdb;Persist Security Info=False";

    System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection();

    System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter();

    System.Data.OleDb.OleDbCommand dc = new System.Data.OleDb.OleDbCommand();

    protected void Page_Load(object sender, EventArgs e)

    {

    if (!Page.IsPostBack)

    {

    AccessDataSource1.DataFile =
    ConfigurationSettings.AppSettings["dbLocation"].ToString();

    cn = new System.Data.OleDb.OleDbConnection(stcron);

    DataTable dt = new DataTable();

     

    //GridView.datakeys[e.row.rowindex]

    }

    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

    {

    int ID = Convert.ToInt32(GridView1.SelectedDataKey.Value);Response.Redirect("Details.aspx?rowID=" + ID);

     

     

    }

    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)

    {

     

     

    }

     

    }

     

    details.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Details.aspx.cs" Inherits="Details" %>

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

    <title>Migzipotpot-Edit</title>

     

    </head>

    <body>

    <form id="form1" runat="server">

    <div>

     

    <asp:FormView ID="FormView1" runat="server" CellPadding="4" DataKeyNames="ID" DataSourceID="AccessDataSource1" Style="z-index: 100; left: 22px; position: absolute; top: 36px" BackColor="White" BorderColor="#CC9966" BorderStyle="Dotted" BorderWidth="1px" Font-Bold="True" Font-Names="Trebuchet MS" GridLines="Both" Width="332px">

     

    <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />

    <RowStyle BackColor="White" ForeColor="#330099" />

    <EditItemTemplate>

     

    ID:

    <asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>'></asp:Label><br />

    LastName:

    <asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>'>

    </asp:TextBox><br />

    FirstName:

    <asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>'>

    </asp:TextBox><br />

    MiddleName:

    <asp:TextBox ID="MiddleNameTextBox" runat="server" Text='<%# Bind("MiddleName") %>'>

    </asp:TextBox><br />

    Address:

    <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>'>

    </asp:TextBox><br />

    TelNo:

    <asp:TextBox ID="TelNoTextBox" runat="server" Text='<%# Bind("TelNo") %>'>

    </asp:TextBox><br />

    CelNo:

    <asp:TextBox ID="CelNoTextBox" runat="server" Text='<%# Bind("CelNo") %>'>

    </asp:TextBox><br />

    EmailAdd:

    <asp:TextBox ID="EmailAddTextBox" runat="server" Text='<%# Bind("EmailAdd") %>'>

    </asp:TextBox><br />

    Nationality:

    <asp:TextBox ID="NationalityTextBox" runat="server" Text='<%# Bind("Nationality") %>'>

    </asp:TextBox><br />

    Marital Status:

    <asp:TextBox ID="Marital_StatusTextBox" runat="server" Text='<%# Bind("[Marital Status]") %>'>

    </asp:TextBox><br />

    Gender:

    <asp:TextBox ID="GenderTextBox" runat="server" Text='<%# Bind("Gender") %>'>

    </asp:TextBox><br />

    Age:

    <asp:TextBox ID="AgeTextBox" runat="server" Text='<%# Bind("Age") %>'>

    </asp:TextBox><br />

    BirthDate:

    <asp:TextBox ID="BirthDateTextBox" runat="server" Text='<%# Bind("BirthDate") %>'>

    </asp:TextBox><br />

    BirthPlace:

    <asp:TextBox ID="BirthPlaceTextBox" runat="server" Text='<%# Bind("BirthPlace") %>'>

    </asp:TextBox><br />

    <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"

    Text="Update">

    </asp:LinkButton>

    <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"

    Text="Cancel">

    </asp:LinkButton>

    </EditItemTemplate>

    <InsertItemTemplate>

    LastName:

    <asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>'>

    </asp:TextBox><br />

    FirstName:

    <asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>'>

    </asp:TextBox><br />

    MiddleName:

    <asp:TextBox ID="MiddleNameTextBox" runat="server" Text='<%# Bind("MiddleName") %>'>

    </asp:TextBox><br />

    Address:

    <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>'>

    </asp:TextBox><br />

    TelNo:

    <asp:TextBox ID="TelNoTextBox" runat="server" Text='<%# Bind("TelNo") %>'>

    </asp:TextBox><br />

    CelNo:

    <asp:TextBox ID="CelNoTextBox" runat="server" Text='<%# Bind("CelNo") %>'>

    </asp:TextBox><br />

    EmailAdd:

    <asp:TextBox ID="EmailAddTextBox" runat="server" Text='<%# Bind("EmailAdd") %>'>

    </asp:TextBox><br />

    Nationality:

    <asp:TextBox ID="NationalityTextBox" runat="server" Text='<%# Bind("Nationality") %>'>

    </asp:TextBox><br />

    Marital Status:

    <asp:TextBox ID="Marital_StatusTextBox" runat="server" Text='<%# Bind("[Marital Status]") %>'>

    </asp:TextBox><br />

    Gender:

    <asp:TextBox ID="GenderTextBox" runat="server" Text='<%# Bind("Gender") %>'>

    </asp:TextBox><br />

    Age:

    <asp:TextBox ID="AgeTextBox" runat="server" Text='<%# Bind("Age") %>'>

    </asp:TextBox><br />

    BirthDate:

    <asp:TextBox ID="BirthDateTextBox" runat="server" Text='<%# Bind("BirthDate") %>'>

    </asp:TextBox><br />

    BirthPlace:

    <asp:TextBox ID="BirthPlaceTextBox" runat="server" Text='<%# Bind("BirthPlace") %>'>

    </asp:TextBox><br />

    <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"

    Text="Insert">

    </asp:LinkButton>

    <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"

    Text="Cancel">

    </asp:LinkButton>

    </InsertItemTemplate>

    <ItemTemplate>

    ID:

    <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>'></asp:Label><br />

    LastName:

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

    FirstName:

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

    MiddleName:

    <asp:Label ID="MiddleNameLabel" runat="server" Text='<%# Bind("MiddleName") %>'>

    </asp:Label><br />

    Address:

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

    TelNo:

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

    CelNo:

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

    EmailAdd:

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

    Nationality:

    <asp:Label ID="NationalityLabel" runat="server" Text='<%# Bind("Nationality") %>'>

    </asp:Label><br />

    Marital Status:

    <asp:Label ID="Marital_StatusLabel" runat="server" Text='<%# Bind("[Marital Status]") %>'>

    </asp:Label><br />

    Gender:

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

    Age:

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

    BirthDate:

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

    BirthPlace:

    <asp:Label ID="BirthPlaceLabel" runat="server" Text='<%# Bind("BirthPlace") %>'>

    </asp:Label><br />

    <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"

    Text="Edit" ForeColor="Black" Font-Size="XX-Large">

    </asp:LinkButton>

     

    </ItemTemplate>

    <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />

    <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />

    <EditRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />

    </asp:FormView>

    <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/db1.mdb"

    DeleteCommand="DELETE FROM [tblUser] WHERE [ID] = ?" InsertCommand="INSERT INTO [tblUser] ([ID], [LastName], [FirstName], [MiddleName], [Address], [TelNo], [CelNo], [EmailAdd], [Nationality], [Marital Status], [Gender], [Age], [BirthDate], [BirthPlace]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

    SelectCommand="SELECT * FROM [tblUser]" UpdateCommand="UPDATE [tblUser] SET [LastName] = ?, [FirstName] = ?, [MiddleName] = ?, [Address] = ?, [TelNo] = ?, [CelNo] = ?, [EmailAdd] = ?, [Nationality] = ?, [Marital Status] = ?, [Gender] = ?, [Age] = ?, [BirthDate] = ?, [BirthPlace] = ? WHERE [ID] = ?">

    <DeleteParameters>

    <asp:Parameter Name="ID" Type="Int32" />

    </DeleteParameters>

    <UpdateParameters>

    <asp:Parameter Name="LastName" Type="String" />

    <asp:Parameter Name="FirstName" Type="String" />

    <asp:Parameter Name="MiddleName" Type="String" />

    <asp:Parameter Name="Address" Type="String" />

    <asp:Parameter Name="TelNo" Type="String" />

    <asp:Parameter Name="CelNo" Type="String" />

    <asp:Parameter Name="EmailAdd" Type="String" />

    <asp:Parameter Name="Nationality" Type="String" />

    <asp:Parameter Name="Marital_Status" Type="String" />

    <asp:Parameter Name="Gender" Type="String" />

    <asp:Parameter Name="Age" Type="Int32" />

    <asp:Parameter Name="BirthDate" Type="String" />

    <asp:Parameter Name="BirthPlace" Type="String" />

    <asp:Parameter Name="ID" Type="Int32" />

    </UpdateParameters>

    <InsertParameters>

    <asp:Parameter Name="ID" Type="Int32" />

    <asp:Parameter Name="LastName" Type="String" />

    <asp:Parameter Name="FirstName" Type="String" />

    <asp:Parameter Name="MiddleName" Type="String" />

    <asp:Parameter Name="Address" Type="String" />

    <asp:Parameter Name="TelNo" Type="String" />

    <asp:Parameter Name="CelNo" Type="String" />

    <asp:Parameter Name="EmailAdd" Type="String" />

    <asp:Parameter Name="Nationality" Type="String" />

    <asp:Parameter Name="Marital_Status" Type="String" />

    <asp:Parameter Name="Gender" Type="String" />

    <asp:Parameter Name="Age" Type="Int32" />

    <asp:Parameter Name="BirthDate" Type="String" />

    <asp:Parameter Name="BirthPlace" Type="String" />

    </InsertParameters>

    </asp:AccessDataSource>

     

     

     

    </div>

    </form>

    </body>

    </html>

     

    Details.aspx.cs

    using System;

    using System.Data;

    using System.Configuration;

    using System.Collections;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using System.Web.UI.HtmlControls;

    using System.Data.OleDb;

    public partial class Details : System.Web.UI.Page

    {

    string stcron = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\Database\\db1.mdb;Persist Security Info=False";

    System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection();

    System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter();

    System.Data.OleDb.OleDbCommand dc = new System.Data.OleDb.OleDbCommand();

    protected void Page_Load(object sender, EventArgs e)

    {

    AccessDataSource1.DataFile =
    ConfigurationSettings.AppSettings["dbLocation"].ToString();

    cn = new System.Data.OleDb.OleDbConnection(stcron);

    DataTable dt = new DataTable();int ID = Int32.Parse(Request.QueryString["rowID"]);

     

    //cn.Open();

    //dc = cn.CreateCommand();

    //TextBox textbox1 = (TextBox)PreviousPage.FindControl("textbox1");

    //TextBox textbox2 = (TextBox)PreviousPage.FindControl("textbox2");

    //TextBox textbox3 = (TextBox)PreviousPage.FindControl("textbox3");

    //TextBox textbox4 = (TextBox)PreviousPage.FindControl("textbox4");

    //TextBox textbox5 = (TextBox)PreviousPage.FindControl("textbox5");

    //TextBox textbox6 = (TextBox)PreviousPage.FindControl("textbox6");

    //TextBox textbox7 = (TextBox)PreviousPage.FindControl("textbox7");

    //TextBox textbox8 = (TextBox)PreviousPage.FindControl("textbox8");

    //TextBox textbox9 = (TextBox)PreviousPage.FindControl("textbox9");

    //TextBox textbox10 = (TextBox)PreviousPage.FindControl("textbox10");

    //TextBox textbox11 = (TextBox)PreviousPage.FindControl("textbox11");

    //TextBox textbox12 = (TextBox)PreviousPage.FindControl("textbox12");

    //TextBox textbox13 = (TextBox)PreviousPage.FindControl("textbox13");

     

     

     

     

    }

    }

  • Re: GridView to DetailsView

    05-13-2008, 5:20 AM
    • Contributor
      5,201 point Contributor
    • aamador
    • Member since 02-11-2008, 10:49 PM
    • Posts 1,107

    concider having both control on this same page and if you do not want to see the detailsview just make it invisible

     

    I am not anti social, am just not user friendly
  • Re: GridView to DetailsView

    05-13-2008, 9:16 PM
    • Member
      5 point Member
    • migs8teen
    • Member since 05-09-2008, 1:14 AM
    • Posts 37

    i really appreciate your support to my post. but that was not the answer ive been looking for,

    i want to view my records in details view everytime i click a record in the gridview... pls help,

     

     

    tnx in advance..

  • Re: GridView to DetailsView

    05-13-2008, 9:52 PM
    • Participant
      1,158 point Participant
    • anthonypj
    • Member since 05-11-2007, 3:31 PM
    • Posts 278

    This tutorial does show an apparoach to what i belive you are after

    http://www.asp.net/learn/data-access/tutorial-10-vb.aspx

    This tutorial will have a GridView whose rows include the name and price of each product along with a Select button. Clicking the Select button for a particular product will cause its full details to be displayed in a DetailsView control on the same page

  • Re: GridView to DetailsView

    05-13-2008, 9:55 PM
    • Participant
      1,158 point Participant
    • anthonypj
    • Member since 05-11-2007, 3:31 PM
    • Posts 278

    or accross twopages

    http://www.asp.net/learn/data-access/tutorial-09-vb.aspx

    In this tutorial we'll implement this pattern by using a GridView to list the suppliers in the database. Each supplier row in the GridView will contain a View Products link that, when clicked, will take the user to a separate page that lists those products for the selected supplier.

  • Re: GridView to DetailsView

    05-14-2008, 1:57 AM
    • Member
      5 point Member
    • migs8teen
    • Member since 05-09-2008, 1:14 AM
    • Posts 37

    sir im sorry that was not the answer.. i want for example i have my records in gridview like this:

    |           | ID | LastName | FirstName | MiddleName |

    Select  | 01 | Stevens | Micheal | Webber |

    Select  | 02 | Davis | Rich Paul  | Ellis      | 

    and then when i click Selct on the first Record which is Micheal the system will take me to another page with the record of Micheal and also with the hidden Fields like this in Details view:

    ID | 01

    LastName | Stevens

    FirstName | Micheal

    MiddleName | Webber

    Address | Hollywood, California

    Age | 21

    Gender | Male

    Nationality | American

    EDIT

    and from that details view there is the edit button

    i have my code here if you want i could send it to you sir..

    i really appreciate your support

     

    thanks,

    Migs-newbie

     

  • Re: GridView to DetailsView

    05-14-2008, 2:26 AM
    • Contributor
      2,161 point Contributor
    • Avinash Desai
    • Member since 01-23-2008, 9:24 AM
    • Bangalore-INDIA
    • Posts 719

    Hey

    The code you have Written is Absolutely Correct and i think in your database you mean have id 58,59,62 and the select command you have given in the Details view page only Loads the First ID so when you get the Id from the First Page i.e., Gridview Page Pass the ID to the Select Command and then Bind the Details view  and You will See all the IDs You Clicked in the Grid view .....As Per my undestanding You are not Passing the ID to the Select Command and If you have Any Queries Please Fell Free to ask

    Thanks
    ~Avinash desai~
    Software Developer
    Bangalore

    Please remember to click "Mark as Answer" on this post if it helped you.
  • Re: GridView to DetailsView

    05-14-2008, 2:39 AM
    • Member
      5 point Member
    • migs8teen
    • Member since 05-09-2008, 1:14 AM
    • Posts 37

    no sir for example i have ID 01,02,03 whenever i click on ID 01 it is ok the record will be displayed but whenever i click id 02, the records in ID 01 will be view again.. my question sir is how will i view id 02 and not id 01. and also when id 03 is click the records again in id 01 will be viewed..

    i appreciate yor support sir..

     

    and also sir i have a problem in updating my records in details view.. how will i update the records in details view control??\

    i really thank you sir have a nice day..

  • Re: GridView to DetailsView

    05-14-2008, 2:51 AM
    • Contributor
      2,161 point Contributor
    • Avinash Desai
    • Member since 01-23-2008, 9:24 AM
    • Bangalore-INDIA
    • Posts 719

     Hey

       Can you show me the Line Where are you Passing the ID to the Select Command?

     

    Thanks
    ~Avinash desai~
    Software Developer
    Bangalore

    Please remember to click "Mark as Answer" on this post if it helped you.
  • Re: GridView to DetailsView

    05-14-2008, 3:07 AM
    • Member
      5 point Member
    • migs8teen
    • Member since 05-09-2008, 1:14 AM
    • Posts 37

    tnx 4 your reply sir Avinash i really appreciate it this is my code and if you want my complete code im free to do it..

     

    in my edit2.aspx.cs i have

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

    {

    int ID = Convert.ToInt32(GridView1.SelectedDataKey.Value);Response.Redirect("Details.aspx?rowID=" + ID);

     

    }

     

     

    and in my Details.aspx.cs i have

     

    protected void Page_Load(object sender, EventArgs e)

    {

    AccessDataSource1.DataFile =
    ConfigurationSettings.AppSettings["dbLocation"].ToString();

    cn = new System.Data.OleDb.OleDbConnection(stcron);

    DataTable dt = new DataTable();

    int ID = Int32.Parse(Request.QueryString["rowID"]);

     

    by the way sir i am using a microsoft access database

    tnx in advance,, pls help me sir..

  • Re: GridView to DetailsView

    05-14-2008, 3:21 AM
    • Contributor
      2,161 point Contributor
    • Avinash Desai
    • Member since 01-23-2008, 9:24 AM
    • Bangalore-INDIA
    • Posts 719

    Hi

    Its Correct and

    migs8teen:
    AccessDataSource1.DataFile = ConfigurationSettings.AppSettings["dbLocation"].ToString();
     

    Gives and Connects to the Database and for displaying Where is the Select Query That you are binding to the Details view?? Can you show me the Select query? 

    Thanks
    ~Avinash desai~
    Software Developer
    Bangalore

    Please remember to click "Mark as Answer" on this post if it helped you.
  • Re: GridView to DetailsView

    05-14-2008, 3:43 AM
    • Member
      5 point Member
    • migs8teen
    • Member since 05-09-2008, 1:14 AM
    • Posts 37

     

    sir are you asking for the select query in my EDIT2.aspx.cs page or in my EDIT2.aspx page ??

    i have no SELECT query in my EDIT2.aspx.cs page.. can you help me pls sir..

  • Re: GridView to DetailsView

    05-14-2008, 4:06 AM
    • Member
      5 point Member
    • migs8teen
    • Member since 05-09-2008, 1:14 AM
    • Posts 37

     

    sir this is my fields in my ms access database

    ID w/ primary key, LastName, FirstName, MiddleName, Address, EmailAdd,TelNo,CelNo, Nationality, [Marital Status], Gender, Age, BirthPlace, BirthDate

     

    this is what i want to do sir when i click a record in gridview it will pass me to another page and will view the records of the record ive select in my gridview control and will be viewed in a details view control.. pls support me sir,

     

    tnx in advance

    migs

  • Re: GridView to DetailsView

    05-14-2008, 4:25 AM
    Answer
    • Contributor
      2,161 point Contributor
    • Avinash Desai
    • Member since 01-23-2008, 9:24 AM
    • Bangalore-INDIA
    • Posts 719

    Hi

    First i want to confirm my understanding .... So You have a Grid view in which you will display the Data and on click of the Row the Grid view's selected Row Data must Go to the Details page where you will bing those data to the Details View and Will show ..

    And The Details View in your page Details.aspx has a details View Which will Show you only one Data at a time when you query a Select Command and in the Same Details view form you have a

    migs8teen:

    <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/db1.mdb"

    DeleteCommand="DELETE FROM [tblUser] WHERE [ID] = ?" InsertCommand="INSERT INTO [tblUser] ([ID], [LastName], [FirstName], [MiddleName], [Address], [TelNo], [CelNo], [EmailAdd], [Nationality], [Marital Status], [Gender], [Age], [BirthDate], [BirthPlace]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

    SelectCommand="SELECT * FROM [tblUser]" UpdateCommand="UPDATE [tblUser] SET [LastName] = ?, [FirstName] = ?, [MiddleName] = ?, [Address] = ?, [TelNo] = ?, [CelNo] = ?, [EmailAdd] = ?, [Nationality] = ?, [Marital Status] = ?, [Gender] = ?, [Age] = ?, [BirthDate] = ?, [BirthPlace] = ? WHERE [ID] = ?">

     

     

    And in the Select statement you have no where condition and See in the Page load write the code below

     

    AccessDataSource1.SelectCommand = "Select * from table1 where id="& ID  &"" ;
     
    i think  this solves your problem...If you have any question please feel free to ask
     
    Thanks
    ~Avinash desai~
    Software Developer
    Bangalore

    Please remember to click "Mark as Answer" on this post if it helped you.
Page 1 of 2 (29 items) 1 2 Next >