
-
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");
}
}
|
|