I have two types of grid on separate screens.
Gridview1
ID Product Date Amount
1 Car1 02/03/2014 $ 15,000
1 Car2 05/03/2014 $ 10,000
2 Bike 01/01/2014 $ 2,500
3 Bus 06/04/2014 $ 25,000
Gridview2
ID Product Date Amount
1 Car2 05/03/2014 $ 25,000
2 Bike 01/01/2014 $ 2,500
3 Bus 06/04/2014 $ 25,000
Gridview2 summarizes the same ID row values from GridView1 and displays in GridView2 a selection of the last effective date.
Now I display my ID column in GridView2 as LinkButton. When I click on the value 1 in the ID column of GridView2, it should go to GridView1 and show only the ID values of 1 in the grid.
Code for:
Gridview1
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = DataRepository.GetG1();
GridView1.DataBind();
}
}
public static DataTable GetG1()
{
DataTable dt = new DataTable();
string strcon = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(strcon))
{
conn.Open();
string strQuery = "Select * from ManLog";
SqlCommand cmd = new SqlCommand(strQuery, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
}
return dt;
}
Gridview2
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView2.DataSource = DataRepository.GetG2();
GridView2.DataBind();
}
}
public static DataTable GetG2()
{
DataTable dt = new DataTable();
string strcon = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(strcon))
{
conn.Open();
string strQuery = "Select ID, Product, max(Date),sum(Amount) from ManLog";
SqlCommand cmd = new SqlCommand(strQuery, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
}
return dt;
}
Link Button for GridView 2:
<asp:TemplateField HeaderText="ID" SortExpression="ID">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="25%" />
<EditItemTemplate>
<asp:TextBox ID="txtID" Width="100%" runat="server" Enabled="false" Text='<%# Eval("ID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="lblID" runat="server" Text='<%# Eval("ID") %>' />
</ItemTemplate>
</asp:TemplateField>
user3279082
source
share