Hai Friends,
I ve the "Travel.aspx" page like below fields
departuredate = textbox,
from = textbox,
to = textbox,
Mode= textbox
request_id visible="false" = textbox.
ADD(when i give the add above details ll be shown on gridview and default request_id ll generated)
save(after enter save these values ll be redirected into "HOME.aspx")
In Home.aspx
============
departuedate(link button) from to ll show on gridview.
when i press the link button redirect into "viewdetails.aspx".
the viewdetails .aspx is used to view what i saved on "travel.aspx"
here i wannna display values depends the request_id what i saved in "travel.aspx".
(i.e)get the request_id from travel.aspx pass into "viewdetails.aspx"
how to do that?
Loading
Rocky RockyPosted Jul 30, 2013, 8:44 AM
Thanks for ur kind help 2 me.
i need 2 requirements
1)in travelrequest.aspx page as before u told declare global variable for request_id
depends upon that id show values what ever dates are stored i m entered in that on gridview's.
2) after save the content entrie details ll show on viewdetails.aspx page here also users can add such values (i.e when we kept the draft mail after include some texts and submits it contains new text and saved contents also)
that present values also show on gridview?
these two are my requirements.......
Iftikar HussainPosted Jul 30, 2013, 8:34 AM
Regards,
Iftikar
Rocky RockyPosted Jul 30, 2013, 8:26 AM
its working now.....
now i ve doubt suppose i try to added some dates in viewdetails.aspx page that dates not show same gridview after give save then only can get the valuedates what i ve entered on it.......
like the same gridview problem on current request_id dates ll show on travelrequest.aspx
Iftikar HussainPosted Jul 30, 2013, 8:03 AM
Regards,
Iftikar
Rocky RockyPosted Jul 30, 2013, 7:57 AM
i need to display the details depends on the request_id in page. if i save the content ll show on second page.........
1)default page is login when the ppl logged in redirect into ==> 'travelreq.aspx'
2) travlreq.aspx page contains 2 asp pannels when the users fill first pannel request_id ll be generated,
depends upon that request_id pannel 2 details ll store and show on gridview. when pressing ADD.
3) After finished the details users gave the save ll goes to HOME.aspx page in travel Draft.
4) if i choose the link button entire aspx ll shown of what i have saved on my "travelreq.aspx"
in viewdetails.aspx.
here also gridview ll show on request_id?
do the need full.
Iftikar HussainPosted Jul 30, 2013, 7:06 AM
Regards,
Iftikar
Rocky RockyPosted Jul 30, 2013, 6:35 AM
after passing the query also wont show on GridView,what was the problem.
Iftikar HussainPosted Jul 30, 2013, 4:11 AM
Regards,
Iftikar
Rocky RockyPosted Jul 30, 2013, 3:51 AM
i added my code and screen shots.... let me back.
Iftikar HussainPosted Jul 30, 2013, 3:31 AM
Regards,
Iftikar
Rocky RockyPosted Jul 30, 2013, 3:24 AM
now the requestid was created and allow to database also,but entered details not shown on grid view.......
simply showing no records found.
what was the problem.
public void binddata()
{
//int passedId = Convert.ToInt32(Request.QueryString["IdPassed"]);/// from the request id ll shown into home.aspx into travel.aspx page
//int id = Convert.ToInt32(Session["request"].ToString());
string strquery = "select * from onward_journey where request_id='" + requestId + "' order by departuredate";
SqlCommand cmd = new SqlCommand(strquery, conn);
//conn.Open();
//cmd.CommandType = CommandType.StoredProcedure;
//cmd.Parameters.AddWithValue("@user", Txtusr.Text);
//cmd.Parameters.AddWithValue("@request", Txtrequest.Text);
//cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(cmd);
ds.Clear();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
else
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
GridView1.DataSource = ds;
GridView1.DataBind();
int columncount = GridView1.Rows[0].Cells.Count;
//GridView1.Rows[0].Cells.Clear();
GridView1.Rows[0].Cells.Add(new TableCell());
GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
GridView1.Rows[0].Cells[0].Text = "No Records Found";
}
}
Iftikar HussainPosted Jul 30, 2013, 3:07 AM
Regards,
Iftikar
Rocky RockyPosted Jul 30, 2013, 2:59 AM
i tried above ur code its the break point value of _requestId = 0, so only not allow the data's
database .
Iftikar HussainPosted Jul 30, 2013, 2:45 AM
protected void TxtComments_TextChanged(object sender, EventArgs e)
{
if ((TxtComments.Text != "") && (Txttotal.Text != ""))
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("travel", conn);
conn.Open();
//draftcheck();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@user", Txtusr.Text);
cmd.Parameters.AddWithValue("@purpose", TxtComments.Text);
cmd.Parameters.AddWithValue("@adamt", TxtAdamt.Text);
cmd.Parameters.AddWithValue("@status", 2);
cmd.Parameters.AddWithValue("@total", Txttotal.Text);
_requestId=Convert.ToInt32(cmd.ExecuteScalar());
conn.Close()
}
}
Regards,
Iftikar
Rocky RockyPosted Jul 30, 2013, 2:40 AM
can i use these _requestid in ADD_CLICK also na.....
like
protected void ADD_Click(object sender, EventArgs e)
{
try
{
//string sql = "insert into onward_journey(departuredate,from_location,to_location,metro,trans_all,mode_of_travel,seat_type,no_of_days,other_details,status_id) values(@departuredate,@from_location,@to_location,@metro,@trans_all,@mode_of_travel,@seat_type,@no_of_days,@other_details,'2')";
SqlCommand cmd = new SqlCommand("[Insert_Journey]", conn);
// datecheck();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@departuredate", string.Format("{0:MM/dd/yyyy}", Datepicker.Text));
cmd.Parameters.AddWithValue("@from_location", TxtFm.Text);
cmd.Parameters.AddWithValue("@to_location", TxtTo.Text);
cmd.Parameters.AddWithValue("@metro", DDL_Metro.Text);
cmd.Parameters.AddWithValue("@trans_all", DDL_trans.Text);
cmd.Parameters.AddWithValue("@mode_of_travel", DDL_ModeOfTravel.Text);
cmd.Parameters.AddWithValue("@seat_type", DDL_SeatType.Text);
cmd.Parameters.AddWithValue("@no_of_days", TxtNo.Text);
cmd.Parameters.AddWithValue("@other_details", Txtothrdet.Text);
cmd.Parameters.AddWithValue("@status_id", Txtstts.Text);
cmd.Parameters.AddWithValue("@request", _requestId);
conn.Open();
cmd.ExecuteNonQuery();
DateTime val = new DateTime();
DateTime b = new DateTime();
val = Convert.ToDateTime(Datepicker.Text);
b = val.AddDays(Convert.ToInt32(TxtNo.Text));
Datepicker.Text = b.ToString();
binddata();
}
catch (System.Exception ex)
{
Console.WriteLine("Source: " + ex.Source);
Console.WriteLine("Exception Message: " + ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
Console.WriteLine("Finally block closing the connection");
conn.Close();
}
}
//Datepicker.Enabled = false;
DDL_Metro.SelectedIndex = 0;
DDL_trans.SelectedIndex = 0;
DDL_ModeOfTravel.SelectedIndex = 0;
DDL_SeatType.SelectedIndex = 0;
TxtFm.Text = "";
TxtTo.Text = "";
TxtNo.Text = "";
Txtothrdet.Text = "";
Txtrequest.Text = "";
}
but that request_id wont allow ADD on database ......... what was the problem,
should i use on gridview
like
select * from onward_journey where request_id= ' " + _requestId + " ';
Iftikar HussainPosted Jul 30, 2013, 2:34 AM
declare global variable in page1.aspx
private int _requestId;
protected void TxtComments_TextChanged(object sender, EventArgs e)
{
if ((TxtComments.Text != "") && (Txttotal.Text != ""))
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("travel", conn);
conn.Open();
//draftcheck();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@user", Txtusr.Text);
cmd.Parameters.AddWithValue("@purpose", TxtComments.Text);
cmd.Parameters.AddWithValue("@adamt", TxtAdamt.Text);
cmd.Parameters.AddWithValue("@status", 2);
cmd.Parameters.AddWithValue("@total", Txttotal.Text);
_requestId=Convert.ToInt32(cmd.ExecuteScalar());
conn.Close()
}
}
Regards,
Iftikar
Rocky RockyPosted Jul 30, 2013, 2:31 AM
ya i m facing the same problem by using IDENT_current('travel_request'),
can u please tell me how to get the request_id and pass into ADD_CLICK .....
alter procedure Insert_Journey
(
@departuredate datetime,
@from_location varchar(50),
@to_location varchar(50),
@metro nvarchar(50),
@trans_all nvarchar(50),
@mode_of_travel nvarchar(50),
@seat_type nvarchar(50),
@no_of_days int,
@other_details varchar(50),
@status_id int,
@request int
)
as
BEGIN
DECLARE @MaxDate datetime
SELECT @MaxDate = MAX(DepartureDate) FROM onward_journey where request_id=IDENT_CURRENT ('travel_request') //// here i made code for not allow less than dates where already entered on that request_id
IF(@MaxDate >@departuredate)
begin
RAISERROR('Your error message for departuredate should be greater then maxdate',16,1)
RETURN
END
insert into onward_journey(departuredate,from_location,to_location,metro,trans_all,mode_of_travel,seat_type,no_of_days,other_details,status_id,request_id) values(@departuredate,@from_location,@to_location,@metro,@trans_all,@mode_of_travel,@seat_type,@no_of_days,@other_details,'2',IDENT_CURRENT ('travel_request') )
--set @request= IDENT_CURRENT ('travel_request')
--return @request
end
how to pass the _requestid from above u told?
Iftikar HussainPosted Jul 30, 2013, 2:21 AM
Regards,
Iftikar
Rocky RockyPosted Jul 30, 2013, 2:17 AM
hey friend with out request_id referl ll be generated automatically and i pass the request_id in add_click request_id=IDENT_CURRENT('travel_request'))
i m facing the problem when i pass
request_id=IDENT_CURRENT('travel_request'))
same thnk in grid view table. its wont working.......
protected void TxtComments_TextChanged(object sender, EventArgs e)
{
if ((TxtComments.Text != "") && (Txttotal.Text != ""))
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("travel", conn);
conn.Open();
//draftcheck();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@user", Txtusr.Text);
cmd.Parameters.AddWithValue("@purpose", TxtComments.Text);
cmd.Parameters.AddWithValue("@adamt", TxtAdamt.Text);
cmd.Parameters.AddWithValue("@status", 2);
cmd.Parameters.AddWithValue("@total", Txttotal.Text);
conn.Close()
}
}
Iftikar HussainPosted Jul 30, 2013, 2:10 AM
declare global variable in page1.aspx
private int _requestId;
protected void TxtComments_TextChanged(object sender, EventArgs e)
{
if ((TxtComments.Text != "") && (Txttotal.Text != ""))
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("travel", conn);
conn.Open();
//draftcheck();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@user", Txtusr.Text);
cmd.Parameters.AddWithValue("@purpose", TxtComments.Text);
cmd.Parameters.AddWithValue("@adamt", TxtAdamt.Text);
cmd.Parameters.AddWithValue("@status", 2);
cmd.Parameters.AddWithValue("@total", Txttotal.Text);
_requestId=Convert.ToInt32(cmd.ExecuteScalar());
conn.Close()
}
}
Regards,
Iftikar
Iftikar HussainPosted Jul 30, 2013, 2:05 AM
Regards,
Iftikar
Rocky RockyPosted Jul 30, 2013, 1:58 AM
here attached the screen shots,
newreques-1 image when i fill the textbox of travel purpose,advance amount,total amount the request_id ll be created.
depends on the request_id newreques-2 image details ll show on gridview these my concept
let me know?
Iftikar HussainPosted Jul 30, 2013, 1:19 AM
Regards,
Iftikar
Rocky RockyPosted Jul 30, 2013, 1:12 AM
The Bindata() method in page 1......
and i ve one more doubt in that,for creating request_id purpose i made the event like
protected void TxtComments_TextChanged(object sender, EventArgs e)
{
if ((TxtComments.Text != "") && (Txttotal.Text != ""))
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("travel", conn);
conn.Open();
//draftcheck();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@user", Txtusr.Text);
cmd.Parameters.AddWithValue("@purpose", TxtComments.Text);
cmd.Parameters.AddWithValue("@adamt", TxtAdamt.Text);
cmd.Parameters.AddWithValue("@status", 2);
cmd.Parameters.AddWithValue("@total", Txttotal.Text);
}
}
procedure for getting request_id:
=======================
alter procedure travel
(
@user varchar(100),
@purpose varchar(100),
@adamt varchar(10),
@status int,
@total varchar(100)
)
as
begin
declare @requestId int
set @requestId=0
if not exists (select 1 from travel_request where user_id=@user and purpose_of_travel=@purpose and advance_amount=@adamt and status_id=@status)
BEGIN
insert into travel_request (user_id,purpose_of_travel,advance_amount,status_id,total_amount) values(@user,@purpose,@adamt,'2',@total)
set @requestId= @@identity
END
SELECT @requestId as requestId
end
as you given before,now i wanna get these request_id and pass to ADD_click event
in c# code:
=========
protected void ADD_Click(object sender, EventArgs e)
{
try
{
//string sql = "insert into onward_journey(departuredate,from_location,to_location,metro,trans_all,mode_of_travel,seat_type,no_of_days,other_details,status_id) values(@departuredate,@from_location,@to_location,@metro,@trans_all,@mode_of_travel,@seat_type,@no_of_days,@other_details,'2')";
SqlCommand cmd = new SqlCommand("[Insert_Journey]", conn);
// datecheck();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@departuredate", string.Format("{0:MM/dd/yyyy}", Datepicker.Text));
cmd.Parameters.AddWithValue("@from_location", TxtFm.Text);
cmd.Parameters.AddWithValue("@to_location", TxtTo.Text);
cmd.Parameters.AddWithValue("@metro", DDL_Metro.Text);
cmd.Parameters.AddWithValue("@trans_all", DDL_trans.Text);
cmd.Parameters.AddWithValue("@mode_of_travel", DDL_ModeOfTravel.Text);
cmd.Parameters.AddWithValue("@seat_type", DDL_SeatType.Text);
cmd.Parameters.AddWithValue("@no_of_days", TxtNo.Text);
cmd.Parameters.AddWithValue("@other_details", Txtothrdet.Text);
cmd.Parameters.AddWithValue("@status_id", Txtstts.Text);
cmd.Parameters.AddWithValue("@request", Txtrequest.Text);/// here i wanna pass that request_id
conn.Open();
cmd.ExecuteNonQuery();
DateTime val = new DateTime();
DateTime b = new DateTime();
val = Convert.ToDateTime(Datepicker.Text);
b = val.AddDays(Convert.ToInt32(TxtNo.Text));
Datepicker.Text = b.ToString();
Session["request_id"] = Txtrequest.Text.ToString();
binddata();
}
catch (System.Data.SqlClient.SqlException ex)
{
Console.WriteLine("Source: " + ex.Source);
Console.WriteLine("Exception Message: " + ex.Message);
}
catch (System.Exception ex)
{
Console.WriteLine("Source: " + ex.Source);
Console.WriteLine("Exception Message: " + ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
Console.WriteLine("Finally block closing the connection");
conn.Close();
}
}
//Datepicker.Enabled = false;
DDL_Metro.SelectedIndex = 0;
DDL_trans.SelectedIndex = 0;
DDL_ModeOfTravel.SelectedIndex = 0;
DDL_SeatType.SelectedIndex = 0;
TxtFm.Text = "";
TxtTo.Text = "";
TxtNo.Text = "";
Txtothrdet.Text = "";
Txtrequest.Text = "";
}
}
above insertion code in sql:
====================
alter procedure Insert_Journey
(
@departuredate datetime,
@from_location varchar(50),
@to_location varchar(50),
@metro nvarchar(50),
@trans_all nvarchar(50),
@mode_of_travel nvarchar(50),
@seat_type nvarchar(50),
@no_of_days int,
@other_details varchar(50),
@status_id int,
@request int
)
as
BEGIN
DECLARE @MaxDate datetime
SELECT @MaxDate = MAX(DepartureDate) FROM onward_journey where request_id=IDENT_CURRENT ('travel_request')
IF(@MaxDate >@departuredate)
begin
RAISERROR('Your error message for departuredate should be greater then maxdate',16,1)
RETURN
END
insert into onward_journey(departuredate,from_location,to_location,metro,trans_all,mode_of_travel,seat_type,no_of_days,other_details,status_id,request_id) values(@departuredate,@from_location,@to_location,@metro,@trans_all,@mode_of_travel,@seat_type,@no_of_days,@other_details,'2',@request)
end
depends on these request_id i wanna show the values bindata() in page 1........
how to do that?
Iftikar HussainPosted Jul 29, 2013, 10:34 AM
Regards,
Iftikar
Rocky RockyPosted Jul 29, 2013, 9:35 AM
I wanna get the request from that page and depends on that ID , i wanna show details on GridView.
after logout that details ll be disappear on GridView column,How to do that?
Iftikar HussainPosted Jul 29, 2013, 7:30 AM
Try like this in binddata()
public void binddata()
{
string gth = Txtrequest.ToString();
}
Not sure why are you reading from session variable as you are calling the method from same page where already request value is available from Textbox
Regards,
Iftikar
Sanjeeb LenkaPosted Jul 29, 2013, 7:11 AM
i checked your code you did a mistake in ADD button click i modified you code. you forgot to write the TEXT
protected void ADD_Click(object sender, EventArgs e)
{
try
{
//string sql = "insert into onward_journey(departuredate,from_location,to_location,metro,trans_all,mode_of_travel,seat_type,no_of_days,other_details,status_id) values(@departuredate,@from_location,@to_location,@metro,@trans_all,@mode_of_travel,@seat_type,@no_of_days,@other_details,'2')";
SqlCommand cmd = new SqlCommand("[Insert_Journey]", conn);
// datecheck();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@departuredate", string.Format("{0:MM/dd/yyyy}", Datepicker.Text));
cmd.Parameters.AddWithValue("@from_location", TxtFm.Text);
cmd.Parameters.AddWithValue("@to_location", TxtTo.Text);
cmd.Parameters.AddWithValue("@metro", DDL_Metro.Text);
cmd.Parameters.AddWithValue("@trans_all", DDL_trans.Text);
cmd.Parameters.AddWithValue("@mode_of_travel", DDL_ModeOfTravel.Text);
cmd.Parameters.AddWithValue("@seat_type", DDL_SeatType.Text);
cmd.Parameters.AddWithValue("@no_of_days", TxtNo.Text);
cmd.Parameters.AddWithValue("@other_details", Txtothrdet.Text);
cmd.Parameters.AddWithValue("@status_id", Txtstts.Text);
cmd.Parameters.AddWithValue("@request", Txtrequest.Text);
conn.Open();
cmd.ExecuteNonQuery();
DateTime val = new DateTime();
DateTime b = new DateTime();
val = Convert.ToDateTime(Datepicker.Text);
b = val.AddDays(Convert.ToInt32(TxtNo.Text));
Datepicker.Text = b.ToString();
binddata();
Session["request_id"] = Txtrequest.Text.ToString();//// store request_id
}
check once and reply
Rocky RockyPosted Jul 29, 2013, 7:06 AM
after modify code on add_click alsop shoeing error........
public void binddata()
{
string gth = Session["request_id"].ToString(); /// Object reference not set to an instance of an object.
string strquery = "select * from onward_journey where request_id =' " + gth +" ' ";
SqlCommand cmd = new SqlCommand(strquery, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
ds.Clear();
da.Fill(ds);
conn.Open();
//if (ds.Tables[0].Rows.Count > 0)
//{
if (ds.Tables.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
GridView1.DataSource = ds;
//GridView1.DataSource = null;
GridView1.DataBind();
}
}
else
{
GridView1.DataSource = null;
GridView1.DataBind();
}
Posted Jul 29, 2013, 6:59 AM
binddata();
Session["request_id"] = Txtrequest.ToString();/
First your should call,
Session["request_id"] = Txtrequest.ToString();
binddata();
Try this now.
Rocky RockyPosted Jul 29, 2013, 6:52 AM
protected void ADD_Click(object sender, EventArgs e)
{
try
{
//string sql = "insert into onward_journey(departuredate,from_location,to_location,metro,trans_all,mode_of_travel,seat_type,no_of_days,other_details,status_id) values(@departuredate,@from_location,@to_location,@metro,@trans_all,@mode_of_travel,@seat_type,@no_of_days,@other_details,'2')";
SqlCommand cmd = new SqlCommand("[Insert_Journey]", conn);
// datecheck();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@departuredate", string.Format("{0:MM/dd/yyyy}", Datepicker.Text));
cmd.Parameters.AddWithValue("@from_location", TxtFm.Text);
cmd.Parameters.AddWithValue("@to_location", TxtTo.Text);
cmd.Parameters.AddWithValue("@metro", DDL_Metro.Text);
cmd.Parameters.AddWithValue("@trans_all", DDL_trans.Text);
cmd.Parameters.AddWithValue("@mode_of_travel", DDL_ModeOfTravel.Text);
cmd.Parameters.AddWithValue("@seat_type", DDL_SeatType.Text);
cmd.Parameters.AddWithValue("@no_of_days", TxtNo.Text);
cmd.Parameters.AddWithValue("@other_details", Txtothrdet.Text);
cmd.Parameters.AddWithValue("@status_id", Txtstts.Text);
cmd.Parameters.AddWithValue("@request", Txtrequest.Text);
conn.Open();
cmd.ExecuteNonQuery();
DateTime val = new DateTime();
DateTime b = new DateTime();
val = Convert.ToDateTime(Datepicker.Text);
b = val.AddDays(Convert.ToInt32(TxtNo.Text));
Datepicker.Text = b.ToString();
binddata();
Session["request_id"] = Txtrequest.ToString();//// store request_id from ADD BUTTON.
}
catch (System.Data.SqlClient.SqlException ex)
{
Console.WriteLine("Source: " + ex.Source);
Console.WriteLine("Exception Message: " + ex.Message);
}
catch (System.Exception ex)
{
Console.WriteLine("Source: " + ex.Source);
Console.WriteLine("Exception Message: " + ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
Console.WriteLine("Finally block closing the connection");
conn.Close();
}
}
//string st = "select convert(varchar, departuredate, 103)as DepartureDate , from_location as 'From' ,to_location 'To', metro,trans_all as Trans,mode_of_travel as ModeOfTravel,seat_type as Seat, no_of_days as Numdays, other_details as OtherDetails from onward_journey";
//SqlDataAdapter de = new SqlDataAdapter(st, conn);
//DataTable dtStore = new DataTable();
//de.Fill(dtStore);
//grdvStore.DataSource = dtStore.DefaultView;
//grdvStore.DataBind();
// br = Txtrequest.Text;
//Datepicker.Enabled = false;
DDL_Metro.SelectedIndex = 0;
DDL_trans.SelectedIndex = 0;
DDL_ModeOfTravel.SelectedIndex = 0;
DDL_SeatType.SelectedIndex = 0;
TxtFm.Text = "";
TxtTo.Text = "";
TxtNo.Text = "";
Txtothrdet.Text = "";
Txtrequest.Text = "";
}
}
for Grdiview display depends on current request_id.
public void binddata()
{
string gth = Session["request_id"].ToString();/// showing error what was problem here.....
string strquery = "select onward_journey_id,convert(varchar, departuredate, 106)as DepartureDate,from_location,to_location, case metro when 'Yes' then 'Yes' else 'No' end as Metro,case Trans_All when 'Yes' then 'Yes' else 'No' END as transit,case when mode_of_travel like 'Ai%' then mode_of_travel when mode_of_travel like 'Tr%' then mode_of_travel when mode_of_travel like 'Bu%' then mode_of_travel when mode_of_travel like 'Ca%' then mode_of_travel when mode_of_travel like 'Au%' then mode_of_travel when mode_of_travel like 'lo%' then mode_of_travel end as Mode,case when mode_of_travel like ('ai%') then seat_type when mode_of_travel like ('tra%') then seat_type when mode_of_travel like ('Bu%') then seat_type when mode_of_travel like ('ca%') then seat_type when mode_of_travel like ('au%') then seat_type when mode_of_travel like ('loc%') then seat_type end as SEAT,no_of_days as noofdays,other_details from onward_journey where request_id=' " + gth + " ' order by departuredate";
SqlCommand cmd = new SqlCommand(strquery, conn);
//conn.Open();
//cmd.CommandType = CommandType.StoredProcedure;
//cmd.Parameters.AddWithValue("@user", Txtusr.Text);
//cmd.Parameters.AddWithValue("@request", Txtrequest.Text);
//cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(cmd);
ds.Clear();
da.Fill(ds);
conn.Open();
//if (ds.Tables[0].Rows.Count > 0)
//{
if (ds.Tables.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
GridView1.DataSource = ds;
//GridView1.DataSource = null;
GridView1.DataBind();
}
}
else
{
GridView1.DataSource = null;
GridView1.DataBind();
}
conn.Close();
}
Sunny SharmaPosted Jul 29, 2013, 2:53 AM
Of course you can do it:
Follow this pattern:
int id=0;
try
{
id=Convert.ToInt32(Session["id"]);
//Get the data with this id:
string query = "select * from mytable where id="+id.ToString();
//do database operation and bind to gridview
}
catch(exception ex)
{
// ID not found, handle the error.
}
Posted Jul 29, 2013, 2:53 AM
Use session variable, you can use it anywhere in the user's session.
If you use QueryString, directly read the querystring value inside your method.
Rocky RockyPosted Jul 29, 2013, 2:49 AM
is it possible to pass these method gridview table?
like
select * from onward_journey where request_id = ' " +id+ " ' in gridview load?
Sanjeeb LenkaPosted Jul 29, 2013, 2:14 AM
here you can use any of two concept of State management.
1.session
2 Query string
if you use session your Request_id is available in all page of your website.
if you use Query string the value is only available to the page where you are redirecting with query string value.
using session:
in 1st page
Session["Request_id"] = Request_id;/storing the value in session
in view.aspx page:
String Request_id = Convert.ToString(Session["Request_id"]);
using query string:
in 1st page within link button click
Response.redirect("view.aspx?RequestId=" + RequestId);
in 2nd page
string Request_Id=Request.QureyString["RequestId"];
Iftikar HussainPosted Jul 29, 2013, 2:01 AM
Try like this
in viewdetails.aspx
string requestId=Request.QureyString["RequestId"];
}
Regards,
Iftikar
Posted Jul 29, 2013, 2:00 AM
1) You can use session variable to pass the values from one to another page.
2) You can use query string parameters
3) You can use cookies.
But the best way is use Session variables.
In the first page
Session["Request_id"] =
And in the second page,
String requestid = Convert.ToString(Session["Request_id"]);
During logout,clear all the session variables.
Hope this helps you.