i have a crystal report which accepts a parameter and gets displayed on a webpage abc.aspx
on another webpage i have a grid displaying columns from a table loan_request.
when i click a row in gridview I want to get the report of that corresponding row.
i used rowcommand on gridview to get the value that uniquely identifies the row in a gridview, now i need to pass this value as parameter to the crystal report.
for this i think two possiblities
1. pass the value as querystring.
2. store it session and use it on the page that display the report.
i dont want to use query string.
plz let me know the solution with expalnation.
for better understanding. once look at the code.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Request_Log_Search_Sort.aspx.cs" Inherits="WebApplication1.Request_Log_Search_Sort" %>
<%--<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>--%>
<%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!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>Untitled Page</title>
<link type="text/css" rel="stylesheet" href="css/style.css" />
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 221px;
}
.style3
{
width: 897px;
}
.style4
{
width: 897px;
text-align: center;
font-weight: bold;
}
.style5
{
width: 897px;
text-align: center;
font-weight: bold;
font-size: large;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table class="style1">
<tr>
<td class="style2">
</td>
<td class="style4">
</td>
<td>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style4">
</td>
<td>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style5">
REQUEST LOG SEARCH FORM FOR
<asp:Label ID="Label3" runat="server" ForeColor="#006600" Text="Label"></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style4">
-----------------------------------------------------------------------------------------------------------------------------------------------------</td>
<td>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style4">
</td>
<td>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style3">
<asp:DropDownList ID="ddlReq_Type" runat="server">
</asp:DropDownList>
<asp:Label ID="Label1" runat="server" Text="Start Date:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="End Date:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Search" onclick="Button1_Click"
Width="108px" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style3">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CssClass="mGrid" PagerStyle-CssClass="pgr" OnRowDataBound="GridView1_RowDataBound" OnRowCommand="GridView1_RowCommand"
AllowPaging="True" PageSize="15"
OnPageIndexChanging = "OnPaging" AllowSorting="True"
GridLines="Horizontal" CellPadding="4"
ForeColor="#333333" Caption="" style="margin-left: 0px">
<PagerStyle CssClass="pgr"></PagerStyle>
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="REQUEST NO." >
<ItemTemplate>
<asp:Label ID="lblRL_REQ_NO" runat="server" Text='<%# Eval("RL_REQ_NO")%>' ></asp:Label></a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ACTION" >
<ItemTemplate>
<asp:Label ID="lblRL_ACTION" runat="server" Text='<%# Eval("RL_ACTION")%>' ></asp:Label></a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RL_ACTION_BY" HeaderText="ACTION BY" HtmlEncode="False" />
<asp:BoundField DataField="RL_ACTION_DATE" HeaderText="ACTION DATE"/>
<asp:TemplateField HeaderText ="Name">
<ItemTemplate >
<asp:LinkButton ID ="lnkRL_REQ_NO" runat ="server" Text='<%#Eval("RL_ACTION_BY")%>' CommandArgument='<%#Eval("RL_REQ_NO")%>' CommandName ="RL_REQ_NO"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Report Link" >
<ItemTemplate>
<a href="Loan_Request_Report.aspx?LR_REQ_NO=<%#Eval("RL_REQ_NO") %>" >
<asp:Label ID="lblRL_REQ_NO1" runat="server" Text='Report' ></asp:Label></a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
<td>
<asp:Label ID="lblreqno" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style3">
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
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.OleDb;
namespace WebApplication1
{
public partial class Request_Log_Search_Sort : System.Web.UI.Page
{
String RNO;
string name="ISMAIL";
private String strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
Loan_Request_Status objRpt;
objRpt = new Loan_Request_Status();
if (!IsPostBack)
{
Label3.Text = name.ToString();
binddropdown();
BindData();
}
}
private DataSet GetData(OleDbCommand cmd)
{
DataSet dt = new DataSet();
using (OleDbConnection con = new OleDbConnection(strConnString))
{
con.Open();
OleDbDataAdapter sda = new OleDbDataAdapter();
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
return dt;
}
}
private void BindData()
{
//select RL_REQ_NO,RL_REQ_TYPE,RL_ACTION,RL_ACTION_BY,to_char(RL_ACTION_DATE, 'DD-Mon-YYYY HH24:MI:SS') AS RL_ACTION_DATE from request_log where rl_action_by='ISMAIL' ORDER BY RL_ACTION_DATE DESC"
string strQuery = "SELECT RL_REQ_NO,RL_SEQ_NO,RL_ACTION,RL_ACTION_BY,to_char(RL_ACTION_DATE, 'DD-Mon-YYYY HH24:MI:SS') AS RL_ACTION_DATE FROM REQUEST_LOG R WHERE RL_ACTION_BY='ISMAIL' AND RL_SEQ_NO = (SELECT MAX(RL_SEQ_NO) FROM REQUEST_LOG WHERE RL_REQ_NO=R.RL_REQ_NO) ORDER BY RL_REQ_NO DESC";
OleDbCommand cmd = new OleDbCommand(strQuery);
GridView1.DataSource = GetData(cmd);
GridView1.DataBind();
}
protected void OnPaging(object sender, GridViewPageEventArgs e)
{
BindData();
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
public void binddropdown()
{
if (!IsPostBack)
{
ddlReq_Type.Items.Add(new ListItem("--Select Request Type--", ""));
ddlReq_Type.AppendDataBoundItems = true;
String strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
String strQuery = "select distinct(rl_req_type) from request_log";
OleDbConnection con = new OleDbConnection(strConnString);
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
cmd.Connection = con;
try
{
con.Open();
ddlReq_Type.DataSource = cmd.ExecuteReader();
ddlReq_Type.DataTextField = "rl_req_type";
ddlReq_Type.DataValueField = "rl_req_type";
ddlReq_Type.DataBind();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection myConnection = new OleDbConnection(strConnString);
string Query1 = "select * from request_log where rl_req_type=" + "'" + ddlReq_Type.SelectedValue + "'" + "and rl_action_date between " + "'" + Convert.ToString(TextBox1.Text) + "'" + " and " + "'" + Convert.ToString(TextBox2.Text) + "'" + " order by RL_ACTION_DATE DESC";
OleDbCommand cmd = new OleDbCommand(Query1);
GridView1.DataSource = GetData(cmd);
GridView1.DataBind();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "RL_REQ_NO")
{
int index= Convert.ToInt32(e.CommandArgument.ToString()); //GridViewRow gr = GridView1.Rows[index]; //lblreqno.Text = gr.Cells[1].Text; lblreqno.Text = index.ToString(); Response.Redirect("Loan_Request_Report.aspx?lr_req_no=" + lblreqno.Text); //Session["reqno"] = index;
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblRL_ACTION = ((Label)e.Row.FindControl("lblRL_ACTION"));
if (lblRL_ACTION.Text.ToString() == "A")
{
lblRL_ACTION.Text = "Approved";
}
else if (lblRL_ACTION.Text.ToString() == "R")
{
lblRL_ACTION.Text = "Rejected";
}
else
{
lblRL_ACTION.Text = "Pending";
}
}
//if (e.Row.RowType == DataControlRowType.DataRow)
//{
// Label lblRL_REQ_NO = ((Label)e.Row.FindControl("lblRL_REQ_NO"));
// RNO = Convert.ToString(lblRL_REQ_NO.Text);
// Session["reqno"] = RNO;
//}
}
catch (Exception ex)
{
throw ex;
}
}
}
}