Table one
product_mainid, product_mainname, Product_home country
Table Two
product_mainid, product_subproduct, product_price, product_quantity, Product_manufacture
Here for example
Table One
product_mainname id =1, product_mainname = colgate, Product_home country=India,
Table Two
product_mainid foriegn key from table one, product_subproduct=brush, product_price=20rs, product_quantity=10, Product_manufacture=india
How to relate with primary and foriegn key and in one page, while loading a page the second table will showing in grid view and the output after clicking the button will show the another grid view in bottom i will attach the output format for your convience.
Loading
newto netPosted Jan 26, 2012, 4:21 AM
Satyapriya NayakPosted Jan 25, 2012, 11:16 PM
Try this...
Run the attachments.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="first.aspx.cs" Inherits="WebApplication4.first" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace WebApplication4
{
public partial class first : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
string str;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid();
}
}
void bindgrid()
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select * from t1";
com = new SqlCommand(str, con);
SqlDataReader reader;
reader = com.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
reader.Close();
con.Close();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="second.aspx.cs" Inherits="WebApplication4.second" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace WebApplication4
{
public partial class second : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
string str, s1;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
s1 = Request.QueryString[0].ToString();
str = "select * from t2 where product_mainid='" + s1 + "'";
com = new SqlCommand(str, con);
SqlDataReader reader;
reader = com.ExecuteReader();
GridView2.DataSource = reader;
GridView2.DataBind();
reader.Close();
con.Close();
}
}
}
Thanks