T
Tai
I'm new at this so please bear with me. I have two webforms, for
example purposes I'll say a.aspx and b.aspx... a.aspx has a datagrid
populated from MS Access with all the records, including contactID. On
b.aspx, I want to populate a datagrid with only one record, based on
the selected row from a.aspx... I can see the contactID in the
HTTP://dadadadada?cid=115 (or whatever row is chosen) but when b.aspx
is loaded, I see nothing. I know I have to assign a parameter for my
BindData method, but how? My code is below. Any help would be great.
Thanks...
Tai
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Data.OleDb;
using System.Reflection;
namespace Contact
{
/// <summary>
/// Summary description for contact_details.
/// </summary>
public class contact_details : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Image Image2;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls.Label Lbl_header;
protected System.Web.UI.WebControls.Literal ContactIDLtl;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Label Label1;
public string ContactID
{
get
{
return ContactIDLtl.Text;
}
}
private void SetContactID()
{
string cid = Request.QueryString["cid"];
ContactIDLtl.Text = cid;
Label1.Text = cid;
}
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack)
{
SetContactID();
BindData();
}
}
private void BindData()
{
string sConnString = ConfigurationSettings.AppSettings["Contact"];
OleDbConnection conn = new OleDbConnection(sConnString);
string sSql = "SELECT Contacts.ContactID, Contacts.FirstName,
Contacts.LastName, Contacts.DateApplied, Contacts.DateAv FROM Contacts
WHERE (((Contacts.ContactID)=[?]))";
Cmd.Parameters.Add("ContactID",
System.Data.SqlDbType.VarChar).Value = ContactID;
OleDbCommand ContactsCmd = new OleDbCommand(sSql, conn);
conn.Open();
try
{
DataGrid1.DataSource = ContactsCmd.ExecuteReader();
DataGrid1.DataBind();
}
finally
{
conn.Close();
}
}
example purposes I'll say a.aspx and b.aspx... a.aspx has a datagrid
populated from MS Access with all the records, including contactID. On
b.aspx, I want to populate a datagrid with only one record, based on
the selected row from a.aspx... I can see the contactID in the
HTTP://dadadadada?cid=115 (or whatever row is chosen) but when b.aspx
is loaded, I see nothing. I know I have to assign a parameter for my
BindData method, but how? My code is below. Any help would be great.
Thanks...
Tai
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Data.OleDb;
using System.Reflection;
namespace Contact
{
/// <summary>
/// Summary description for contact_details.
/// </summary>
public class contact_details : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Image Image2;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls.Label Lbl_header;
protected System.Web.UI.WebControls.Literal ContactIDLtl;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Label Label1;
public string ContactID
{
get
{
return ContactIDLtl.Text;
}
}
private void SetContactID()
{
string cid = Request.QueryString["cid"];
ContactIDLtl.Text = cid;
Label1.Text = cid;
}
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack)
{
SetContactID();
BindData();
}
}
private void BindData()
{
string sConnString = ConfigurationSettings.AppSettings["Contact"];
OleDbConnection conn = new OleDbConnection(sConnString);
string sSql = "SELECT Contacts.ContactID, Contacts.FirstName,
Contacts.LastName, Contacts.DateApplied, Contacts.DateAv FROM Contacts
WHERE (((Contacts.ContactID)=[?]))";
Cmd.Parameters.Add("ContactID",
System.Data.SqlDbType.VarChar).Value = ContactID;
OleDbCommand ContactsCmd = new OleDbCommand(sSql, conn);
conn.Open();
try
{
DataGrid1.DataSource = ContactsCmd.ExecuteReader();
DataGrid1.DataBind();
}
finally
{
conn.Close();
}
}